-
Notifications
You must be signed in to change notification settings - Fork 6
/
contig.py
756 lines (679 loc) · 26.7 KB
/
contig.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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
__author__ = 'hervemn'
from fragment import fragment
class contig():
def __init__(self ,):
"standart init "
@classmethod
def initiate(cls,init_contig,id_frag_start,id_frag_end,orientation):
obj = cls()
obj.name = obj.init_contig_name(init_contig,id_frag_start,id_frag_end,orientation)
obj.length_kb = 0
obj.n_frags = 0
obj.kb_metric = [0]
obj.FragmentS = []
obj.orientation = orientation
obj.status = 'active'
obj.old_2_new = dict()
obj.old_2_new['0:-1'] = {'contig_id':'self', 'position':1, 'orientation':'w'}
obj.new_compo = []
obj.new_compo.append({'contig_id':'self','position':1,'orientation':'w','start':1,'end':-1,'dup':False})
obj.composition = []
obj.contig_id = 0
####################
init_compo = dict()
init_compo['init_contig'] = init_contig
init_compo['id_frag_start'] = id_frag_start
init_compo['id_frag_end'] = id_frag_end
init_compo['orientation'] = orientation
init_compo['pos_id'] = 1
#####################
obj.composition.append(init_compo)
return obj
def to_string(self, reverse):
import string
out = ""
if reverse:
for i in range(len(self.FragmentS) - 1, -1, -1):
f = self.FragmentS[i]
out = out + f.init_name + f.orientation.translate(string.maketrans('wc', 'cw'))
else:
for f in self.FragmentS:
out = out + f.init_name + f.orientation
return out
def init_contig_name(self,name,id_frag_start,id_frag_end,orientation):
new_name = '>'+name+':'+str(id_frag_start)+':'+str(id_frag_end)+':'+ orientation +'>'
return new_name
def update_name(self,contig_id):
self.contig_id = contig_id
if self.old_2_new.has_key('0:-1'):
if self.old_2_new['0:-1']['contig_id'] == 'self':
self.old_2_new.pop('0:-1')
start = str(1)
end = str(self.n_frags)
name_0 = start+':'+end
self.old_2_new[name_0] = dict()
self.old_2_new[name_0]['contig_id'] = contig_id
self.old_2_new[name_0]['position'] = 1
self.old_2_new[name_0]['orientation'] = 'w'
for ele in self.new_compo:
if ele['contig_id'] == 'self':
ele['contig_id'] = contig_id
ele['end'] = self.n_frags
#update fragments name
for f in self.FragmentS:
f.update_name(contig_id)
def update_repeats(self,old_instance_2_new_instance):
"""udpate repeats name in contig"""
from colorama import Fore, Back, Style
from colorama import init
init(autoreset=True)
print " -------------------------------"
print Fore.BLUE + " update contig name:"+self.name
for ele in self.new_compo:
if ele["dup"]:
old_contig_id = ele["contig_id"]
new_contig_id = old_instance_2_new_instance[old_contig_id]["new_instance"]
ele["contig_id"] = new_contig_id
print "new_compo" + Fore.RED + str(old_contig_id) + " --->" +Fore.GREEN + str(new_contig_id)
def append_fragment(self,fragment,orientation):
import numpy as np
self.kb_metric.append(self.kb_metric[-1] + fragment.length_kb/2)
ind_frag = self.n_frags + 1
fragment.curr_id = ind_frag
fragment.orientation = orientation
self.length_kb += fragment.length_kb
fragment.pos_kb = np.copy(self.kb_metric[-1])
self.FragmentS.append(fragment)
self.n_frags = ind_frag
def reset_old_2_new_new_compo(self):
self.old_2_new = dict()
access_bloc = "1:" + str(self.n_frags)
self.old_2_new[access_bloc] = dict()
self.old_2_new[access_bloc]["orientation"] = "w"
self.old_2_new[access_bloc]["contig_id"] = self.contig_id
self.old_2_new[access_bloc]["position"] = 1
if self.new_compo[0]["dup"]:
is_duplicate = True
else:
is_duplicate = False
self.new_compo = []
tmp_new_compo = dict()
tmp_new_compo["contig_id"] = self.contig_id
tmp_new_compo["orientation"] = "w"
tmp_new_compo["position"] = 1
tmp_new_compo["start"] = 1
tmp_new_compo["end"] = self.n_frags
tmp_new_compo["dup"] = is_duplicate
self.new_compo.append(tmp_new_compo)
def have_to_split(self, pos):
if (pos == 0) or (pos >= self.n_frags - 1): # added 23 /02/2013 nfrags - 1
output = False
else:
output = True
return output
def return_extremity(self,extremity,orientation):
## extremity = left or right
sub_parts = self.old_2_new.keys()
first_coords = []
for ele in sub_parts:
tmp = ele.split(':')
first_coords.append(int(tmp[0]))
new_index = sorted(range(len(first_coords)), key=lambda k: first_coords[k])
print "contig name = ",self.name
print new_index
print sub_parts
ext = extremity == 'right'
ori = orientation == 'w'
test = (ext and ori) or (not(ext) and not(ori))
if test:
return sub_parts[new_index[-1]]
else:
return sub_parts[new_index[0]]
def vect_orientation(self,):
orientation = []
for ele in self.composition:
n_frag = ele['id_frag_end'] - ele['id_frag_start'] + 1
ori = ele['orientation']
for i in range(0,n_frag):
orientation.append(ori)
return orientation
def reverse_name(self,):
import string
data = self.name.split('-')
n = len(data)
reverso = range(n-1,-1,-1)
cumul_init = []
for ele in reverso:
tmp = data[ele]
bloc = tmp[:-2]+tmp[-2].translate(string.maketrans('wc', 'cw')) + '>'
cumul_init.append(bloc)
output = string.join(cumul_init,'-')
return output
def sub_content(self,pos_a,pos_b):
# a modifier comme le split !!!!!!!!!!!!!!!!!!!!!!!!
from copy import deepcopy as deepcopy
## composition split
n_compo = len(self.composition)
compo1 = []
id_frag = 0
f = deepcopy(self.FragmentS)
frag1 = []
stop = False
position = 0
n_frags_prec = 0
for ele in range(0,n_compo):
out_cond = True
data = self.composition[ele]
orientation = data['orientation']
start = data['id_frag_start']
start0 = data['id_frag_start']
end = data['id_frag_end']
tmp_compo = dict()
tmp_compo['orientation'] = data['orientation']
n_frags_local = end - start0 + 1
if orientation == 'w':
# index_frag = range(start,end+1)
index_frag = range(1,n_frags_local + 1)
else:
# index_frag = range(end,start-1,-1)
index_frag = range(n_frags_local,0,-1)
tmp_compo['init_contig'] = data['init_contig']
n_frags = end - start + 1
id_rel = 0
id_rel_2 = 0
for i in index_frag:
id_rel += 1
id_frag += 1
if ((id_frag>=pos_a) and (id_frag<=pos_b)):
id_rel_2 += 1
if id_rel_2 ==1:
position +=1
tmp_compo['pos_id'] = position
## splitting fragments
frag1.append(f[n_frags_prec + i-1])
if id_frag == pos_a:
start = i
end = i
if orientation == 'w':
tmp_compo['id_frag_start'] = start
tmp_compo['id_frag_end'] = i + (start0 -1)
else:
tmp_compo['id_frag_start'] = i + (start0 -1)
tmp_compo['id_frag_end'] = end
if id_frag == pos_b:
if (id_rel == n_frags):
out_cond = False
stop = True
compo1.append(tmp_compo)
if (out_cond and not(stop)):
compo1.append(tmp_compo)
n_frags_prec += n_frags_local
## new composition split
new_n_compo = len(self.new_compo)
new_compo1 = []
id_frag = 0
stop = False
position = 0
for ele in range(0,new_n_compo):
out_cond = True
data = self.new_compo[ele]
orientation = data['orientation']
start = data['start']
start0 = data['start']
end = data['end']
tmp_compo = dict()
tmp_compo['orientation'] = data['orientation']
# the bloc has been duplicated force it here ??
tmp_compo['dup'] = data['dup']
if orientation == 'w':
# index_frag = range(start,end+1)
index_frag = range(1,n_frags_local + 1)
else:
# index_frag = range(end,start-1,-1)
index_frag = range(n_frags_local,0,-1)
tmp_compo['contig_id'] = data['contig_id']
n_frags = end - start + 1
id_rel = 0
id_rel_2 = 0
for i in index_frag:
id_rel += 1
id_frag += 1
if ((id_frag>=pos_a) and (id_frag<=pos_b)):
id_rel_2 +=1
if id_rel_2 ==1:
position +=1
tmp_compo['position'] = position
if id_frag == pos_a:
start = i
end = i
if orientation == 'w':
tmp_compo['start'] = start
tmp_compo['end'] = i + (start0 -1)
else:
tmp_compo['start'] = i + (start0 -1)
tmp_compo['end'] = end
if (id_frag == pos_b):
if (id_rel == n_frags):
out_cond = False
new_compo1.append(tmp_compo)
stop = True
if (out_cond and not(stop)):
new_compo1.append(tmp_compo)
return frag1, compo1, new_compo1
def split_content(self,pos_cut):
import string
import numpy as np
#### To correct !!! ####
from copy import deepcopy as deepcopy
## composition split
n_compo = len(self.composition)
compo1 = []
compo2 = []
id_frag = 0
active_compo = compo1
f = deepcopy(self.FragmentS)
frag1 = []
frag2 = []
active_frag = 1
position = 0
n_frags_prec = 0
already_split = False
for ele in range(0,n_compo):
out_cond = True
data = self.composition[ele]
orientation = data['orientation']
start = data['id_frag_start']
start0 = data['id_frag_start']
end = data['id_frag_end']
tmp_compo = dict()
tmp_compo['orientation'] = data['orientation']
n_frags_local = end - start0 + 1
if orientation == 'w':
# index_frag = range(start,end+1)
index_frag = range(1,n_frags_local + 1)
else:
# index_frag = range(end,start-1,-1)
index_frag = range(n_frags_local,0,-1)
tmp_compo['init_contig'] = data['init_contig']
n_frags = end - start + 1
id_rel = 0
for i in index_frag:
id_rel += 1
id_frag += 1
## splitting fragments
## Attention la position de split correspond deja a l'index de coupure dans self.FragmentS
## donc pas besoin de changer la facon dde progresser dans la liste fragments
if active_frag == 1:
# frag1.append(f[n_frags_prec + i-1])
frag1.append(f[id_frag - 1])
elif active_frag == 2:
# frag2.append(f[n_frags_prec + i-1])
frag2.append(f[id_frag - 1])
if id_rel == 1 :
position +=1
tmp_compo['pos_id'] = position
if orientation == 'w':
tmp_compo['id_frag_start'] = start
tmp_compo['id_frag_end'] = i + (start0 -1)
else:
tmp_compo['id_frag_start'] = i + (start0 -1)
tmp_compo['id_frag_end'] = end
if id_frag == pos_cut:
if (id_rel == n_frags):
out_cond = False
already_split = True# added rv :: be careful
active_compo.append(tmp_compo)
active_compo = compo2
position = 0
tmp_compo = dict()
tmp_compo['init_contig'] = data['init_contig']
tmp_compo['orientation'] = data['orientation']
position +=1
tmp_compo['pos_id'] = position
if orientation == 'w':
start = i + 1 + (start0 -1)
else:
end = i - 1 + (start0 -1)
position = 0 # added rv
active_frag = 2
if out_cond:
active_compo.append(tmp_compo)
n_frags_prec += n_frags_local
## new composition split
new_n_compo = len(self.new_compo)
# print " new n compo = ", new_n_compo
# print self.new_compo
new_compo1 = []
new_compo2 = []
id_frag = 0
new_active_compo = new_compo1
position = 0
already_split = False
for ele in range(0,new_n_compo):
out_cond = True
data = self.new_compo[ele]
orientation = data['orientation']
start = data['start']
start0 = data['start']
end = data['end']
tmp_compo = dict()
tmp_compo['orientation'] = data['orientation']
# print 'contitg id = ', data['contig_id']
# print 'champs dup ', data['dup']
tmp_compo['dup'] = data['dup']
n_frags_local = end - start0 + 1
if orientation == 'w':
# index_frag = range(start,end+1)
index_frag = range(1,n_frags_local+1)
else:
# index_frag = range(end,start-1,-1)
index_frag = range(n_frags_local,0,-1)
tmp_compo['contig_id'] = data['contig_id']
n_frags = end - start + 1
id_rel = 0
for i in index_frag:
id_rel += 1
id_frag += 1
if id_rel == 1 : # added rv :: be careful
position +=1
tmp_compo['position'] = position
if orientation == 'w':
tmp_compo['start'] = start
tmp_compo['end'] = i + (start0 -1)
else:
tmp_compo['start'] = i + (start0 -1)
tmp_compo['end'] = end
if id_frag == pos_cut:
if (id_rel == n_frags):
out_cond = False
already_split = True # added rv :: be careful
new_active_compo.append(tmp_compo)
new_active_compo = new_compo2
tmp_compo = dict()
position = 0
# position = 1
tmp_compo['contig_id'] = data['contig_id']
tmp_compo['orientation'] = data['orientation']
tmp_compo['dup'] = data['dup']
position +=1
tmp_compo['position'] = position
if orientation == 'w':
start = i + 1 + (start0 -1)
else:
end = i - 1 + (start0 -1)
position = 0 # added rv :: be careful
if out_cond:
new_active_compo.append(tmp_compo)
return frag1, compo1, new_compo1, frag2, compo2, new_compo2
def split_name(self,pos_cut):
import string
data = self.name.split('-')
n = len(data)
pos_in_contig = 0
output = []
check_cut = 0
output.append([])
output.append([])
for ele in range(0,n):
tmp_ctg = data[ele]
info = tmp_ctg[1:-1].split(':') # initials contigs extract info
init_contig = info[0]
start = int(info[1])
end = int(info[2])
orientation = info[3]
n_frags = (end - start) +1
if orientation == 'w':
index_frag = range(1,n_frags+1)
start_write = start
else:
index_frag = range(n_frags,0,-1)
start_write = end
id = 0
out_cond = True
for i in index_frag:
id +=1
if orientation =='w':
name = '>' + string.join([init_contig,str(start_write),str(i + (start - 1) ),orientation],':') + '>'
else:
name = '>' + string.join([init_contig,str(i + (start - 1) ),str(start_write),orientation],':') + '>'
abs_pos = id + pos_in_contig
if (abs_pos == pos_cut):
if (id == n_frags):
out_cond = False
output[check_cut].append(name)
check_cut = 1
output[check_cut] = []
if orientation == 'w':
start_write = i + 1 + (start - 1)
else:
start_write = i - 1 + (start - 1)
if out_cond:
output[check_cut].append(name)
pos_in_contig = pos_in_contig + n_frags
name_1 = string.join(output[0],'-')
name_2 = string.join(output[1],'-')
return name_1,name_2
def sub_name(self,pos_a,pos_b):
import string
data = self.name.split('-')
n = len(data)
pos_in_contig = 0
output = []
stop = False
for ele in range(0,n):
tmp_ctg = data[ele]
info = tmp_ctg[1:-1].split(':') # initials contigs extract info
init_contig = info[0]
start = int(info[1])
end = int(info[2])
orientation = info[3]
n_frags = (end - start) +1
if orientation == 'w':
index_frag = range(1,n_frags+1)
start_write = start
else:
index_frag = range(n_frags,0,-1)
start_write = end
id = 0
out_cond = True
for i in index_frag:
id +=1
abs_pos = id + pos_in_contig
if ((abs_pos >= pos_a) and (abs_pos <= pos_b)):
if abs_pos == pos_a:
start_write = i
if orientation =='w':
name = '>' + string.join([init_contig,str(start_write),str(i),orientation],':') + '>'
else:
name = '>' + string.join([init_contig,str(i),str(start_write),orientation],':') + '>'
if (abs_pos == pos_b):
if (id == n_frags):
out_cond = False
output.append(name)
stop = True
if (out_cond and not(stop)):
output.append(name)
pos_in_contig = pos_in_contig + n_frags
name_1 = string.join(output,'-')
return name_1
def reverse_content(self,):
from copy import deepcopy as deepcopy
import string
init_contigs_compo = deepcopy(self.composition)
new_contigs_compo = deepcopy(self.new_compo)
FragmentS = deepcopy(self.FragmentS)
new_contigs_index = 0
init_contigs_index = 0
fragment_index = 0
init_contigs_compo.reverse()
for ele in init_contigs_compo:
init_contigs_index += 1
ele['orientation'] = ele['orientation'].translate(string.maketrans('wc', 'cw'))
ele['pos_id'] = init_contigs_index
new_contigs_compo.reverse()
for ele in new_contigs_compo:
new_contigs_index += 1
ele['orientation'] = ele['orientation'].translate(string.maketrans('wc', 'cw'))
ele['position'] = new_contigs_index
FragmentS.reverse()
for ele in FragmentS:
fragment_index +=1
ele.curr_id = fragment_index
result = dict()
result['init_contig_compo'] = init_contigs_compo
result['new_contig_compo'] = new_contigs_compo
result['FragmentS'] = FragmentS
return result
def export_abs_frag_vect(self):
abs_frag_vect = []
for fragment in self.FragmentS:
abs_frag_vect.append(fragment.np_id_abs-1)
return abs_frag_vect
def export_kb_pos_and_ctg_id(self,):
kb_pos_and_ctg_id = []
for fragment in self.FragmentS:
kb_pos_and_ctg_id.append([fragment.pos_kb,fragment.contig_id])
return kb_pos_and_ctg_id
def dist(self,frag_a,frag_b):
return self.kb_metric
@classmethod
def join(cls,contig_a,do_reverse_a,contig_b,do_reverse_b):
from copy import deepcopy as deepcopy
import string
obj = cls()
tmp_name = []
if do_reverse_a:
tmp_name.append(contig_a.reverse_name())
result_a = contig_a.reverse_content()
FragmentS_a = result_a['FragmentS']
Compo_init_a = result_a['init_contig_compo']
ind_init_compo = len(Compo_init_a)
Compo_new_a = result_a['new_contig_compo']
ind_new_compo = len(Compo_new_a)
else:
tmp_name.append(contig_a.name)
FragmentS_a = deepcopy(contig_a.FragmentS)
Compo_init_a = deepcopy(contig_a.composition)
ind_init_compo = len(Compo_init_a)
Compo_new_a = deepcopy(contig_a.new_compo)
ind_new_compo = len(Compo_new_a)
if do_reverse_b:
tmp_name.append(contig_b.reverse_name())
result_b = contig_b.reverse_content()
FragmentS_b = result_b['FragmentS']
Compo_init_b = result_b['init_contig_compo']
for ele in Compo_init_b:
ind_init_compo +=1
ele['pos_id'] = ind_init_compo
Compo_new_b = result_b['new_contig_compo']
for ele in Compo_new_b:
ind_new_compo +=1
ele['position'] = ind_new_compo
else:
tmp_name.append(contig_b.name)
FragmentS_b = deepcopy(contig_b.FragmentS)
Compo_init_b = deepcopy(contig_b.composition)
for ele in Compo_init_b:
ind_init_compo +=1
ele['pos_id'] = ind_init_compo
Compo_new_b = deepcopy(contig_b.new_compo)
for ele in Compo_new_b:
ind_new_compo +=1
ele['position'] = ind_new_compo
obj.name = string.join(tmp_name,'-')
obj.length_kb = 0
obj.n_frags = 0
obj.kb_metric = [0]
obj.FragmentS = []
obj.orientation = 'w'
obj.status = 'active'
obj.old_2_new = dict()
obj.old_2_new['0:-1'] = {'contig_id':'self','position':1,'orientation':'w'}
obj.new_compo = Compo_new_a
obj.new_compo.extend(Compo_new_b)
obj.composition = Compo_init_a
obj.composition.extend(Compo_init_b)
FragmentS_a.extend(FragmentS_b)
orientation = obj.vect_orientation()
i = 0
for frag in FragmentS_a:
new_frag = fragment.copy(frag)
obj.append_fragment(new_frag,orientation[i])
i += 1
return obj
@classmethod
def split(cls,contig_a, pos_cut):
# print "splitting"
obj1 = cls()
obj2 = cls()
name1,name2 = contig_a.split_name(pos_cut)
frag1, compo1, new_compo1, frag2, compo2, new_compo2 = contig_a.split_content(pos_cut)
# corriger le split ici ...
# print 'new_compo1 = ',new_compo1
# print 'new_compo2 = ',new_compo2
obj1.name = name1
obj1.length_kb = 0
obj1.n_frags = 0
obj1.kb_metric = [0]
obj1.FragmentS = []
obj1.orientation = 'w'
obj1.status = 'active'
obj1.old_2_new = dict()
obj1.old_2_new['0:-1'] = {'contig_id':'self','position':1,'orientation':'w'}
obj1.new_compo = new_compo1
obj1.composition = compo1
orientation = obj1.vect_orientation()
i = 0
for frag in frag1:
obj1.append_fragment(frag,orientation[i])
# print "contig 1 ultimate frag added = ",obj1.FragmentS[-1].curr_name
i += 1
obj2.name = name2
obj2.length_kb = 0
obj2.n_frags = 0
obj2.kb_metric = [0]
obj2.FragmentS = []
obj2.orientation = 'w'
obj2.status = 'active'
obj2.old_2_new = dict()
obj2.old_2_new['0:-1'] = {'contig_id':'self','position':1,'orientation':'w'}
obj2.new_compo = new_compo2
obj2.composition = compo2
orientation = obj2.vect_orientation()
i = 0
# print '##################################'
for frag in frag2:
# print frag.init_name
obj2.append_fragment(frag,orientation[i])
# print "contig 2 ultimate frag added = ",obj2.FragmentS[-1].curr_name
i += 1
return obj1, obj2
@classmethod
def duplicate(cls,contig_a,pos_a,pos_b):
print "duplicate"
obj1 = cls()
name1= contig_a.sub_name(pos_a,pos_b)
frag1, compo1, new_compo1 = contig_a.sub_content(pos_a,pos_b)
obj1.name = name1
obj1.length_kb = 0
obj1.n_frags = 0
obj1.kb_metric = [0]
obj1.FragmentS = []
obj1.orientation = 'w'
obj1.status = 'active'
obj1.old_2_new = dict()
obj1.old_2_new['0:-1'] = {'contig_id': 'self', 'position': 1, 'orientation':'w', 'dup': False}
obj1.new_compo = new_compo1
obj1.composition = compo1
orientation = obj1.vect_orientation()
i = 0
for frag in frag1:
obj1.append_fragment(frag,orientation[i])
i += 1
return obj1
def has_repeats(self):
output = False
for ele in self.new_compo:
if ele["dup"]:
output = True
return output