Mercurial > repos > iuc > gemini_stats
annotate test-data/util/shrink_tabix.py @ 6:73b103195e2a draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 251c6024b4ff643a63e17fbfe2590998c2bae3a7"
| author | iuc | 
|---|---|
| date | Fri, 24 Jan 2020 17:34:06 -0500 | 
| parents | cdd90678004a | 
| children | 
| rev | line source | 
|---|---|
| 
4
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
1 from __future__ import print_function | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
2 | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
3 import argparse | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
4 | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
5 import pysam | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
6 | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
7 | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
8 def main(infile, ofile, region): | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
9 print(infile, '->', ofile) | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
10 with pysam.Tabixfile(infile) as i: | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
11 fformat = i.format.lower() | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
12 if fformat == 'sam': | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
13 fformat = 'bed' | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
14 if ofile[-3:] == '.gz': | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
15 ofile = ofile[:-3] | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
16 with open(ofile, 'w') as o: | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
17 try: | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
18 region_it = i.fetch(region=region) | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
19 except ValueError: | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
20 region_it = i.fetch(region='chr' + region) | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
21 for line in i.header: | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
22 o.write(line + '\n') | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
23 for line in region_it: | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
24 o.write(str(line) + '\n') | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
25 pysam.tabix_index(ofile, preset=fformat, force=True) | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
26 | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
27 | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
28 if __name__ == '__main__': | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
29 p = argparse.ArgumentParser() | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
30 p.add_argument('infile') | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
31 p.add_argument( | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
32 '-r', '--region', | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
33 required=True, | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
34 help='the region of the input file to rewrite' | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
35 ) | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
36 p.add_argument( | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
37 '-o', '--ofile', | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
38 required=True, | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
39 help="the name of the output file" | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
40 ) | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
41 args = vars(p.parse_args()) | 
| 
 
cdd90678004a
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/gemini commit 283362494058ed64143b1f27afb447b8a1cb4313
 
iuc 
parents:  
diff
changeset
 | 
42 main(**args) | 
