-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdebreak_detect.py
534 lines (501 loc) · 17.7 KB
/
debreak_detect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
import pysam
import time
import os
def cigardeletion(flag,chrom,position,cigar,min_size,max_size): #input a read line, return list of deletions
flag=int(flag)
if flag<=16:
detect_cigar_sv=True
else:
detect_cigar_sv=False
pos=int(position)
numbers='1234567890'
num=''
reflen=0
readlen=0
leftclip=0
rightclip=0
deletions=[]
insertions=[]
for c in cigar:
if c in numbers:
num+=c
continue
if c in 'MNP=X':
readlen+=int(num); reflen+=int(num); num=''; continue
if c=='I':
if detect_cigar_sv and int(num)>=min_size and int(num)<=max_size:
insertions+=[[chrom,pos+reflen,int(num),'I-cigar',readlen+leftclip]]
readlen+=int(num)
num=''; continue
if c == 'D':
if detect_cigar_sv and int(num)>=min_size and int(num)<=max_size:
deletions+=[[chrom,pos+reflen,int(num),'D-cigar']]
reflen+=int(num); num=''; continue
if c in 'SH':
if readlen==0:
leftclip=int(num)
else:
rightclip=int(num)
num=''; continue
#merge deletions
if detect_cigar_sv:
testif=1
window=500
while testif==1:
testif=0
if len(deletions)==1:
break
i=len(deletions)-1
while i>0:
gaplength=deletions[i][1]-deletions[i-1][1]-deletions[i-1][2]
if gaplength <= window:
deletions=deletions[:i-1]+[[chrom,deletions[i-1][1],deletions[i-1][2]+deletions[i][2],'D-cigar']]+deletions[i+1:]
testif=1
break
else:
i-=1
#merge insertions
testif=1
while testif==1:
testif=0
if len(insertions)==1:
break
i=len(insertions)-1
while i>0:
l1=insertions[i][2]
l2=insertions[i-1][2]
gaplength=insertions[i][1]-insertions[i-1][1]
window=200 if max(l1,l2)<100 else 400
window=400 if window==400 and max(l1,l2) <500 else 600
if gaplength >window :
i-=1
else:
insertions=insertions[:i-1]+[[chrom,insertions[i-1][1],l1+l2,'I-cigar',insertions[i-1][4]]]+insertions[i+1:]
testif=1
break
svcallset=deletions+insertions
return [svcallset,reflen,[leftclip,readlen,rightclip]]
def simplifycigar(cigar):
numbers='1234567890'
num=''
readlen=0
leftclip=0
rightclip=0
for c in cigar:
if c in numbers:
num+=c; continue
if c in 'MNP=XI':
readlen+=int(num); num=''; continue
if c == 'D':
num=''; continue
if c in 'SH':
if readlen==0:
leftclip=int(num)
num=''
else:
rightclip=int(num)
num=''
return [leftclip,readlen,rightclip]
def segmentdeletion(segments,min_size,max_size): #input a list of segments,return list of deletions
if len([c for c in segments if int(c[1])<=16])==0:
return []
if len(segments)<=1:
return []
svcallset=[]
primary=[c for c in segments if int(c[1])<=16][0]
segments=[c for c in segments if c != primary]
readseq=primary[7]
chrom=primary[2]
priflag=(int(primary[1])%32)>15
samedirchr=[]
samechr=[]
diffchr=[]
rawsegsvid=1
for c in segments:
ch=c[2]
f=int(c[1])%32>15
if c[5][1]<300:
continue
if ch!=chrom:
diffchr+=[c]
elif f!=priflag:
samechr+=[c]
else:
samedirchr+=[c]
for c in samedirchr:
if c[3]>primary[3] :
leftread=primary
rightread=c
elif c[3]<primary[3]:
leftread=c
rightread=primary
else:
continue
leftinfo=leftread[5]
rightinfo=rightread[5]
#insertion:
if abs(rightread[3]-leftread[4])<=300:
overlap=rightread[3]-leftread[4]
ins_size=rightinfo[0]-leftinfo[1]-leftinfo[0]-overlap
if min_size<=ins_size<=max_size:
svcallset+=[chrom+'\t'+str(min(rightread[3],leftread[4]))+'\t'+str(ins_size)+'\t'+'I-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(int(c[1])+int(primary[1]))+'\t'+str((int(c[6])+int(primary[6]))//2)+'\t'+readseq[leftinfo[0]+leftinfo[1]:rightinfo[0]-overlap]]
rawsegsvid+=1
#deletion:
overlapmap=leftinfo[0]+leftinfo[1]-rightinfo[0]
window_max=1500
if -200<overlapmap<window_max:
del_size=rightread[3]-leftread[4]+overlapmap
if min_size<=del_size<=max_size:
svcallset+=[chrom+'\t'+str(max(0,leftread[4]-max(0,overlapmap)))+'\t'+str(del_size)+'\t'+'D-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
#duplication:
overlapmap=leftinfo[0]+leftinfo[1]-rightinfo[0]
window_max=500
if -200<overlapmap<window_max and leftread[4]-rightread[3]>=max(50,overlapmap):
dup_size=leftread[4]-rightread[3]-max(overlapmap,0)
if min_size<=dup_size<=max_size:
svcallset+=[chrom+'\t'+str(rightread[3])+'\t'+str(dup_size)+'\t'+'DUP-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
overlapmap=rightinfo[0]+rightinfo[1]-leftinfo[0]
if -200<overlapmap<window_max and (rightread[4]-leftread[3])>=max(1000,overlapmap):
dup_size=rightread[4]-leftread[3]-overlapmap
if min_size<=dup_size<=max_size:
svcallset+=[chrom+'\t'+str(leftread[3])+'\t'+str(dup_size)+'\t'+'DUP-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
#inversion:
for c in samechr:
if c[3]>primary[3] and c[4]-primary[4]>-200:
leftread=primary
rightread=c
elif c[3]<primary[3] and primary[4]-c[4]>-200:
leftread=c
rightread=primary
else:
continue
leftinfo=leftread[5]
rightinfo=rightread[5]
window_max=500
overlapmap=rightinfo[0]+rightinfo[1]-leftinfo[2]
if -200<overlapmap<window_max and (rightread[4]-leftread[4])>=max(100,overlapmap):
inv_size=rightread[4]-leftread[4]-overlapmap
if min_size<=inv_size<=max_size:
svcallset+=[chrom+'\t'+str(leftread[4])+'\t'+str(inv_size)+'\t'+'INV-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
continue
overlapmap=rightinfo[1]+rightinfo[2]-leftinfo[0]
if -200<overlapmap<window_max and (rightread[3]-leftread[3])>=max(100,overlapmap):
inv_size=rightread[3]-leftread[3]-overlapmap
if min_size<=inv_size<=max_size:
svcallset+=[chrom+'\t'+str(leftread[3])+'\t'+str(inv_size)+'\t'+'INV-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
continue
#translocation:
for c in diffchr:
pinfo=primary[5]
cinfo=c[5]
window_max=200
bp1=''
bp2=''
if abs(pinfo[0]-cinfo[0]-cinfo[1])<=window_max or abs(pinfo[0]-cinfo[1]-cinfo[2])<=window_max:
chrom1=primary[2]
bp1=primary[3]
elif abs(pinfo[2]-cinfo[0]-cinfo[1])<=window_max or abs(pinfo[2]-cinfo[1]-cinfo[2])<=window_max:
chrom1=primary[2]
bp1=primary[4]
if abs(cinfo[0]-pinfo[0]-pinfo[1])<=window_max or abs(cinfo[0]-pinfo[1]-pinfo[2])<=window_max:
chrom2=c[2]
bp2=c[3]
elif abs(cinfo[2]-pinfo[0]-pinfo[1])<=window_max or abs(cinfo[2]-pinfo[1]-pinfo[2])<=window_max:
chrom2=c[2]
bp2=c[4]
if bp1!='' and bp2!='':
if chrom1 > chrom2:
svcallset+=[chrom2+'\t'+str(bp2)+'\t'+chrom1+'\t'+str(bp1)+'\tTRA-segment\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
if chrom1 < chrom2:
svcallset+=[chrom1+'\t'+str(bp1)+'\t'+chrom2+'\t'+str(bp2)+'\tTRA-segment\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
return svcallset
def segmentdeletion_tumor(segments,min_size,max_size): #input a list of segments,return list of deletions
svcallset=[]
for i in range(len(segments)-1):
primary=segments[i]
others=segments[i+1:]
chrom=primary[2]
priflag=(int(primary[1])%32)>15
samedirchr=[]
samechr=[]
diffchr=[]
rawsegsvid=1
for c in others:
ch=c[2]
f=int(c[1])%32>15
if c[5][1]<300:
continue
if ch!=chrom:
diffchr+=[c]
elif f!=priflag:
samechr+=[c]
else:
samedirchr+=[c]
for c in samedirchr:
if c[3]>primary[3] :
leftread=primary
rightread=c
elif c[3]<primary[3]:
leftread=c
rightread=primary
else:
continue
leftinfo=leftread[5]
rightinfo=rightread[5]
#insertion:
if abs(rightread[3]-leftread[4])<=300:
overlap=rightread[3]-leftread[4]
ins_size=rightinfo[0]-leftinfo[1]-leftinfo[0]-overlap
if min_size<=ins_size<=max_size:
svcallset+=[chrom+'\t'+str(min(rightread[3],leftread[4]))+'\t'+str(ins_size)+'\t'+'I-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(int(c[1])+int(primary[1]))+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
#deletion:
overlapmap=leftinfo[0]+leftinfo[1]-rightinfo[0]
window_max=1500
if -200<overlapmap<window_max:
del_size=rightread[3]-leftread[4]+overlapmap
if min_size<=del_size<=max_size:
svcallset+=[chrom+'\t'+str(leftread[4]-max(0,overlapmap))+'\t'+str(del_size)+'\t'+'D-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
#duplication:
overlapmap=leftinfo[0]+leftinfo[1]-rightinfo[0]
window_max=500
if -200<overlapmap<window_max and leftread[4]-rightread[3]>=max(50,overlapmap):
dup_size=leftread[4]-rightread[3]-max(overlapmap,0)
if min_size<=dup_size<=max_size:
svcallset+=[chrom+'\t'+str(rightread[3])+'\t'+str(dup_size)+'\t'+'DUP-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
overlapmap=rightinfo[0]+rightinfo[1]-leftinfo[0]
if -200<overlapmap<window_max and (rightread[4]-leftread[3])>=max(1000,overlapmap):
dup_size=rightread[4]-leftread[3]-overlapmap
if min_size<=dup_size<=max_size:
svcallset+=[chrom+'\t'+str(leftread[3])+'\t'+str(dup_size)+'\t'+'DUP-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
#inversion:
for c in samechr:
if c[3]>primary[3] and c[4]-primary[4]>-200:
leftread=primary
rightread=c
elif c[3]<primary[3] and primary[4]-c[4]>-200:
leftread=c
rightread=primary
else:
continue
leftinfo=leftread[5]
rightinfo=rightread[5]
window_max=500
overlapmap=rightinfo[0]+rightinfo[1]-leftinfo[2]
if -200<overlapmap<window_max and (rightread[4]-leftread[4])>=max(100,overlapmap):
inv_size=rightread[4]-leftread[4]-overlapmap
if min_size<=inv_size<=max_size:
svcallset+=[chrom+'\t'+str(leftread[4])+'\t'+str(inv_size)+'\t'+'INV-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
continue
overlapmap=rightinfo[1]+rightinfo[2]-leftinfo[0]
if -200<overlapmap<window_max and (rightread[3]-leftread[3])>=max(100,overlapmap):
inv_size=rightread[3]-leftread[3]-overlapmap
if min_size<=inv_size<=max_size:
svcallset+=[chrom+'\t'+str(leftread[3])+'\t'+str(inv_size)+'\t'+'INV-segment'+'\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
continue
#translocation:
for c in diffchr:
pinfo=primary[5]
cinfo=c[5]
window_max=200
bp1=''
bp2=''
if abs(pinfo[0]-cinfo[0]-cinfo[1])<=window_max or abs(pinfo[0]-cinfo[1]-cinfo[2])<=window_max:
chrom1=primary[2]
bp1=primary[3]
elif abs(pinfo[2]-cinfo[0]-cinfo[1])<=window_max or abs(pinfo[2]-cinfo[1]-cinfo[2])<=window_max:
chrom1=primary[2]
bp1=primary[4]
if abs(cinfo[0]-pinfo[0]-pinfo[1])<=window_max or abs(cinfo[0]-pinfo[1]-pinfo[2])<=window_max:
chrom2=c[2]
bp2=c[3]
elif abs(cinfo[2]-pinfo[0]-pinfo[1])<=window_max or abs(cinfo[2]-pinfo[1]-pinfo[2])<=window_max:
chrom2=c[2]
bp2=c[4]
if bp1!='' and bp2!='':
if chrom1 > chrom2:
svcallset+=[chrom2+'\t'+str(bp2)+'\t'+chrom1+'\t'+str(bp1)+'\tTRA-segment\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
if chrom1 < chrom2:
svcallset+=[chrom1+'\t'+str(bp1)+'\t'+chrom2+'\t'+str(bp2)+'\tTRA-segment\t'+primary[0]+'_seg'+str(rawsegsvid)+'\t'+str(c[1])+'\t'+str((int(c[6])+int(primary[6]))//2)]
rawsegsvid+=1
return svcallset
def detect_sam(filename,readpath,writepath,chromosomes,min_size,max_size,record_depth,if_rawsvcall):
print('Start to detect SVs from '+filename)
f=pysam.AlignmentFile(readpath+filename,'r')
allread=f.fetch()
if if_rawsvcall:
g=open(writepath+'sv_raw_calls/'+filename[:-4]+'.debreak.temp','w')
else:
g=open(writepath+filename[:-4]+'.debreak.temp','w')
lastname=''
segments=['']
totalmaplength=0
for c in allread:
#remove headerlines, secondary alignments, alignment on scallfolds
if c.is_secondary or c.flag==4:
continue
if chromosomes!=[] and c.reference_name not in chromosomes:
continue
#detect the deletion from cigar
readname=c.query_name
flag=str(c.flag)
chrom=c.reference_name
position=c.reference_start
mappingquality=str(c.mapq)
readseq=c.query_sequence
cigar=c.cigarstring
cigarinfo=cigardeletion(flag,chrom,position,cigar,min_size,max_size)
refend=position+cigarinfo[1]
cimplecigar=str(cigarinfo[2][0])+'\t'+str(cigarinfo[2][1])+'\t'+str(cigarinfo[2][2])
# if primary: write deletions from cigar string
if not c.is_supplementary:
cigarsv=cigarinfo[0]
totalmaplength+=c.query_length
rawsvid=0
for d in cigarsv:
rawsvid+=1
if 'I-cigar' in d:
insertseq=readseq[d[4]:d[4]+d[2]]
g.write(d[0]+'\t'+str(d[1])+'\t'+str(d[2])+'\t'+d[3]+'\t'+readname+'_cigar'+str(rawsvid)+'\t'+flag+'\t'+mappingquality+'\t'+insertseq+'\n')
else:
g.write(d[0]+'\t'+str(d[1])+'\t'+str(d[2])+'\t'+d[3]+'\t'+readname+'_cigar'+str(rawsvid)+'\t'+flag+'\t'+mappingquality+'\n')
readinfo=[readname,flag,chrom,position,refend,cigarinfo[2],mappingquality,readseq]
else:
readinfo=[readname,flag,chrom,position,refend,cigarinfo[2],mappingquality,'']
if readname!=lastname:
if 1<len(segments)<=20:
segmentd=segmentdeletion(segments,min_size,max_size)
for d in segmentd:
g.write(d+'\n')
lastname=readname
segments=[readinfo]
else:
segments+=[readinfo]
if 1<len(segments)<=20:
segmentd=segmentdeletion(segments,min_size,max_size)
for d in segmentd:
g.write(d+'\n')
segments=[]
f.close()
g.close()
if record_depth and totalmaplength>0:
f=open(writepath+'map_depth/maplength_'+filename,'w')
f.write(str(totalmaplength)+'\n')
f.close()
return True
def detect_sortbam(filename,writepath,min_size,max_size,chrom,chromosomes,record_clip,ifrescuedup,iftumor):
print ('Start to detect SV from '+filename)
samfile=pysam.AlignmentFile(filename,"rb")
tempfile=open(writepath+'sv_raw_calls/'+filename.split('/')[-1]+'-'+chrom+'.debreak.temp','w')
allreads=samfile.fetch(chrom)
segmentreads={}
tracandidate=[]
clipinfo=[]
totalmaplength=0
for align in allreads:
if align.is_unmapped or align.is_secondary:
continue
readname=align.query_name
flag=align.flag
position=align.reference_start+1
mappingquality=align.mapping_quality
cigar=align.cigar
readclipinfo=chrom
readstart=align.reference_start
readstop=align.reference_end
if record_clip and ( cigar[0][0] in [4,5] and cigar[0][1]>=200 ) or (cigar[-1][0] in [4,5] and cigar[-1][1]>=200):
if (cigar[0][0]==4 or cigar[0][0]==5) and cigar[0][1]>=200:
readclipinfo+='\t0\t'+str(readstart)
else:
readclipinfo+='\t'+str(readstart)+'\t0'
if (cigar[-1][0]==4 or cigar[-1][0]==5) and cigar[-1][1]>=200:
readclipinfo+='\t0\t'+str(readstop)
else:
readclipinfo+='\t'+str(readstop)+'\t0'
clipinfo+=[readclipinfo]
if align.is_supplementary:
cigarinfo=[0,0,0]
cigarleft=align.cigar[0]
cigarright=align.cigar[-1]
if cigarleft[0]==4 or cigarleft[0]==5:
cigarinfo[0]=cigarleft[1]
if cigarright[0]==4 or cigarright[0]==5:
cigarinfo[2]=cigarright[1]
cigarinfo[1]=align.query_alignment_length
refend=align.reference_end+1
readinfo=[readname,flag,chrom,int(position),refend,cigarinfo,mappingquality,'']
if readname in segmentreads:
segmentreads[readname]+=[readinfo]
else:
segmentreads[readname]=[readinfo]
else:
cigar=align.cigarstring
readseq=align.query_sequence
cigarinfo=cigardeletion(flag,chrom,position,cigar,min_size,max_size)
cigarsv=cigarinfo[0]
totalmaplength+=align.query_length
rawsvid=0
for d in cigarsv:
rawsvid+=1
if 'I-cigar' in d:
insertseq=readseq[d[4]:d[4]+d[2]]
if ifrescuedup:
rawseq=readseq[:d[4]]+readseq[d[4]+d[2]:]
else:
rawseq=''
tempfile.write(d[0]+'\t'+str(d[1])+'\t'+str(d[2])+'\t'+d[3]+'\t'+readname+'_cigar'+str(rawsvid)+'\t'+str(flag)+'\t'+str(mappingquality)+'\t'+str(d[4])+'\t'+insertseq+'\t'+rawseq+'\n')
else:
tempfile.write(d[0]+'\t'+str(d[1])+'\t'+str(d[2])+'\t'+d[3]+'\t'+readname+'_cigar'+str(rawsvid)+'\t'+str(flag)+'\t'+str(mappingquality)+'\n')
if align.has_tag("SA"):
refend=position+cigarinfo[1]
readinfo=[readname,flag,chrom,position,refend,cigarinfo[2],mappingquality,align.query_sequence]
if readname in segmentreads:
segmentreads[readname]+=[readinfo]
else:
segmentreads[readname]=[readinfo]
suppaligns=align.get_tag("SA").split(';')[:-1]
diffchr=[]
for c in suppaligns:
if c.split(',')[0]==chrom or c.split(',')[0] not in chromosomes:
continue
if c.split(',')[2]=='+':
suppflag=2048
else:
suppflag=2064
cigarinfo=simplifycigar(c.split(',')[3])
suppinfo=[readname,suppflag,c.split(',')[0],int(c.split(',')[1]),int(c.split(',')[1])+cigarinfo[1],cigarinfo,c.split(',')[4]]
segmentreads[readname]+=[suppinfo]
for readgroup in segmentreads:
if len(segmentreads[readgroup])<2 or len(segmentreads[readgroup])>20:
continue
if iftumor:
segmentsv=segmentdeletion_tumor(segmentreads[readgroup],min_size,max_size)
else:
segmentsv=segmentdeletion(segmentreads[readgroup],min_size,max_size)
for d in segmentsv:
tempfile.write(d+'\n')
tempfile.close()
if record_clip:
f=open(writepath+'debreak_ins_workspace/readinfo_start_end_'+chrom,'w')
for c in clipinfo:
f.write(c+'\n')
f.close()
print (chrom+' is done with maplength: '+str(totalmaplength))
if totalmaplength!=0:
f=open(writepath+'map_depth/maplength_'+chrom,'w')
f.write(str(totalmaplength)+'\n')
f.close()
return True