Debian Codegraph @

atac-driver/chainer/python/dedashMatches.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #!/usr/bin/python3
2
3 # dedashMatches.py /prod/IR02/synteny/mus-vs-rat/mouse_celera_R13_chr_20030210-vs-rat_celera_R1_chr_20030507-V3.atac.t20.l100.br.squeezed.filled.coalesced mus-vs-rat.out /prod/IR05/GENOMES/mouse_celera_R13_chr_20030210 /prod/IR05/GENOMES/rat_celera_R1_chr_20030507 MR13 RR1
4
5 # dedashMatches.py mouse_celera_R13_chr_20030210-vs-rat_celera_R1_chr_20030507-V3.atac.t20.l100.br.squeezed.filled.coalesced mus-vs-rat.out mouse_celera_R13_chr_20030210 rat_celera_R1_chr_20030507 MR13 RR1
6
7
8 import sys
9 import string
10 import time
11 import MatchRecord
12 import IdxStore
13 import halign
14
15 #import shelve
16
17 class dedasher:
18 def __init__(self,xstr,ystr):
19 pass
20 def __iter__(self):
21 return iter([1])
22
23 x = 3
24 def suba():
25 global x
26 x = 7
27 def subb():
28 global x
29 x -= 1
30 return (x,None)[x == 0]
31 def subc():
32 suba()
33 it = iter(subb,None)
34 for y in it:
•35 print(y)
36
37 def main( inpfile, outfile, xIdx, yIdx):
38 inpfile.seek(0)
39 outfile.seek(0)
40 lineCount = 0
41 t0 = time.time()
42 for line in inpfile:
43 lineCount += 1
44 if((lineCount % 10000)==0):
•45 print("lineCount=",lineCount," time=",time.time()-t0, file=sys.stderr)
46 if(line[0] == 'M'):
47 FM = MatchRecord.MatchRecord(line)
48 if(FM.subtype == 'g'):
49 parentid = FM.matchid
50 parent_x_forward = (FM.x_orientation == 1)
51 parent_y_forward = (FM.y_orientation == 1)
52 parent_x_start = FM.x_start
53 parent_y_start = FM.y_start
54 parent_x_length = FM.x_length
55 parent_y_length = FM.y_length
56
57 # Why two orientations and not just a flipped flag?
58 # Because we want the resulting matches to come out in
59 # the same sorted order as the input matches.
60
61 x_substring = string.upper(
62 xIdx.getStringFromFasta( parent_x_forward,
63 FM.x_scaf_uid, FM.x_start, FM.x_length));
64 y_substring = string.upper(
65 yIdx.getStringFromFasta( parent_y_forward,
66 FM.y_scaf_uid, FM.y_start, FM.y_length));
67 ii = 0
68 # Here we call the dedasher.
69 halign.halignStart(x_substring,
70 y_substring)
71 for segment in iter(halign.halignDedash,None):
72 #print >>outfile, segment
73 (bgn1,bgn2,len1,len2,nmat) = segment
74 # Filter by a minimum length? say four bp.
75 ii += 1
76 FM.subtype = 'u'
77 FM.matchid = parentid + 'u' + str(ii)
78 # FM.runid = parentid
79 FM.x_start = parent_x_start + (parent_x_length-bgn1-len1,bgn1)[parent_x_forward]
80 FM.y_start = parent_y_start + (parent_y_length-bgn2-len2,bgn2)[parent_y_forward]
81 FM.x_length = len1
82 FM.y_length = len2
83 assert(len1 == len2)
84 mismatches = 0
85 for ic in range(len1):
86 if(x_seq[bgn1+ic] != y_seq[bgn2+ic]):
87 mismatches += 1
88 FM.extend['mm'] = str(mismatches)
89 FM.identifier = "" # BEWARE
•90 print(FM, file=outfile)
91 else:
•92 print(line, end=' ', file=outfile)
93 else:
•94 print(line, end=' ', file=outfile)
95
96
97 def oldmain():
98 inpname = sys.argv[1]
99 outname = sys.argv[2]
100 xIndexName = sys.argv[3]
101 yIndexName = sys.argv[4]
102 assemblyId1 = sys.argv[5]
103 assemblyId2 = sys.argv[6]
104
105 # mismatches = checkExactMatches( x, y, inpfile)
106 # sys.stderr.write("mismatches = %d\n" % mismatches)
107
108 inpfile = open(inpname)
109 outfile = open(outname,"w")
110 xIdx = IdxStore.IdxStore(xIndexName,assemblyId1)
111 yIdx = IdxStore.IdxStore(yIndexName,assemblyId2)
112
113 main( inpfile, outfile, xIdx, yIdx)
114 outfile.close()
115
116 import AtacFile
117 import MyFile
118
119 def newmain():
120 inpname = sys.argv[1]
121 outname = sys.argv[2]
122
123 obj = AtacFile.AtacFile(inpname)
124 xname = obj.globals["assemblyFilePrefix1"]
125 yname = obj.globals["assemblyFilePrefix1"]
126 assemblyId1 = obj.globals["assemblyId1"]
127 assemblyId2 = obj.globals["assemblyId2"]
128
129
130 xIdx = IdxStore.IdxStore(xname,assemblyId1)
131 yIdx = IdxStore.IdxStore(yname,assemblyId2)
132
133 inpfile = obj.matches
134 outfile = MyFile.myfile()
135 main( inpfile, outfile, xIdx, yIdx)
136 obj.matches = outfile
137 obj.checkpoint(outname)
138 outfile.close()
139
140
141 # Allow each module to have its own main for testing.
142 if __name__ == '__main__':
143 newmain()
144 # end if