comparison test-data/util/shrink_tabix.py @ 0:3123ce7acd0e draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 62ed732cba355e695181924a8ed4cce49ca21c59
author iuc
date Fri, 11 Jan 2019 17:50:55 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3123ce7acd0e
1 from __future__ import print_function
2
3 import argparse
4
5 import pysam
6
7
8 def main(infile, ofile, region):
9 print(infile, '->', ofile)
10 with pysam.Tabixfile(infile) as i:
11 fformat = i.format.lower()
12 if fformat == 'sam':
13 fformat = 'bed'
14 if ofile[-3:] == '.gz':
15 ofile = ofile[:-3]
16 with open(ofile, 'w') as o:
17 try:
18 region_it = i.fetch(region=region)
19 except ValueError:
20 region_it = i.fetch(region='chr' + region)
21 for line in i.header:
22 o.write(line + '\n')
23 for line in region_it:
24 o.write(str(line) + '\n')
25 pysam.tabix_index(ofile, preset=fformat, force=True)
26
27
28 if __name__ == '__main__':
29 p = argparse.ArgumentParser()
30 p.add_argument('infile')
31 p.add_argument(
32 '-r', '--region',
33 required=True,
34 help='the region of the input file to rewrite'
35 )
36 p.add_argument(
37 '-o', '--ofile',
38 required=True,
39 help="the name of the output file"
40 )
41 args = vars(p.parse_args())
42 main(**args)