root/galaxy-central/lib/galaxy/datatypes/converters/vcf_to_interval_index_converter.py @ 2

リビジョン 2, 0.9 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1#!/usr/bin/env python
2
3"""
4Convert from VCF file to interval index file.
5"""
6
7from __future__ import division
8
9import optparse
10from galaxy import eggs
11import pkg_resources; pkg_resources.require( "bx-python" )
12import galaxy_utils.sequence.vcf
13from bx.interval_index_file import Indexes
14
15def 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
33if __name__ == "__main__":
34    main()
35   
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。