/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 · 2 complexity · 48672b0d1bc3f90bc5ccb39ff0047e84 MD5 · raw file

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