comparison pileup_interval.py @ 4:9c1c0b947e46 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/pileup_interval commit 8b2095c59ecc2e94c58a42e2e04dbcecdc823dbf"
author devteam
date Fri, 15 Jan 2021 11:38:56 +0000
parents a110f9d6ae24
children
comparison
equal deleted inserted replaced
3:ef11139d4545 4:9c1c0b947e46
12 -s, --seq_column=s: Sequence column 12 -s, --seq_column=s: Sequence column
13 -l, --loc_column=l: Base location column 13 -l, --loc_column=l: Base location column
14 -r, --base_column=r: Reference base column 14 -r, --base_column=r: Reference base column
15 -C, --cvrg_column=C: Coverage column 15 -C, --cvrg_column=C: Coverage column
16 """ 16 """
17
18 from galaxy import eggs
19 import pkg_resources; pkg_resources.require( "bx-python" )
20 from bx.cookbook import doc_optparse
21 import sys 17 import sys
22 18
23 def stop_err( msg ): 19 from bx.cookbook import doc_optparse
24 sys.stderr.write( msg ) 20
25 sys.exit()
26 21
27 def __main__(): 22 def __main__():
28 strout = '' 23 # Parse Command Line
29 #Parse Command Line 24 options, args = doc_optparse.parse(__doc__)
30 options, args = doc_optparse.parse( __doc__ )
31 coverage = int(options.coverage) 25 coverage = int(options.coverage)
32 fin = file(options.input, 'r') 26 fin = open(options.input, 'r')
33 fout = file(options.output, 'w') 27 fout = open(options.output, 'w')
34 inLine = fin.readline() 28 inLine = fin.readline()
35 if options.format == 'six': 29 if options.format == 'six':
36 seqIndex = 0 30 seqIndex = 0
37 locIndex = 1 31 locIndex = 1
38 baseIndex = 2 32 baseIndex = 2
57 bases = [] 51 bases = []
58 while inLine.strip() != '': 52 while inLine.strip() != '':
59 lineParts = inLine.split('\t') 53 lineParts = inLine.split('\t')
60 try: 54 try:
61 seq, loc, base, cov = lineParts[seqIndex], int(lineParts[locIndex]), lineParts[baseIndex], int(lineParts[covIndex]) 55 seq, loc, base, cov = lineParts[seqIndex], int(lineParts[locIndex]), lineParts[baseIndex], int(lineParts[covIndex])
62 except IndexError, ei: 56 except IndexError as ei:
63 if options.format == 'ten': 57 if options.format == 'ten':
64 stop_err( 'It appears that you have selected 10 columns while your file has 6. Make sure that the number of columns you specify matches the number in your file.\n' + str( ei ) ) 58 sys.exit('It appears that you have selected 10 columns while your file has 6. Make sure that the number of columns you specify matches the number in your file.\n' + str(ei))
65 else: 59 else:
66 stop_err( 'There appears to be something wrong with your column index values.\n' + str( ei ) ) 60 sys.exit('There appears to be something wrong with your column index values.\n' + str(ei))
67 except ValueError, ev: 61 except ValueError as ev:
68 if options.format == 'six': 62 if options.format == 'six':
69 stop_err( 'It appears that you have selected 6 columns while your file has 10. Make sure that the number of columns you specify matches the number in your file.\n' + str( ev ) ) 63 sys.exit('It appears that you have selected 6 columns while your file has 10. Make sure that the number of columns you specify matches the number in your file.\n' + str(ev))
70 else: 64 else:
71 stop_err( 'There appears to be something wrong with your column index values.\n' + str( ev ) ) 65 sys.exit('There appears to be something wrong with your column index values.\n' + str(ev))
72 # strout += str(startLoc) + '\n' 66 # strout += str(startLoc) + '\n'
73 # strout += str(bases) + '\n' 67 # strout += str(bases) + '\n'
74 # strout += '%s\t%s\t%s\t%s\n' % (seq, loc, base, cov) 68 # strout += '%s\t%s\t%s\t%s\n' % (seq, loc, base, cov)
75 if loc == lastLoc+1 or lastLoc == -1: 69 if loc == lastLoc + 1 or lastLoc == -1:
76 if cov >= coverage: 70 if cov >= coverage:
77 if seq == lastSeq or lastSeq == '': 71 if seq == lastSeq or lastSeq == '':
78 if startLoc == -1: 72 if startLoc == -1:
79 startLoc = loc 73 startLoc = loc
80 locs.append(loc) 74 locs.append(loc)
81 bases.append(base) 75 bases.append(base)
82 else: 76 else:
83 if len(bases) > 0: 77 if len(bases) > 0:
84 fout.write('%s\t%s\t%s\t%s\n' % (lastSeq, startLoc-1, lastLoc, ''.join(bases))) 78 fout.write('%s\t%s\t%s\t%s\n' % (lastSeq, startLoc - 1, lastLoc, ''.join(bases)))
85 startLoc = loc 79 startLoc = loc
86 locs = [loc] 80 locs = [loc]
87 bases = [base] 81 bases = [base]
88 else: 82 else:
89 if len(bases) > 0: 83 if len(bases) > 0:
90 fout.write('%s\t%s\t%s\t%s\n' % (lastSeq, startLoc-1, lastLoc, ''.join(bases))) 84 fout.write('%s\t%s\t%s\t%s\n' % (lastSeq, startLoc - 1, lastLoc, ''.join(bases)))
91 startLoc = -1 85 startLoc = -1
92 locs = [] 86 locs = []
93 bases = [] 87 bases = []
94 else: 88 else:
95 if len(bases) > 0: 89 if len(bases) > 0:
96 fout.write('%s\t%s\t%s\t%s\n' % (lastSeq, startLoc-1, lastLoc, ''.join(bases))) 90 fout.write('%s\t%s\t%s\t%s\n' % (lastSeq, startLoc - 1, lastLoc, ''.join(bases)))
97 if cov >= coverage: 91 if cov >= coverage:
98 startLoc = loc 92 startLoc = loc
99 locs = [loc] 93 locs = [loc]
100 bases = [base] 94 bases = [base]
101 else: 95 else:
104 bases = [] 98 bases = []
105 lastSeq = seq 99 lastSeq = seq
106 lastLoc = loc 100 lastLoc = loc
107 inLine = fin.readline() 101 inLine = fin.readline()
108 if len(bases) > 0: 102 if len(bases) > 0:
109 fout.write('%s\t%s\t%s\t%s\n' % (lastSeq, startLoc-1, lastLoc, ''.join(bases))) 103 fout.write('%s\t%s\t%s\t%s\n' % (lastSeq, startLoc - 1, lastLoc, ''.join(bases)))
110 fout.close() 104 fout.close()
111 fin.close() 105 fin.close()
112
113 # import sys 106 # import sys
114 # strout += file(fout.name,'r').read() 107 # strout += file(fout.name,'r').read()
115 # sys.stderr.write(strout) 108 # sys.stderr.write(strout)
116 109
117 if __name__ == "__main__" : __main__() 110
111 if __name__ == "__main__":
112 __main__()