PageRenderTime 28ms CodeModel.GetById 20ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/datatypes/converters/vcf_to_summary_tree_converter.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 30 lines | 14 code | 6 blank | 10 comment | 3 complexity | 48672b0d1bc3f90bc5ccb39ff0047e84 MD5 | raw file
 1#!/usr/bin/env python
 2
 3"""
 4Convert from VCF file to summary tree file.
 5
 6usage: %prog in_file out_file
 7"""
 8from __future__ import division
 9
10import optparse
11import galaxy_utils.sequence.vcf
12from galaxy.visualization.tracks.summary import SummaryTree
13
14def main():
15    # Read options, args.
16    parser = optparse.OptionParser()
17    (options, args) = parser.parse_args()
18    in_file, out_file = args
19        
20    # Do conversion.
21    st = SummaryTree(block_size=25, levels=6, draw_cutoff=150, detail_cutoff=30)
22    for line in list( galaxy_utils.sequence.vcf.Reader( open( in_file ) ) ):
23        # VCF format provides a chrom and 1-based position for each variant. 
24        # SummaryTree expects 0-based coordinates.
25        st.insert_range( line.chrom, long( line.pos-1 ), long( line.pos ) )
26    
27    st.write(out_file)
28
29if __name__ == "__main__": 
30    main()