-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkmer_metablock_constructor.cpp
2216 lines (1836 loc) · 115 KB
/
kmer_metablock_constructor.cpp
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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <cstdio>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cstring>
#include <cassert>
#include <fstream>
#include <queue>
#include <sstream>
#include <stdexcept>
#include <tuple>
#include <algorithm>
#include <iterator>
#include <chrono>
#include <set>
#include <utility>
#include <math.h>
using Clock = std::chrono::steady_clock;
using std::chrono::time_point;
using std::chrono::duration_cast;
using std::chrono::milliseconds;
using namespace std;
typedef pair<string,short> pss;
typedef unsigned long long int ulli;
typedef pair<short,list<ulli> > pslistulli;
typedef pair<ulli,ulli> pulliulli;
typedef pair<short,pulliulli > pspuu;
typedef pair<pulliulli,unsigned long > ppuuul;
typedef pair<unsigned long,ulli> pululli;
typedef pair<ulli,bool> pullib;
typedef pair<unsigned int,bool> puib;
typedef pair<int,bool> pib;
typedef tuple<ulli,int,bool> tup_uib;
typedef tuple<ulli,ulli,bool> tup_uub;
typedef tuple<ulli,ulli,ulli> tup_uuu;
typedef pair<short,ulli> psulli;
typedef tuple<ulli,psulli,bool> tup_upsub;
typedef tuple<string,ulli,ulli,ulli> tup_suuu;
typedef tuple<unsigned int,ulli,ulli,ulli> tup_iuuu;
typedef pair<string, unsigned int> psui;
typedef pair<string, ulli> pstrulli;
typedef tuple<unsigned int,bool,unsigned int,bool,float,float,short> tup_ibibffs;
typedef tuple<psulli,bool,unsigned int> tup_psubi;
typedef tuple<psulli,psulli,bool,bool> tup_psupsubb;
typedef tuple<ulli,tup_psupsubb> tup_ulli_tpsupsubb;
typedef tuple<tup_psubi,tup_psubi> tup_tpsubitpsubi;
typedef pair<psulli,vector<bool> > ppsuvecb;
typedef pair<tup_psupsubb,vector<bool> > ptuppsuvecb;
typedef pair<psulli,list<ulli> > ppsulistulli;
typedef pair<tup_psupsubb,list<ulli> > ptuppsulistulli;
typedef pair<psulli,ulli > ppsuulli;
typedef tuple<ulli,ulli,bool,bool> tup_uubb;
typedef tuple<unsigned long,unsigned long,bool,bool> tup_ululbb;
typedef tuple<ulli,ulli,bool,bool,long> tup_uubbl;
typedef tuple<ulli,ulli,int,bool> tup_uuib;
typedef tuple<unsigned long,ulli,ulli,short> tup_uluus;
typedef tuple<unsigned long,short,bool> tup_ulsb;
typedef tuple<unsigned long,short,short> tup_ulss;
typedef tuple<unsigned long,short,short,vector<short> > tup_ulssvecs;
typedef tuple<ulli,bool,int> tup_ullibi;
typedef tuple<tup_ullibi,tup_ullibi> tup_tubitubi;
typedef tuple<unsigned long,bool,int> tup_ulbi;
typedef tuple<tup_ulbi,tup_ulbi> tup_tulbitulbi;
typedef tuple<ulli,bool,long> tup_ubl;
typedef tuple<tup_ubl,tup_ubl> tup_tubltubl;
typedef pair<tup_ululbb,vector<bool> > ptupulvecb;
typedef pair<short,pullib> ps_pullib;
typedef pair<ulli,pullib> pullipullib;
typedef pair<unsigned int,unsigned int> puiui;
typedef tuple<bool,bool,float,float,short> tup_bbffs;
typedef tuple<ulli,ulli,bool,ulli> tup_uubu;
ulli strtoulli(string number){
ulli result = 0;
for(int pos = 0; pos< number.length(); pos++){
result *=10;
result += number[pos]-'0';
}
return result;
}
bool is_valid_split_string(string item){
if(item.length()>1)
return true;
if(item.length()==0)
return false;
char c = item[0];
switch(c){
case ' ': case '\t': case '\n': case '\b': case '\r': case ',': case '.':
return false;
default:
return true;
}
}
template<typename Out>
void split(const string &s, char delim, Out result) {
stringstream ss(s);
string item;
while (std::getline(ss, item, delim)) {
if(is_valid_split_string(item))
*(result++) = item;
}
}
list<string> split(const string &s, char delim) {
list<string> elems;
split(s, delim, back_inserter(elems));
return elems;
}
list<string> get_lines(const char* FILENAME){
ifstream input_file(FILENAME);
list<string> lines_list;
string text;
while (getline( input_file, text )){
lines_list.push_back(text);
}
return lines_list;
}
vector< ulli > get_contig_ends_vector(string contig_len_filename){
list<string> lines = get_lines(contig_len_filename.c_str());
list<string> lsplit;
vector< ulli > length_ends_vector;
unsigned int contig_count = 0;
ulli contig_end;
for(list<string> :: iterator line_it = lines.begin(); line_it != lines.end(); line_it++){
lsplit = split(*line_it, '\t');
contig_end = strtoulli(lsplit.back());
length_ends_vector.push_back(contig_end);
contig_count++;
}
return length_ends_vector;
}
map< puiui, tup_bbffs > load_oriented_links_map(string oll_filename){
// cout<<"load_oriented_links_map started: "<<oll_filename<<"\n";
// list< tup_ibibffs > oriented_links_list;
map< puiui, tup_bbffs> oriented_links_map;
ulli oll_count;
tup_ibibffs current_row;
ifstream inFile;
inFile.open(oll_filename, ios::binary);
if(inFile.fail()){
cerr<<oll_filename<<" cannot be opened\n";
return oriented_links_map;
}
inFile.read((char*) (&oll_count), sizeof(oll_count));
while(oll_count--){
inFile.read((char*) (¤t_row), sizeof(current_row));
// oriented_links_list.push_back(current_row);
oriented_links_map[ puiui( get<0>(current_row), get<2>(current_row) ) ] = make_tuple(get<1>(current_row), get<3>(current_row),
get<4>(current_row), get<5>(current_row), get<6>(current_row));
}
inFile.close();
// cout<<"load_oriented_links_map ended: "<<oriented_links_map.size()<<"\n";
return oriented_links_map;
}
map< unsigned long, vector<tup_uub> > load_required_block_coordinates(list<ulli> merged_sorted_block_list, list<unsigned long> merged_sorted_assembly_list,
string assembly_blocks_dir){
cout<<"load_required_block_coordinates started: "<<merged_sorted_block_list.size()<<" "<<merged_sorted_assembly_list.size()<<" ";
cout<<assembly_blocks_dir<<"\n";
map< unsigned long, vector<tup_uub> > assembly_block_coords_map;
list<string> lines, lsplit;
list<string>::iterator it_coords;
list<ulli>::iterator it_blocks;
list<unsigned long>::iterator it_assembly;
ulli current_block_idx, diff, start_pos, end_pos;
bool orientation;
string filename;
/*for(it_blocks = merged_sorted_block_list.begin(); it_blocks != merged_sorted_block_list.end(); it_blocks++)
cout<< *it_blocks <<" ";
cout<<"\n\n";
for(it_assembly = merged_sorted_assembly_list.begin(); it_assembly != merged_sorted_assembly_list.end(); it_assembly++)
cout<< *it_assembly << " ";
cout<<"\n\n";*/
for(it_assembly = merged_sorted_assembly_list.begin(); it_assembly != merged_sorted_assembly_list.end(); it_assembly++){
// cout<< (*it_assembly) <<" ";
vector<tup_uub> current_required_coordinates;
// current_required_coordinates.reserve(merged_sorted_block_list.size());
filename = assembly_blocks_dir + to_string(*it_assembly);
lines = get_lines(filename.c_str());
lsplit = split(lines.front(), ',');
it_coords = lsplit.begin();
current_block_idx = 0;
// short show = 0;
for(it_blocks = merged_sorted_block_list.begin(); it_blocks != merged_sorted_block_list.end(); it_blocks++){
// cout<<"\n"<< *it_blocks << " " << current_block_idx << " ";
diff = ( (*it_blocks) - current_block_idx )*3;
// cout<< diff << " ";
if(diff>0)
advance(it_coords, diff);
// cout<< *it_coords << "\n";
start_pos = strtoulli( *it_coords++ );
end_pos = strtoulli( *it_coords++ );
orientation = ( *it_coords++ == "1" );
current_required_coordinates.push_back( make_tuple(start_pos, end_pos, orientation) );
/*if(show < 10){
cout<< "[" << *it_blocks << " " << current_block_idx << " : (" << start_pos << "," << end_pos << "," << (orientation?"1":"0") << "] ";
show++;
}*/
current_block_idx = (*it_blocks) + 1; // +1 due to the 3 it_coords++ operations
}
// cout<< current_required_coordinates.size() << "\n\n";
assembly_block_coords_map[ *it_assembly ] = current_required_coordinates;
}
/*short count = 0;
for(auto it = assembly_block_coords_map[ merged_sorted_assembly_list.front() ].begin();
it != assembly_block_coords_map[ merged_sorted_assembly_list.front() ].end() && count < 10; it++){
if( get<0>( *it ) > 0){
cout << "(" << get<0>( *it ) << "," << get<1>( *it ) << "," << (get<2>( *it )?"1":"0") << ") \n";
count++;
}
}*/
cout<<"load_required_block_coordinates ended\n";
return assembly_block_coords_map;
}
list<tup_uub> get_sorted_assembly_component_blocks( list<ulli> component_block_idx_list, list<ulli> merged_sorted_block_list,
vector<tup_uub> assembly_block_coords_vector){
list<ulli>::iterator it_merged_blocks, it_current_blocks;
list<tup_uub> block_locator_list; // (block_start_pos, block_idx, block_orientation)
it_merged_blocks = merged_sorted_block_list.begin();
it_current_blocks = component_block_idx_list.begin();
ulli pos = 0;
while(it_current_blocks != component_block_idx_list.end()){
while(*it_current_blocks != *it_merged_blocks){
it_merged_blocks++;
pos++;
}
block_locator_list.push_back( make_tuple( get<0>( assembly_block_coords_vector[pos] ), *it_current_blocks,
get<2>( assembly_block_coords_vector[pos] ) ) );
it_current_blocks++;
}
block_locator_list.sort();
// cout << "get_sorted_assembly_component_blocks : "<<block_locator_list.size()<<" "<<assembly_block_coords_vector.size()<<"\n";
// short count = 0;
// for(auto it = block_locator_list.begin(); it != block_locator_list.end() && count<5; it++, count++)
// cout<< "(" << get<0>(*it) << "," << get<1>(*it) << "," << ((get<2>(*it))?"1":"0") << ")\n";
return block_locator_list;
}
void check_coords_vector(vector<tup_uub> assembly_block_coords_vector){
cout<<"check_coords_vector: "<< assembly_block_coords_vector.size() << " ";
short count = 0;
for(auto it = assembly_block_coords_vector.begin(); it != assembly_block_coords_vector.end() && count <10 ; it++)
if( (get<0>(*it)) > 0){
cout<< "(" << (get<0>(*it)) << "," << (get<1>(*it)) << ") ";
count++;
}
cout<<"\n";
}
list<tup_uuu> get_sorted_assembly_component_block_coords( list<ulli> sorted_block_idx_list, list<ulli> merged_sorted_block_list,
vector<tup_uub> assembly_block_coords_vector){
list<ulli>::iterator it_merged_blocks, it_current_blocks;
list<tup_uuu> block_locator_list; // (block_start_pos, block_idx, block_end_pos)
it_merged_blocks = merged_sorted_block_list.begin();
it_current_blocks = sorted_block_idx_list.begin();
ulli pos = 0, block_idx, start_pos, end_pos;
while(it_current_blocks != sorted_block_idx_list.end()){
while(*it_current_blocks != *it_merged_blocks){
it_merged_blocks++;
pos++;
}
start_pos = get<0>( assembly_block_coords_vector[pos] );
end_pos = get<1>( assembly_block_coords_vector[pos] );
block_idx = *it_current_blocks;
// cout<<"("<<start_pos<<","<<block_idx<<","<<end_pos<<") ";
block_locator_list.push_back( make_tuple( start_pos, block_idx, end_pos) );
it_current_blocks++;
}
// cout<<"\n";
block_locator_list.sort();
// short count = 0;
// for(auto it = block_locator_list.begin(); it != block_locator_list.end() && count<5; it++, count++)
// cout<< "(" << get<0>(*it) << "," << get<1>(*it) << "," << ((get<2>(*it))?"1":"0") << ")\n";
return block_locator_list;
}
/*void generate_and_update_block_pair_counts( list<tup_uub> block_locator_list, vector<ulli> contig_ends_vector,
map< tup_uubb, unsigned long >& block_pair_map, map< ulli, unsigned long >& block_map,
bool new_component){
unsigned int current_contig_idx = 0;
bool new_contig_block = true;
tup_uubb block_pair_tuple;
tup_uub previous_block;
map< tup_uubb, unsigned long >::iterator it_pair_map;
map< ulli, unsigned long >::iterator it_single_map;
for(list<tup_uub>::iterator it = block_locator_list.begin(); it != block_locator_list.end(); it++){
if(get<0>( *it )==0)
continue;
while( get<0>( *it ) > contig_ends_vector[current_contig_idx]){
current_contig_idx++;
new_contig_block = true;
}
it_single_map = block_map.find( get<1>( *it ) );
if(new_component && it_single_map == block_map.end())
block_map[ get<1>( *it ) ] = 1;
else
(it_single_map->second) = (it_single_map->second) + 1;
if( !new_contig_block && get<0>( *it ) > 0 && get<0>( previous_block ) > 0){
if( get<1>(previous_block) < get<1>( *it ) )
block_pair_tuple = make_tuple(get<1>(previous_block), get<1>( *it ), get<2>(previous_block), get<2>( *it ));
else
block_pair_tuple = make_tuple(get<1>( *it ), get<1>( previous_block ), !get<2>( *it ), !get<2>( previous_block ));
it_pair_map = block_pair_map.find(block_pair_tuple);
// We just need to look for core blocks
// ==> new tuples are to be added only if tuples from first assembly for that component are being loaded
if(new_component && it_pair_map == block_pair_map.end())
block_pair_map[block_pair_tuple] = 1;
else
(it_pair_map->second) = (it_pair_map->second) + 1;
}
new_contig_block = false;
previous_block = *it;
}
// short count = 0;
// for(it_pair_map = block_pair_map.begin(); it_pair_map != block_pair_map.end() && count<5; it_pair_map++, count++){
// cout << "("<< get<0>(it_pair_map->first) << "," << get<1>(it_pair_map->first) << ",";
// cout << ((get<2>(it_pair_map->first))?"1":"0") << "," << ((get<3>(it_pair_map->first))?"1":"0") << ")";
// cout<<":"<<it_pair_map->second<<"\n";
// }
}*/
void generate_and_update_block_pair_counts( list<tup_uub> block_locator_list, vector<ulli> contig_ends_vector,
map< tup_uubb, unsigned long >& block_pair_map, bool new_component){
unsigned int current_contig_idx = 0;
bool new_contig_block = true;
tup_uubb block_pair_tuple;
tup_uub previous_block;
map< tup_uubb, unsigned long >::iterator map_it;
for(list<tup_uub>::iterator it = block_locator_list.begin(); it != block_locator_list.end(); it++){
if(get<0>( *it )==0)
continue;
while( get<0>( *it ) > contig_ends_vector[current_contig_idx]){
current_contig_idx++;
new_contig_block = true;
}
if( !new_contig_block && get<0>( *it ) > 0 && get<0>( previous_block ) > 0){
if( get<1>(previous_block) < get<1>( *it ) )
block_pair_tuple = make_tuple(get<1>(previous_block), get<1>( *it ), get<2>(previous_block), get<2>( *it ));
else
block_pair_tuple = make_tuple(get<1>( *it ), get<1>( previous_block ), !get<2>( *it ), !get<2>( previous_block ));
map_it = block_pair_map.find(block_pair_tuple);
// We just need to look for core blocks
// ==> new tuples are to be added only if tuples from first assembly for that component are being loaded
if(new_component /*&& map_it == block_pair_map.end()*/)
block_pair_map[block_pair_tuple] = 1;
else if (map_it != block_pair_map.end())
(map_it->second) = (map_it->second) + 1;
}
new_contig_block = false;
previous_block = *it;
}
// short count = 0;
// for(map_it = block_pair_map.begin(); map_it != block_pair_map.end() && count<5; map_it++, count++){
// cout << "("<< get<0>(map_it->first) << "," << get<1>(map_it->first) << ",";
// cout << ((get<2>(map_it->first))?"1":"0") << "," << ((get<3>(map_it->first))?"1":"0") << ")";
// cout<<":"<<map_it->second<<"\n";
// }
}
/*void retain_core_block_pairs(map< tup_uubb, unsigned long >& block_pair_map, map< ulli, unsigned long >& block_map,
unsigned long component_assembly_count){
set<ulli> core_blocks_set;
set<ulli>::iterator set_it;
cout << "retain_core_block_pairs: "<<block_pair_map.size()<<" ";
for(map< tup_uubb, unsigned long >::iterator it_pair_map = block_pair_map.begin(); it_pair_map != block_pair_map.end(); ){
if(it_pair_map->second == component_assembly_count){
core_blocks_set.insert( get<0>( it_pair_map->first) );
core_blocks_set.insert( get<1>( it_pair_map->first) );
it_pair_map++;
}
else
it_pair_map = block_pair_map.erase(it_pair_map);
}
cout<<block_pair_map.size()<<" ";
for(map< ulli, unsigned long >::iterator it_single_map = block_map.begin(); it_single_map != block_map.end(); ){
set_it = core_blocks_set.find( it_single_map->first );
if(it_single_map->second == component_assembly_count && set_it == core_blocks_set.end()){
// The block is by itself a core block, but adjoining blocks in the vicinity do not form core tuple
block_pair_map[ make_tuple( it_single_map->first, it_single_map->first, true, true) ] = component_assembly_count;
}
it_single_map = block_map.erase(it_single_map);
}
cout<<block_pair_map.size()<<"\n";
// cout<<"\t("<<max_val<<")\t";
// short count = 0;
// for(map< tup_uubb, unsigned long >::iterator it_pair_map = block_pair_map.begin(); it_pair_map != block_pair_map.end() && count<5;
// it_pair_map++, count++){
// cout << "("<< get<0>(it_pair_map->first) << "," << get<1>(it_pair_map->first) << ",";
// cout << ((get<2>(it_pair_map->first))?"1":"0") << "," << ((get<3>(it_pair_map->first))?"1":"0") << ")";
// cout<<":"<<it_pair_map->second<<"\n";
// }
}*/
void retain_core_block_pairs(map< tup_uubb, unsigned long >& block_pair_map, unsigned long component_assembly_count){
// unsigned long max_val = 0;
for(map< tup_uubb, unsigned long >::iterator map_it = block_pair_map.begin(); map_it != block_pair_map.end(); ){
// max_val = (max_val > map_it->second)?max_val:map_it->second;
if(map_it->second == component_assembly_count)
map_it++;
else
map_it = block_pair_map.erase(map_it);
}
// cout<<"\t("<<max_val<<")\t";
// short count = 0;
// for(map< tup_uubb, unsigned long >::iterator map_it = block_pair_map.begin(); map_it != block_pair_map.end() && count<5;
// map_it++, count++){
// cout << "("<< get<0>(map_it->first) << "," << get<1>(map_it->first) << ",";
// cout << ((get<2>(map_it->first))?"1":"0") << "," << ((get<3>(map_it->first))?"1":"0") << ")";
// cout<<":"<<map_it->second<<"\n";
// }
}
// This is not a struct for metablock
// This is just to locate the chains of core blocks:
// some of these could then be merged - some of these could span across contig boundaries in some assemblies
// The collection of the subsequent merged and those that could not be merged chains forms the metablocks
struct Chain{
pulliulli chain_idx;
unsigned long reference_assembly_idx;
pulliulli ends_blocks;
list< pulliulli > ends_coords_list;
list< bool > orientations_list;
};
list<ulli> get_core_block_list(map< tup_uubb, unsigned long > block_pair_map){
cout<<"get_core_block_list started: "<<block_pair_map.size()<<"\n";
set<ulli> core_blocks_set;
for(map< tup_uubb, unsigned long >::iterator map_it = block_pair_map.begin(); map_it != block_pair_map.end(); map_it++){
core_blocks_set.insert( get<0>( map_it->first) );
core_blocks_set.insert( get<1>( map_it->first) );
}
cout<<core_blocks_set.size()<<" ";
list<ulli> core_blocks_list(core_blocks_set.begin(), core_blocks_set.end());
// list<ulli> core_blocks_list;
// for(set<ulli>::iterator it = core_blocks_set.begin(); it != core_blocks_set.end(); it++){
// core_blocks_list.push_back( *it );
// }
core_blocks_list.sort();
cout<<core_blocks_list.size()<<" ";
return core_blocks_list;
}
// Had a bug: it is possible that in some genome, the chaining of blocks from the reference genome, is now split across 2 contigs
// The other contig may still be placed next to the previous one, but in reverse orientation
// If only the end coords and blocks from the reference genome chaining is used, this causes issues
// Maintain a set of just the block indices tuples (orientations can be discarded now as they are checked and verified before)
// Get the location sorted list of blocks, just as before
// For each current block, check if a core block tuple is formed with its preceding block - using this block tuple set
// If yes, extend the current chain
list< Chain > merge_block_pairs_into_chains(map< tup_uubb, unsigned long > block_pair_map, list<ulli> merged_sorted_block_list,
vector<tup_uub> assembly_block_coords_vector, ulli comp_idx, short max_neighbour_separation,
unsigned long reference_assembly_idx, unsigned long entry_location ){
// cout<<"merge_block_pairs_into_chains started: "<<block_pair_map.size()<<" "<<merged_sorted_block_list.size()<<" ";
// cout<<assembly_block_coords_vector.size()<<" "<<comp_idx<<" "<<max_neighbour_separation<<"\n";
list< Chain > component_chains_list;
set<ulli> core_blocks_set;
set<pulliulli> core_block_tuples_set;
set<pulliulli>::iterator it_pair_presence;
ulli previous_block_idx;
for(map< tup_uubb, unsigned long >::iterator map_it = block_pair_map.begin(); map_it != block_pair_map.end(); map_it++){
core_blocks_set.insert( get<0>( map_it->first) );
core_blocks_set.insert( get<1>( map_it->first) );
if(get<0>( map_it->first) < get<1>( map_it->first))
core_block_tuples_set.insert( make_pair( get<0>( map_it->first) , get<1>( map_it->first) ) );
else
core_block_tuples_set.insert( make_pair( get<1>( map_it->first) , get<0>( map_it->first) ) );
}
// cout<<core_blocks_set.size()<<" ";
list<ulli> core_blocks_list(core_blocks_set.begin(), core_blocks_set.end());
core_blocks_list.sort();
// cout<<core_blocks_list.size()<<" ";
list<tup_uuu> location_sorted_blocks_list = get_sorted_assembly_component_block_coords(core_blocks_list, merged_sorted_block_list,
assembly_block_coords_vector);
// cout<<location_sorted_blocks_list.size()<<"\n";
Chain current_chain;
ulli current_chain_no = 0;
list<tup_uuu>::iterator it_block_loc = location_sorted_blocks_list.begin();
list< pulliulli > reset_ends_coords_list;
list<bool> default_orientation_list;
for(unsigned long assembly_idx=0; assembly_idx<entry_location; assembly_idx++){
reset_ends_coords_list.push_back( make_pair(0,0) );
default_orientation_list.push_back(false);
}
default_orientation_list.push_back(true);
current_chain.chain_idx = make_pair(comp_idx, current_chain_no);
// current_chain.ends_blocks = make_pair( get<1>( *it_block_loc ), get<1>( *it_block_loc ));
current_chain.ends_coords_list = reset_ends_coords_list;
current_chain.orientations_list = default_orientation_list;
current_chain.reference_assembly_idx = reference_assembly_idx;
pulliulli ends_coords = make_pair( get<0>( *it_block_loc ), get<2>( *it_block_loc ));
pulliulli ends_blocks = make_pair( get<1>( *it_block_loc ), get<1>( *it_block_loc ));
unsigned long assembly_idx;
previous_block_idx = get<1>( *it_block_loc );
cout << (current_chain.chain_idx).first << "," << (current_chain.chain_idx).second << " : " << get<1>( *it_block_loc );
if(ends_coords.first==0 || ends_coords.second==0)
cout<<"\tNULL_CORE_BLOCK_ISSUE!!! " << reference_assembly_idx << "("<<ends_coords.first<<","<<ends_coords.second<<")\n";
it_block_loc++;
while(it_block_loc != location_sorted_blocks_list.end()){
if(previous_block_idx < get<1>( *it_block_loc ))
it_pair_presence = core_block_tuples_set.find( make_pair( previous_block_idx , get<1>( *it_block_loc ) ) );
else
it_pair_presence = core_block_tuples_set.find( make_pair( get<1>( *it_block_loc ) , previous_block_idx ) );
if( ( it_pair_presence != core_block_tuples_set.end() ) &&
( ends_coords.second + max_neighbour_separation + 1 >= get<0>( *it_block_loc ) ) ){
cout << "-" << get<1>( *it_block_loc );
ends_blocks.second = get<1>( *it_block_loc );
ends_coords.second = get<2>( *it_block_loc );
if(ends_coords.first==0 || ends_coords.second==0)
cout<<"\tNULL_CORE_BLOCK_ISSUE!!! " << reference_assembly_idx << "("<<ends_coords.first<<","<<ends_coords.second<<")\n";
}
else{
current_chain.ends_blocks = ends_blocks;
(current_chain.ends_coords_list).push_back( ends_coords );
component_chains_list.push_back(current_chain);
cout << " :: [" << (current_chain.ends_blocks).first << ",";
cout << (current_chain.ends_blocks).second << "] => ";
cout << " :: [" << ((current_chain.ends_coords_list).front()).first << ",";
cout << ((current_chain.ends_coords_list).front()).second << "]\n";
current_chain_no++;
current_chain.chain_idx = make_pair(comp_idx, current_chain_no);
// current_chain.ends_blocks = make_pair( get<1>( *it_block_loc ), get<1>( *it_block_loc ));
ends_blocks = make_pair( get<1>( *it_block_loc ), get<1>( *it_block_loc ));
current_chain.orientations_list = default_orientation_list;
ends_coords = make_pair( get<0>( *it_block_loc ), get<2>( *it_block_loc ));
// (current_chain.ends_coords_list).clear();
current_chain.ends_coords_list = reset_ends_coords_list;
cout << (current_chain.chain_idx).first << "," << (current_chain.chain_idx).second << " : " << get<1>( *it_block_loc );
if(ends_coords.first==0 || ends_coords.second==0)
cout<<"\tNULL_CORE_BLOCK_ISSUE!!! " << reference_assembly_idx << "("<<ends_coords.first<<","<<ends_coords.second<<")\n";
}
previous_block_idx = get<1>( *it_block_loc );
it_block_loc++;
}
current_chain.ends_blocks = ends_blocks;
(current_chain.ends_coords_list).push_back(ends_coords);
component_chains_list.push_back(current_chain);
// cout << " :: [" << (current_chain.ends_blocks).first << ",";
// cout << (current_chain.ends_blocks).second << "] => ";
// cout << " :: [" << ((current_chain.ends_coords_list).front()).first << ",";
// cout << ((current_chain.ends_coords_list).front()).second << "]\n";
cout<<"\nmerge_block_pairs_into_chains "<<comp_idx<<" : "<<component_chains_list.size()<<"\n";
return component_chains_list;
}
void update_chain_coordinates_lists(list< Chain >& all_component_chains_list, list<ulli> chain_ends_block_list,
list<ulli> merged_sorted_block_list, vector<tup_uub> assembly_block_coords_vector,
unsigned long current_assembly_idx/*, unsigned long entry_location*/,
vector< bool > component_presence_vector, ulli start_comp_idx){
list<tup_uuu> location_sorted_blocks_list = get_sorted_assembly_component_block_coords(chain_ends_block_list, merged_sorted_block_list,
assembly_block_coords_vector);
// cout<< location_sorted_blocks_list.size() << " ";
map< ulli, pulliulli > block_coords_map;
list<tup_uuu>::iterator it_block_loc;
ulli diff;
for(it_block_loc = location_sorted_blocks_list.begin(); it_block_loc != location_sorted_blocks_list.end(); it_block_loc++)
block_coords_map[ get<1>( *it_block_loc) ] = make_pair( get<0>( *it_block_loc) , get<2>( *it_block_loc) );
// cout << block_coords_map.size() << "\n";
pulliulli block_1_coords, block_2_coords;
for(list< Chain >::iterator it_chain = all_component_chains_list.begin(); it_chain != all_component_chains_list.end(); it_chain++){
/*if( (*it_chain).reference_assembly_idx == current_assembly_idx ){
if( (*it_chain).ends_coords_list.front().first >= (*it_chain).ends_coords_list.front().second ){
cout << "CHAIN_ISSUE!!! : (" << (*it_chain).chain_idx.first << "," << (*it_chain).chain_idx.second << ") ";
cout << (*it_chain).ends_coords_list.front().first << " " << (*it_chain).ends_coords_list.front().second << "\n";
}
continue;
}
else*/
if((*it_chain).reference_assembly_idx < current_assembly_idx){
if(component_presence_vector[ (*it_chain).chain_idx.first - start_comp_idx] == false){
(*it_chain).ends_coords_list.push_back( make_pair(0, 0) );
(*it_chain).orientations_list.push_back( false );
continue;
}
block_1_coords = block_coords_map[ (*it_chain).ends_blocks.first ];
block_2_coords = block_coords_map[ (*it_chain).ends_blocks.second ];
// // Append only if the chain exists in the assembly
// if(block_1_coords.first > 0 && block_2_coords.first > 0){
// if(block_1_coords.first < block_2_coords.first){
// // forward strand orientation
// (*it_chain).ends_coords_list.push_back( make_pair( block_1_coords.first, block_2_coords.second) );
// (*it_chain).orientations_list.push_back( true );
// }
// else{
// // reverse strand orientation
// (*it_chain).ends_coords_list.push_back( make_pair( block_2_coords.first, block_1_coords.second) );
// (*it_chain).orientations_list.push_back( false );
// }
// }
// This will result in all valid list entries to be appropriately placed
// (lengths may vary depending on later assemblies that do not contain the corresponding blocks)
/*diff = entry_location - (*it_chain).orientations_list.size();
while(diff>0){
(*it_chain).ends_coords_list.push_back( make_pair( 0, 0) );
(*it_chain).orientations_list.push_back( false );
diff--;
}*/
if(block_1_coords.first==0 || block_2_coords.first==0 || block_1_coords.second==0 || block_2_coords.second==0){
cout<<"CHAIN_ENDS_BLOCKS_NULL_COORDS_ISSUE!!!: ("<<(*it_chain).chain_idx.first<<","<<(*it_chain).chain_idx.second<<") : ";
cout<<current_assembly_idx<<" ("<<block_1_coords.first<<","<<block_1_coords.second<<") ";
cout<<"("<<block_2_coords.first<<","<<block_2_coords.second<<")\n";
}
if(block_1_coords.first < block_2_coords.first){
// forward strand orientation
(*it_chain).ends_coords_list.push_back( make_pair( block_1_coords.first, block_2_coords.second) );
(*it_chain).orientations_list.push_back( true );
}
else{
// reverse strand orientation
(*it_chain).ends_coords_list.push_back( make_pair( block_2_coords.first, block_1_coords.second) );
(*it_chain).orientations_list.push_back( false );
}
}
}
}
void filter_chain_coordinates_lists(Chain& current_chain, list<unsigned long> assembly_idx_innerlist,
list<unsigned long> merged_sorted_assembly_list){
// cout<<"filter_chain_coordinates_lists started: ("<<current_chain.chain_idx.first<<","<<current_chain.chain_idx.second<<") ";
// cout<<current_chain.orientations_list.size()<<" "<<assembly_idx_innerlist.size()<<" ";
// short count=0;
// for(auto it = assembly_idx_innerlist.begin(); it != assembly_idx_innerlist.end() && count<10; it++, count++)
// cout<< *it << " ";
// cout<<"\n";
// unsigned long assembly_idx, assembly_count;
list<unsigned long>::iterator it_assembly_innerlist = assembly_idx_innerlist.begin();
list<unsigned long>::iterator it_merged_assembly = merged_sorted_assembly_list.begin();
list< pulliulli >::iterator it_ends_coords = current_chain.ends_coords_list.begin();
list< bool >::iterator it_orient = current_chain.orientations_list.begin();
// assembly_idx = 0;
// assembly_count = current_chain.orientations_list.size();
/*while(it_assembly_innerlist != assembly_idx_innerlist.end()){
if(assembly_idx != (*it_assembly_innerlist) ){
it_ends_coords = current_chain.ends_coords_list.erase(it_ends_coords);
it_orient = current_chain.orientations_list.erase(it_orient);
}
else{
it_assembly_innerlist++;
it_ends_coords++;
it_orient++;
}
assembly_idx++;
}
while(it_orient != current_chain.orientations_list.end()){
it_ends_coords = current_chain.ends_coords_list.erase(it_ends_coords);
it_orient = current_chain.orientations_list.erase(it_orient);
}*/
list<pulliulli> filtered_ends_coords_list;
list<bool> filtered_orientations_list;
for(it_assembly_innerlist = assembly_idx_innerlist.begin(); it_assembly_innerlist != assembly_idx_innerlist.end();
it_merged_assembly++, it_ends_coords++, it_orient++){
if( (*it_assembly_innerlist) == (*it_merged_assembly) ){
filtered_ends_coords_list.push_back( *it_ends_coords );
filtered_orientations_list.push_back( *it_orient );
if( it_ends_coords->first==0 || it_ends_coords->second==0 ){
cout<<"CHAIN_COORDS_NULL_ISSUE!!! ("<<current_chain.chain_idx.first<<","<<current_chain.chain_idx.second<<") ";
cout<<"<"<<current_chain.reference_assembly_idx << "> : ";
cout<<(*it_assembly_innerlist)<<" "<<(it_ends_coords->first)<<" "<<(it_ends_coords->second)<<" "<<(*it_orient)<<"\n";
}
it_assembly_innerlist++;
}
}
current_chain.ends_coords_list = filtered_ends_coords_list;
current_chain.orientations_list = filtered_orientations_list;
// cout<<"filter_chain_coordinates_lists ended: ("<<current_chain.chain_idx.first<<","<<current_chain.chain_idx.second<<") ";
// cout<<current_chain.orientations_list.size()<<" "<<assembly_idx_innerlist.size()<<"\n";
}
unsigned int get_contig_index_by_coordinate(vector<ulli> contig_ends_vector, ulli start_coordinate, unsigned int start, unsigned int end){
if(start==end)
return start;
unsigned int mid_contig = (start+end)/2;
ulli mid_value = contig_ends_vector[mid_contig];
if(start_coordinate == mid_value)
return mid_contig;
if(start_coordinate > mid_value)
return get_contig_index_by_coordinate(contig_ends_vector, start_coordinate, mid_contig+1, end);
return get_contig_index_by_coordinate(contig_ends_vector, start_coordinate, start, mid_contig);
}
struct Metablock{
ulli comp_idx;
bool is_contig_split;
// "non-split" fields
pulliulli ends_blocks;
list< pulliulli > ends_coords_list;
list< bool > orientations_list;
// "split" fields
list< pulliulli > contig_ends_blocks_list;
list< list< pulliulli > > contig_ends_coords_list;
list< list< bool > > contig_orientations_list;
};
Metablock init_chain_as_metablock(Chain current_chain){
Metablock current_metablock;
current_metablock.comp_idx = current_chain.chain_idx.first;
current_metablock.is_contig_split = false;
current_metablock.ends_blocks = current_chain.ends_blocks;
current_metablock.ends_coords_list = current_chain.ends_coords_list;
current_metablock.orientations_list = current_chain.orientations_list;
return current_metablock;
}
list<unsigned int> get_chain_coords_contig_index_list(list<pulliulli> ends_coords_list, list< unsigned long> assembly_idx_innerlist,
map< unsigned long, vector<ulli> > mapped_contig_ends){
list<unsigned int> contig_idx_list;
vector<ulli> contig_ends_vector;
list<pulliulli>::iterator it_ends_coords = ends_coords_list.begin();
for(list<unsigned long>::iterator it_assembly_innerlist = assembly_idx_innerlist.begin(); it_assembly_innerlist != assembly_idx_innerlist.end();
it_assembly_innerlist++, it_ends_coords++){
contig_ends_vector = mapped_contig_ends[ *it_assembly_innerlist ];
contig_idx_list.push_back( get_contig_index_by_coordinate( contig_ends_vector, (*it_ends_coords).first, 0, contig_ends_vector.size() - 1 ) );
}
return contig_idx_list;
}
/*list<ulli> get_chain_end_coord_list(Chain current_chain, bool is_preceding){
list<ulli> end_coord_list;
list<bool> orientations_list = current_chain.orientations_list;
list<bool>::iterator it_orient = orientations_list.begin();
for(list<pulliulli>::iterator it_ends_coords = current_chain.ends_coords_list.begin(); it_ends_coords != current_chain.ends_coords_list.end();
it_ends_coords++, it_orient++){
if(is_preceding){
if( (*it_orient) )
end_coord_list.push_back( (*it_ends_coords).second );
else
end_coord_list.push_back( (*it_ends_coords).first );
}
else{
if( (*it_orient) )
end_coord_list.push_back( (*it_ends_coords).first );
else
end_coord_list.push_back( (*it_ends_coords).second );
}
}
return end_coord_list;
}*/
list<ulli> get_chain_end_coord_list(Chain current_chain, bool is_preceding, list<bool>assembly_contig_orientation_list){
list<ulli> end_coord_list;
list<bool> orientations_list = current_chain.orientations_list;
list<bool>::iterator it_orient = orientations_list.begin();
list<bool>::iterator it_contig_orient = assembly_contig_orientation_list.begin();
for(list<pulliulli>::iterator it_ends_coords = current_chain.ends_coords_list.begin(); it_ends_coords != current_chain.ends_coords_list.end();
it_ends_coords++, it_orient++, it_contig_orient++){
if( !(is_preceding ^ (*it_contig_orient) ) ){
if( (*it_orient) )
end_coord_list.push_back( (*it_ends_coords).second );
else
end_coord_list.push_back( (*it_ends_coords).first );
}
else{
if( (*it_orient) )
end_coord_list.push_back( (*it_ends_coords).first );
else
end_coord_list.push_back( (*it_ends_coords).second );
}
}
return end_coord_list;
}
// is_preceding ==> in forward orientation, if true: gives 'end' coordinate, else: gives 'start' coordinate; and vice versa
/*list<ulli> get_chain_end_coord_list(list<pulliulli> ends_coords_list, bool is_preceding, list<bool>assembly_contig_orientation_list){
list<ulli> end_coord_list;
// list<bool> orientations_list = current_chain.orientations_list;
// list<bool>::iterator it_orient = orientations_list.begin();
list<bool>::iterator it_orient = assembly_contig_orientation_list.begin();
for(list<pulliulli>::iterator it_ends_coords = ends_coords_list.begin(); it_ends_coords != ends_coords_list.end();
it_ends_coords++, it_orient++){
if(is_preceding){
if( (*it_orient) )
end_coord_list.push_back( (*it_ends_coords).second );
else
end_coord_list.push_back( (*it_ends_coords).first );
}
else{
if( (*it_orient) )
end_coord_list.push_back( (*it_ends_coords).first );
else
end_coord_list.push_back( (*it_ends_coords).second );
}
}
return end_coord_list;
}*/
list< Metablock > generate_metablocks(list< Chain > all_component_chains_list, list< list<unsigned long> > component_assembly_idx_outerlist,
map< unsigned long, vector<ulli> > mapped_contig_ends, short max_neighbour_separation,
bool use_oriented_links, map< unsigned long, map< puiui, tup_bbffs > > mapped_oriented_links_map,
unsigned long iter_diff){
cout<<"generate_metablocks started: "<< all_component_chains_list.size() << " " << component_assembly_idx_outerlist.size() << "\n";
list< Metablock > metablock_list;
Metablock current_metablock;
bool current_contig_split, required_orientation, metablock_contig_orientation, chain_contig_orientation;
bool chain_effective_orientation;
list< Chain >::iterator it_chain = all_component_chains_list.begin();
list< list< unsigned long > >::iterator it_assembly_outerlist = component_assembly_idx_outerlist.begin();
advance(it_assembly_outerlist, iter_diff);
list< unsigned int > metablock_end_contig_indices, chain_contig_indices;
list< unsigned int >::iterator it_metablock_contig, it_chain_contig;
list< ulli > metablock_start_coord_list, metablock_end_coord_list, chain_other_end_coord_list, chain_end_coord_list;
list< ulli >::iterator it_metablock_start_coord, it_metablock_coord, it_chain_coord, it_chain_other_end_coord;
list<bool> orientations_list, assembly_contig_orientation_list, metablock_last_orientations_list, orientations_innerlist;
list<bool>::iterator it_orient, it_assembly_contig_orient, it_metablock_last_orient, it_metablock_orient;
map< puiui, tup_bbffs > oriented_links_map;
map< puiui, tup_bbffs >::iterator it_ol_map;
tup_bbffs contig_orientation_tuple;
long diff_metablock_contig, diff_chain_contig, diff_effective;
// list< list< bool > > split_contig_orientations;
// list< list< bool > >::iterator it_split_contig;
unsigned long assembly_iter;
list< list< pulliulli > >::iterator it_update_coords_outerlist;
list< list< bool > >::iterator it_update_orientations_outerlist;
list<pulliulli>::iterator it_ends_coords, it_metablock_ends_coords;
list< pulliulli > ends_coords_innerlist;
current_metablock = init_chain_as_metablock(*it_chain);
metablock_end_contig_indices = get_chain_coords_contig_index_list(current_metablock.ends_coords_list, ( *it_assembly_outerlist ),
mapped_contig_ends);
for(assembly_iter = 0; assembly_iter < ( *it_assembly_outerlist ).size(); assembly_iter++)
assembly_contig_orientation_list.push_back(true);
it_assembly_contig_orient = assembly_contig_orientation_list.begin();
// metablock_start_coord_list = get_chain_end_coord_list( *it_chain, !(*it_assembly_contig_orient) );
// metablock_end_coord_list = get_chain_end_coord_list( *it_chain, (*it_assembly_contig_orient) );
// metablock_start_coord_list = get_chain_end_coord_list( (*it_chain).ends_coords_list, false, (*it_chain).ends_coords_list.orientations_list);
// metablock_end_coord_list = get_chain_end_coord_list( (*it_chain).ends_coords_list, true, (*it_chain).ends_coords_list.orientations_list);
metablock_start_coord_list = get_chain_end_coord_list( *it_chain, false, assembly_contig_orientation_list);
metablock_end_coord_list = get_chain_end_coord_list( *it_chain, true, assembly_contig_orientation_list);
list< unsigned long >::iterator it_assembly_innerlist = ( *it_assembly_outerlist ).begin();
current_contig_split = false;
metablock_last_orientations_list = (*it_chain).orientations_list;
it_metablock_last_orient = metablock_last_orientations_list.begin();
cout<< current_metablock.comp_idx << " : " << (*it_chain).chain_idx.second << " ";
// cout << "(" << ((*it_chain).ends_coords_list.front()).first << "," << ((*it_chain).ends_coords_list.front()).second << ") ";
short count = 0;
auto it_bool_auto = (*it_chain).orientations_list.begin();
for(auto it_auto = (*it_chain).ends_coords_list.begin(); it_auto != (*it_chain).ends_coords_list.end() && count<5;
it_auto++, count++, it_bool_auto++)
cout << "(" << (*it_auto).first << "," << (*it_auto).second << "," << ( (*it_bool_auto)?"1":"0" ) << ") ";
it_chain++;
bool is_chain_extension_valid;
while(it_chain != all_component_chains_list.end()){
if(metablock_last_orientations_list.size() != ( *it_assembly_outerlist ).size()){
cout<<"\nLIST_SIZE_MISMATCH_ISSUE!!! : "<<( *it_assembly_outerlist ).size()<<" "<<metablock_last_orientations_list.size()<<" ";
cout<<current_metablock.orientations_list.size()<<" "<<current_metablock.contig_orientations_list.size()<<"\n";
}
if( (*it_chain).chain_idx.first != current_metablock.comp_idx ){
metablock_list.push_back(current_metablock);
iter_diff = (*it_chain).chain_idx.first - current_metablock.comp_idx;
// it_assembly_outerlist++;
advance(it_assembly_outerlist, iter_diff);
cout<< "\n";
current_metablock = init_chain_as_metablock(*it_chain);