1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """ |
---|
4 | Convert from VCF file to interval index file. |
---|
5 | """ |
---|
6 | |
---|
7 | from __future__ import division |
---|
8 | |
---|
9 | import optparse |
---|
10 | from galaxy import eggs |
---|
11 | import pkg_resources; pkg_resources.require( "bx-python" ) |
---|
12 | import galaxy_utils.sequence.vcf |
---|
13 | from bx.interval_index_file import Indexes |
---|
14 | |
---|
15 | def main(): |
---|
16 | # Read options, args. |
---|
17 | parser = optparse.OptionParser() |
---|
18 | (options, args) = parser.parse_args() |
---|
19 | in_file, out_file = args |
---|
20 | |
---|
21 | # Do conversion. |
---|
22 | index = Indexes() |
---|
23 | reader = galaxy_utils.sequence.vcf.Reader( open( in_file ) ) |
---|
24 | offset = reader.metadata_len |
---|
25 | for vcf_line in reader: |
---|
26 | # VCF format provides a chrom and 1-based position for each variant. |
---|
27 | # IntervalIndex expects 0-based coordinates. |
---|
28 | index.add( vcf_line.chrom, vcf_line.pos-1, vcf_line.pos, offset ) |
---|
29 | offset += len( vcf_line.raw_line ) |
---|
30 | |
---|
31 | index.write( open( out_file, "w" ) ) |
---|
32 | |
---|
33 | if __name__ == "__main__": |
---|
34 | main() |
---|
35 | |
---|