-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCleanBar.c
1311 lines (979 loc) · 34.9 KB
/
CleanBar.c
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
//----------------------------------------------------------------
// CLEANBAR.C : BARCODES AND SINGLE CELL SEQUENCING
//----------------------------------------------------------------
// 1- Barcodes are searched in order
// 2- We use the direct and reverse_complementary sequences
// 3- We search for consecutive BARCODES.
// 4- We generate output FASTQ file with with 4 BARCODES.
// 5- Also with 2 or 3 Barcodes.
// 6- Different folders for reads with 4 BARCODES and 2 or 3.
//----------------------------------------------------------------
// 7- We always show both senses of the READ
// 8- We clean the READS from the output files with 4 BARCODES
//----------------------------------------------------------------
// 9- We generate a single output file for 0 or 1 BARCODE.
// And also for 2 or 3 barcodes.
//
//----------------------------------------------------------------
//----------------------------------------------------------------
// Project Manager: Maria Dzunkova
//----------------------------------------------------------------
// Programmed by: Vicente Arnau. 20-VII-2024
//----------------------------------------------------------------
//----------------------------------------------------------------
// Compile as : gcc -O2 -o CB CleanBar.c
//----------------------------------------------------------------
// Execute as : CB <options> bar_file fastq_file
//----------------------------------------------------------------
// Examples of use:
// CB barcodes.txt Atrandi_1k.fq
// CB barcodes.txt Atrandi_100.fq
// CB -l 55 -s 99 barcodes.txt Atrandi_100.fq
// CB barcodes.txt Atrandi_2.fastq
//----------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//======>> Constants that depend on the file with the BARCODES:
#define MAXBAR 24 //--> Number of BARCODES per position
#define BARSIZE 8 //--> BARCODE SIZE
#define LINKSIZE 4 //--> LINK SIZE
//==============================================================
#define CAB_4 320 //--> large value
//--> (greater than CAB+BARSIZE+LINKSIZE)
#define SS_100 100
//=====> ASCII character code: "#" "." "-"
#define SOS 35 //--> ASCII code
#define PUNTO 46 //--> ASCII code
#define MENOS 45 //--> ASCII code
#define SS 32 //--> Size of BARCODE LABELS
//=====> longitud maxima ETI = 370
#define SSS 600
//=====> longitud maxima SEQ = 320000 nt
#define SSS4 20000000 //--> 40Mnt
//=======>>>>>>> These folders must already be created:
#define FF_4BAR "res_4barcodes/"
#define FF_23BAR "res_23barcodes/"
//=======>>>>>>> Non-output files (Ficheros de NO salida):
#define No_file " ------ "
//------->> Predefined functions (at the end of the file):
int busca(char *bar, char *sss, int pos, int CAB);
int inv_com(char *ss1, char *ss2);
int main( int argc, char *argv[])
{
FILE *fbar, *ffastq, *fout, *fest;
FILE *ff10, *ff23;
FILE *facu; //------>> para acumular las reads
char *ficha, *ficha_base, caracter;
char *ff_stats[SS_100], *ff_sum[SS_100];
char ff_aux_base[SS_100], ff_aux[SS_100]; //--> for output files
char *linea, *auxss, *auxll;
int i, j, k, contador;
int encontrados_A, encontrados_B, encontrados_C, encontrados_D;
int pos_D, pos_C, pos_B, pos_A, dd, tengo_bar;
char *linea1, *linea2, *linea2_inv, *linea3, *linea4;
char *linea2_clean, *linea4_clean;
char *lin_dir;
int len1, len2, len3, len4, maxlen1, maxlen2;
int cuantos=0, cc_dir=0, cc_ic=0;
int encontrados=0, completos=0, lim=0;
char *nomff1, *nomff2; //----> name of the two output files
int pos_max_dir, pos_max_ic;
int corte_dir, corte_ic;
int pos_D_d, pos_C_d, pos_B_d, pos_A_d;
int i_barD=-1, min_dd=0;
int ii, jj, kk, aux, aux2, pos_bus=0;
int indice_D, indice_C, indice_B, indice_A;
int uno_cero=0;
float faux, faux1, faux2;
char ss_com[BARSIZE+1];
//------------------->> You can change SS to BARSIZE+1:
char etiAA[MAXBAR][SS], SSA[MAXBAR][BARSIZE+1];
char etiBB[MAXBAR][SS], SSB[MAXBAR][BARSIZE+1];
char etiCC[MAXBAR][SS], SSC[MAXBAR][BARSIZE+1];
char etiDD[MAXBAR][SS], SSD[MAXBAR][BARSIZE+1];
//----------------------------
//-------------------->> default values
//---------> number of predefined reads with screen output:
int LLL_VEO= 2000;
//-------->> number of nucleotides analyzed at the start of the read
int HEAD = 88;
int CAB = 80; //---> (HEAD-BARSIZE)
printf ( "===================================================");
printf ("\n= CleanBar : Single Cell data analysis =");
printf ("\n===================================================");
printf ("\n= Vicente Arnau & Maria Dzunkova . 20-XII-2024 =");
printf ("\n===================================================\n");
if (argc == 1) {
printf("\nSINTAX: ./CB <options> BARCODES_File FASTQ_File ");
printf(" > screen_File ");
printf("\n\nYou can use this: ./CB --help \n");
fflush(stdin); getchar(); exit(0);
}
if (argc == 2){
// printf("\n ##%s##", argv[1]);
aux=1; aux2=1;
aux= strcmp ( argv[1], "-help");
aux2= strcmp ( argv[1], "--help");
if ((aux==0) || (aux2==0)){
printf("\nSINTAX: ./CB <options> BARCODES_File FASTQ_File");
printf(" > screen_output_File \n");
printf("\n<options>: ");
printf("\n -l\t: Number of nt parsed at the start and the end of a read");
printf("\n -s\t: Number of reads showed on the screen");
printf("\n \t: screen_output_File is optional \n");
fflush(stdin); getchar(); exit(0);
}
else {
printf("\nYou can use this: ./CB --help");
fflush(stdin); getchar(); exit(0);
}
}
//==============================================================
//======== I reserve dynamic memory for STRINGS:
auxll= (char *) calloc (SSS, sizeof(char));
auxss= (char *) calloc (SSS, sizeof(char));
linea = (char *) calloc (SSS, sizeof(char));
ficha = (char *) calloc (SSS, sizeof(char));
ficha_base = (char *) calloc (SSS, sizeof(char));
nomff1 = (char *) calloc (SSS, sizeof(char));
nomff2 = (char *) calloc (SSS, sizeof(char));
linea1= (char *) calloc (SSS, sizeof(char));
linea2= (char *) calloc (SSS4, sizeof(char));
linea3= (char *) calloc (SS, sizeof(char));
linea4= (char *) calloc (SSS4, sizeof(char));
linea2_inv = (char *) calloc (SSS4, sizeof(char));
linea2_clean= (char *) calloc (SSS4, sizeof(char));
linea4_clean= (char *) calloc (SSS4, sizeof(char));
lin_dir = (char *) calloc (SSS, sizeof(char));
//==============================================================
//------------->> NO OPTIONS:
if (argc == 3){
strcpy(ficha, argv[1]);
if ( (fbar=fopen(ficha,"r"))==NULL) {
printf ("\n Problems with %s??", ficha);
fflush(stdin); getchar(); exit(0);
}
printf ("\n BARCODES File: %s", ficha);
strcpy(ficha, argv[2]);
if ( (ffastq=fopen(ficha,"r"))==NULL) {
printf ("\n Problems with %s??", ficha);
fflush(stdin); getchar(); exit(0);
}
printf ("\n FASTQ File : %s\n", ficha);
strcpy(ficha_base, ficha);
printf ("\n==================================================");
}
else {//----->> WHIT OPTIONS:
if (argc == 5){
aux=1;
aux= strcmp ( argv[1], "-s");
if (aux==0){ //---> we modify the lines per screen that we display
LLL_VEO= atoi(argv[2]);
printf ("\nLines per screen = %d\n", LLL_VEO);
}
else {
aux=1;
aux= strcmp ( argv[1], "-l");
if (aux==0){ //---> we modify head (CAB+SIZEBAR)
HEAD= atoi(argv[2]);
printf ("\nSequence length analyzed = %d\n", HEAD);
CAB = HEAD - BARSIZE;
}
}
//---> Now I read the data files:
strcpy(ficha, argv[3]);
if ( (fbar=fopen(ficha,"r"))==NULL) {
printf ("\n Problems with %s??", ficha);
fflush(stdin); getchar(); exit(0);
}
printf ("\n BARCODES File: %s", ficha);
strcpy(ficha, argv[4]);
if ( (ffastq=fopen(ficha,"r"))==NULL) {
printf ("\n Problems with %s??", ficha);
fflush(stdin); getchar(); exit(0);
}
printf ("\n FASTQ File : %s\n", ficha);
strcpy(ficha_base, ficha);
printf ("\n==================================================");
}
else if (argc == 7){//------->> Ultimo IF-ELSE
//--> Primer opcional:
aux=1;
aux= strcmp ( argv[1], "-s");
if (aux==0){ //---> we modify the lines per screen that we display
LLL_VEO= atoi(argv[2]);
printf ("\nLines per screen = %d\n", LLL_VEO);
}
else {
aux=1;
aux= strcmp ( argv[1], "-l");
if (aux==0){ //---> we modify head (CAB+SIZEBAR)
HEAD= atoi(argv[2]);
printf ("\nSequence length analyzed = %d\n", HEAD);
CAB = HEAD - BARSIZE;
}
}
//--> Segundo opcional:
aux=1;
aux= strcmp ( argv[3], "-s");
if (aux==0){ //---> we modify the lines per screen that we display
LLL_VEO= atoi(argv[4]);
printf ("\nLines per screen = %d\n", LLL_VEO);
}
else {
aux=1;
aux= strcmp ( argv[3], "-l");
if (aux==0){ //---> we modify head (CAB+SIZEBAR)
HEAD= atoi(argv[4]);
printf ("\nSequence length analyzed = %d\n", HEAD);
CAB = HEAD - BARSIZE;
}
}
//---> Now I read the data files:
strcpy(ficha, argv[5]);
if ( (fbar=fopen(ficha,"r"))==NULL) {
printf ("\n Problems with %s??", ficha);
fflush(stdin); getchar(); exit(0);
}
printf ("\n BARCODES File: %s", ficha);
strcpy(ficha, argv[6]);
if ( (ffastq=fopen(ficha,"r"))==NULL) {
printf ("\n Problems with %s??", ficha);
fflush(stdin); getchar(); exit(0);
}
printf ("\n FASTQ File : %s\n", ficha);
strcpy(ficha_base, ficha);
printf ("\n==================================================");
}//---->> del último IF-ELSE
}
// printf("\n ... press a key <CR> ");
// fflush(stdin); getchar();
//============>> We generate the name of the output files:
//---> Generating "_stats.txt" file:
ff_aux_base[0]=0; //--> inicialized
aux= strlen(ficha_base); // printf("\n length of %s = %d", ficha_base, aux);
i=0;
do {
ff_aux_base[i]= ficha_base[i]; i++;
}
while ((ficha_base[i-1] != PUNTO) && (i<aux));
ff_aux_base[i-1]=0; //--> end of string, no dot
strcpy(ff_aux, ff_aux_base);
strcat(ff_aux, "_stats.txt");
fest=fopen(ff_aux, "w");
printf("\n Stats file : %s", ff_aux);
//--------------------------------------
//---> Generating "_summary.txt" file:
strcpy(ff_aux, ff_aux_base);
strcat(ff_aux, "_summary.txt");
fout=fopen(ff_aux, "w");
printf("\n Summary file : %s", ff_aux);
//--------------------------------------------------
//------>> Ficheros de salida con 0+1 o 2+3 BARCODES:
strcpy(ff_aux, ff_aux_base);
strcat(ff_aux, "_1_0_bar.fq");
printf("\n File with 1 or 0 barcode : %s", ff_aux);
ff10=fopen(ff_aux,"a+");
//-------
strcpy(ff_aux, ff_aux_base);
strcat(ff_aux, "_3_2_bar.fq");
printf("\n File with 3 or 2 barcode : %s", ff_aux);
ff23=fopen(ff_aux,"a+");
printf ("\n==================================================\n");
// fflush(stdin); getchar();
//******** Leo datos de BARCODES.TXT y guardo en arrays *********
//====>> BARCODES A ======================
caracter= getc(fbar);
if (caracter!=SOS)
{printf("\n We started wrong: %c ", caracter); exit(0);}
auxss=fgets(linea, SSS, fbar);
printf("#%s", linea);
//---------------------------
for (i=0; i<MAXBAR; i++){
fscanf(fbar,"%s %s", etiAA[i], SSA[i]);
printf("\n%2d %s %s", i, etiAA[i], SSA[i]);
}
printf("\n------------------------------------------- \n");
//====>> BARCODES B ======================
caracter= getc(fbar);
if (caracter!=SOS){
auxss=fgets(linea, SSS, fbar);
caracter= getc(fbar);
}
if (caracter!=SOS)
{printf("\n Bad second set of barcodes: %c ", caracter); exit(0);}
auxss=fgets(linea, SSS, fbar);
printf("#%s", linea);
//---------------------------
for (i=0; i<MAXBAR; i++){
fscanf(fbar,"%s %s", etiBB[i], SSB[i]);
printf("\n%2d %s %s", i, etiBB[i], SSB[i]);
}
printf("\n------------------------------------------- \n");
//====>> BARCODES C ======================
caracter= getc(fbar);
if (caracter!=SOS){
auxss=fgets(linea, SSS, fbar);
caracter= getc(fbar);
}
auxss=fgets(linea, SSS, fbar);
printf("#%s", linea);
//---------------------------
for (i=0; i<MAXBAR; i++){
fscanf(fbar,"%s %s", etiCC[i], SSC[i]);
printf("\n%2d %s %s", i, etiCC[i], SSC[i]);
}
printf("\n------------------------------------------- \n");
//====>> BARCODES D ======================
caracter= getc(fbar);
if (caracter!=SOS){
auxss=fgets(linea, SSS, fbar);
caracter= getc(fbar);
}
auxss=fgets(linea, SSS, fbar);
printf("#%s", linea);
//---------------------------
for (i=0; i<MAXBAR; i++){
fscanf(fbar,"%s %s", etiDD[i], SSD[i]);
printf("\n%2d %s %s", i, etiDD[i], SSD[i]);
}
printf("\n------------------------------------------- \n");
// fflush(stdin); getchar();
//==============================================================
//========= READ THE FASTQ FILE
//==============================================================
maxlen1=0; maxlen2=0;
contador=0; uno_cero=0;
lim=0;
encontrados_A=0; encontrados_B=0; encontrados_C=0; encontrados_D=0;
while (!feof(ffastq)) {
linea1[0]=0; linea2[0]=0, linea3[0]=0, linea4[0]=0;
//--->> PRIMERA linea de fichero FASTQ
auxss= fgets(linea1, SSS, ffastq);
len1=strlen(linea1); linea1[len1-1]=0;
if(len1>2){
if (len1>maxlen1) maxlen1=len1;
}
//--->> SEGUNDA linea de fichero FASTQ
auxss= fgets(linea2, SSS4-1, ffastq);
len2=strlen(linea2); linea2[len2-1]=0;
if(len1>2){
if (len2>maxlen2) maxlen2=len2;
}
//--->> TERCERA linea. La leo y paso de ella:
auxss= fgets(linea3, SS, ffastq);
len3= strlen(linea3); linea3[len3-1]=0;
//--->> CUARTA linea: La leo y no la uso:
auxss= fgets(linea4, SSS4-1, ffastq);
len4 = strlen(linea4); linea4[len4-1]=0;
// printf("\n--------------------------------");
//fflush(stdin); getchar();
cuantos=0; cc_dir=0;
if (len2>CAB){//====================>> TENGO LINEA2 <<===========
strcpy(nomff1, "ff_"); //---> inicio de nombre de fichero
cc_dir=0;
contador++; lim++;
fprintf(fout, "%s\tDirect\t%5d", linea1, contador);
//-------------->> BARCODE_D : <<--------------------------
if (lim <= LLL_VEO) //-->> por pantalla las primeras LLL_VEO reads
printf("\n---------%6d - dir ----------------", contador);
tengo_bar=0;
i_barD=0; dd= -1; min_dd= CAB_4; //--> UN NUMERO GRANDE.
for (i=0; i<MAXBAR; i++){
//--> Funcion de busqueda de BARCODES:
dd= busca(SSD[i], linea2, 0, CAB);
if (dd>=0){
if(dd<min_dd){
min_dd=dd;
i_barD= i;
//printf("[%3d]-", min_dd);
}
}
}//---->> del for(i)
//printf("\n");
if ((min_dd>=0) && (min_dd!=CAB_4)){
// printf("\n-------> linea : %6d", contador);
if (lim <= LLL_VEO){
printf("\n%d\t -->[BARCODE_D]\n", min_dd);
for (k=0; k<(CAB+BARSIZE); k++) printf("%c", linea2[k]);
printf ("\n");
for (k=0; k<min_dd; k++) printf(" ");
printf ("%s\t", SSD[i_barD]);
printf (" --> %s\n", etiDD[i_barD]);
}
fprintf(fout, "\t%s", etiDD[i_barD]);
cc_dir++;
encontrados_D++;
// tengo_bar=1; //---> SALGO: he encontrado BARCODE-D
// fflush(stdin); getchar();
}
if ((min_dd>=0) && (min_dd!=CAB_4))
dd= min_dd;
else dd= -1;
pos_D= dd;
if (dd<0) fprintf(fout, "\t...\t%3d", dd);
else fprintf(fout, "\t%3d", pos_D);
if (dd<0) strcat(nomff1, "____");
else{
strcat(nomff1, etiDD[i_barD]);
strcat(nomff1, "_");
}
//-------------->> BARCODE_C :
tengo_bar=0; i=0; dd= -1;
if (pos_D>=0) pos_bus= pos_D + 8;
else pos_bus= 0;
do{
//-------->> Trozo de linea2 con lo que compara el BARCODE:
kk=0;
for(k=pos_bus; k < (pos_bus+BARSIZE); k++, kk++) {
ss_com[kk]= linea2[k];
}
ss_com[BARSIZE] = 0; //--> final de string !!!
jj=0;
do{
aux= strcmp(ss_com, SSC[jj]);
if (aux==0) tengo_bar=1;
jj++;
}
while ((jj<MAXBAR) && (tengo_bar==0) );
//dd = pos_bus;
indice_C = jj-1;
if (tengo_bar == 1){
dd= pos_bus;
//printf("\n-------> linea : %6d", contador);
if (lim <= LLL_VEO){
printf("\n%d\t --> [BARCODE_C]\n", dd);
for (k=0; k < (CAB+BARSIZE); k++) printf("%c", linea2[k]);
printf ("\n");
for (k=0; k<dd; k++) printf(" ");
printf ("%s\t", SSC[indice_C]);
printf (" --> %s\n", etiCC[indice_C]);
}
fprintf(fout, "\t%s", etiCC[indice_C]);
cc_dir++;
encontrados_C++;
// fflush(stdin); getchar();
}
pos_bus++;
}
while ((tengo_bar==0) && (pos_bus<CAB));
pos_C= dd;
if (dd<0) fprintf(fout, "\t...\t%3d", dd);
else fprintf(fout, "\t%3d", pos_C);
// fprintf(fout, "\n");
if (dd<0) strcat(nomff1, "___");
else{
strcat(nomff1, etiCC[indice_C]);
strcat(nomff1, "_");
}
//-------------->> BARCODE_B :
tengo_bar=0; i=0; dd= -1;
if (pos_C>=0) pos_bus= pos_C + 8;
else pos_bus= 0;
do{
//-------->> Trozo de linea2 con lo que compara el BARCODE:
kk=0;
for(k=pos_bus; k < (pos_bus+BARSIZE); k++, kk++) {
ss_com[kk]= linea2[k];
}
ss_com[BARSIZE] = 0; //--> final de string !!!
jj=0;
do{
aux= strcmp(ss_com, SSB[jj]);
if (aux==0) tengo_bar=1;
jj++;
}
while ((jj<MAXBAR) && (tengo_bar==0) );
indice_B = jj-1;
if (tengo_bar == 1){
dd= pos_bus;
if (lim <= LLL_VEO){
printf("\n%d\t --> [BARCODE_B]\n", dd);
for (k=0; k< (CAB+BARSIZE); k++) printf("%c", linea2[k]);
printf ("\n");
for (k=0; k<dd; k++) printf(" ");
printf ("%s\t", SSB[indice_B]);
printf (" --> %s\n", etiBB[indice_B]);
}
fprintf(fout, "\t%s", etiBB[indice_B]);
cc_dir++;
encontrados_B++;
// fflush(stdin); getchar();
}
pos_bus++;
}
while ((tengo_bar==0) && (pos_bus<CAB));
pos_B= dd;
if (dd<0) fprintf(fout, "\t...\t%3d", dd);
else fprintf(fout, "\t%3d", pos_B);
// fprintf(fout, "\n");
if (dd<0) strcat(nomff1, "___");
else{
strcat(nomff1, etiBB[indice_B]);
strcat(nomff1, "_");
}
//-------------->> BARCODE_A :
tengo_bar=0; i=0; dd= -1;
if (pos_B>=0) pos_bus= pos_B + 8;
else pos_bus= 0;
do{
//-------->> Trozo de linea2 con lo que compara el BARCODE:
kk=0;
for(k=pos_bus; k < (pos_bus+BARSIZE); k++, kk++) {
ss_com[kk]= linea2[k];
}
ss_com[BARSIZE] = 0; //--> final de string !!!
jj=0;
do{
aux= strcmp(ss_com, SSA[jj]);
if (aux==0) tengo_bar=1;
jj++;
}
while ((jj<MAXBAR) && (tengo_bar==0) );
indice_A = jj-1;
if (tengo_bar == 1){
dd= pos_bus;
if (lim <= LLL_VEO){
printf("\n%d\t --> [BARCODE_A]\n", dd);
for (k=0; k< (CAB+BARSIZE); k++) printf("%c", linea2[k]);
printf ("\n");
for (k=0; k<dd; k++) printf(" ");
printf ("%s\t", SSA[indice_A]);
printf (" --> %s\n", etiAA[indice_A]);
}
fprintf(fout, "\t%s", etiAA[indice_A]);
cc_dir++;
encontrados_A++;
}
pos_bus++;
}
while ((tengo_bar==0) && (pos_bus<CAB));
pos_A= dd;
if (dd<0) fprintf(fout, "\t...\t%3d", dd);
else fprintf(fout, "\t%3d", pos_A);
// fprintf(fout, "\n");
// if (dd<0) strcat(nomff1, "___");
if (dd<0) strcat(nomff1, "__");
else{
strcat(nomff1, etiAA[indice_A]);
}
//----->> Posicion en DIR para limpiar las reads:
pos_max_dir=0;
if (cc_dir==4) pos_max_dir= pos_A;
else {
if (pos_D > pos_max_dir) pos_max_dir=pos_D;
if (pos_C > pos_max_dir) pos_max_dir=pos_C;
if (pos_B > pos_max_dir) pos_max_dir=pos_B;
if (pos_A > pos_max_dir) pos_max_dir=pos_A;
}
//----> Copio valores:
pos_D_d= pos_D; pos_C_d= pos_C; pos_B_d= pos_B; pos_A_d= pos_A;
strcat(nomff1, ".fq"); //--->> siempre con *.fq
// if (cc_dir==4) fflush(stdin); getchar();
//===================================================================
//========>> Search in reverse complementary (INVERSA_COMPLEMENTARIA)
//--------->> REVERSE COMPLEMENTARY:
k = inv_com(linea2_inv, linea2);
strcpy(nomff2, "ff_"); //---> inicio de nombre de fichero
cc_ic= 0;
fprintf(fout, "\tRev_com\t%5d", contador);
//-------------->> BARCODE_D : NUEVA FUNCION!!
if (lim <= LLL_VEO) //-->> por pantalla las primeras LLL_VEO reads
printf("\n---------%6d - rc ----------------", contador);
tengo_bar=0;
i_barD=0; dd= 0; min_dd= CAB_4; //--> UN NUMERO GRANDE.
for (i=0; i<MAXBAR; i++){
//--> Funcion de busqueda de BARCODES:
dd = busca(SSD[i], linea2_inv, 0, CAB);
if (dd>=0){
if(dd<min_dd){
min_dd=dd;
i_barD= i;
}
}
}//---->> del for(i)
if ((min_dd>=0) && (min_dd!=CAB_4)){
// printf("\n-------> linea : %6d", contador);
if (lim <= LLL_VEO){
printf("\n%d\t -->[BARCODE_D]\n", min_dd);
for (k=0; k<(CAB+BARSIZE); k++) printf("%c", linea2_inv[k]);
printf ("\n");
for (k=0; k<min_dd; k++) printf(" ");
printf ("%s\t", SSD[i_barD]);
printf (" --> %s\n", etiDD[i_barD]);
}
fprintf(fout, "\t%s", etiDD[i_barD]);
cc_ic++;
encontrados_D++;
// tengo_bar=1; //---> SALGO: he encontrado BARCODE-D
// fflush(stdin); getchar();
}
if ((min_dd>=0) && (min_dd!=CAB_4))
dd= min_dd;
else dd= -1;
pos_D= dd;
if (dd<0) fprintf(fout, "\t...\t%3d", dd);
else fprintf(fout, "\t%3d", pos_D);
if (dd<0) strcat(nomff2, "____");
else{
strcat(nomff2, etiDD[i_barD]);
strcat(nomff2, "_");
}
//-------------->> BARCODE_C :
tengo_bar=0; i=0; dd= -1;
if (pos_D>=0) pos_bus= pos_D + 8;
else pos_bus= 0;
do{
//-------->> Trozo de linea2_inv con lo que compara el BARCODE:
kk=0;
for(k=pos_bus; k < (pos_bus+BARSIZE); k++, kk++) {
ss_com[kk]= linea2_inv[k];
}
ss_com[BARSIZE] = 0; //--> final de string !!!
jj=0;
do{
aux= strcmp(ss_com, SSC[jj]);
if (aux==0) tengo_bar=1;
jj++;
}
while ((jj<MAXBAR) && (tengo_bar==0) );
indice_C = jj-1;
if (tengo_bar == 1){
dd= pos_bus;
if (lim <= LLL_VEO){
printf("\n%d\t --> [BARCODE_C]\n", dd);
for (k=0; k<(CAB+BARSIZE); k++) printf("%c", linea2_inv[k]);
printf ("\n");
for (k=0; k<dd; k++) printf(" ");
printf ("%s\t", SSC[indice_C]);
printf (" --> %s\n", etiCC[indice_C]);
}
fprintf(fout, "\t%s", etiCC[indice_C]);
cc_ic++;
encontrados_C++;
// fflush(stdin); getchar();
}
pos_bus++;
}
while ((tengo_bar==0) && (pos_bus<CAB));
pos_C= dd;
if (dd<0) fprintf(fout, "\t...\t%3d", dd);
else fprintf(fout, "\t%3d", pos_C);
// fprintf(fout, "\n");
if (dd<0) strcat(nomff2, "___");
else{
strcat(nomff2, etiCC[indice_C]);
strcat(nomff2, "_");
}
//-------------->> BARCODE_B :
tengo_bar=0; i=0; dd= -1;
if (pos_C>=0) pos_bus= pos_C + 8;
else pos_bus= 0;
do{
//-------->> Trozo de linea2_inv con lo que compara el BARCODE:
kk=0;
for(k=pos_bus; k < (pos_bus+BARSIZE); k++, kk++) {
ss_com[kk]= linea2_inv[k];
}
ss_com[BARSIZE] = 0; //--> final de string !!!
jj=0;
do{
aux= strcmp(ss_com, SSB[jj]);
if (aux==0) tengo_bar=1;
jj++;
}
while ((jj<MAXBAR) && (tengo_bar==0) );
indice_B = jj-1;
if (tengo_bar == 1){
dd= pos_bus;
if (lim <= LLL_VEO){
printf("\n%d\t --> [BARCODE_B]\n", dd);
for (k=0; k<(CAB+BARSIZE); k++) printf("%c", linea2_inv[k]);
printf ("\n");
for (k=0; k<dd; k++) printf(" ");
printf ("%s\t", SSB[indice_B]);
printf (" --> %s\n", etiBB[indice_B]);
}
fprintf(fout, "\t%s", etiBB[indice_B]);
cc_ic++;
encontrados_B++;
// fflush(stdin); getchar();
}
pos_bus++;
}
while ((tengo_bar==0) && (pos_bus<CAB));
pos_B= dd;
if (dd<0) fprintf(fout, "\t...\t%3d", dd);
else fprintf(fout, "\t%3d", pos_B);
if (dd<0) strcat(nomff2, "___");
else{
strcat(nomff2, etiBB[indice_B]);
strcat(nomff2, "_");
}
//-------------->> BARCODE_A :
tengo_bar=0; i=0; dd= -1;
if (pos_B>=0) pos_bus= pos_B + 8;
else pos_bus= 0;
do{
//-------->> Trozo de linea2_inv con lo que compara el BARCODE:
kk=0;
for(k=pos_bus; k < (pos_bus+BARSIZE); k++, kk++) {
ss_com[kk]= linea2_inv[k];
}
ss_com[BARSIZE] = 0; //--> final de string !!!
jj=0;
do{
aux= strcmp(ss_com, SSA[jj]);
if (aux==0) tengo_bar=1;
jj++;
}
while ((jj<MAXBAR) && (tengo_bar==0) );
indice_A = jj-1;
if (tengo_bar == 1){
dd= pos_bus;
if (lim <= LLL_VEO){
printf("\n%d\t --> [BARCODE_A]\n", dd);
for (k=0; k<(CAB+BARSIZE); k++) printf("%c", linea2_inv[k]);
printf ("\n");
for (k=0; k<dd; k++) printf(" ");
printf ("%s\t", SSA[indice_A]);
printf (" --> %s\n", etiAA[indice_A]);
}
fprintf(fout, "\t%s", etiAA[indice_A]);
cc_ic++;
encontrados_A++;
// fflush(stdin); getchar();
}
pos_bus++;
}
while ((tengo_bar==0) && (pos_bus<CAB));