This repository was archived by the owner on Apr 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrch4prf.c
893 lines (792 loc) · 25.2 KB
/
srch4prf.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
/****************************************************************************/
/* */
/* But: Alignement entre une sequence et une collection de profils */
/* */
/****************************************************************************/
/*3456789012345678901234567890123456789012345678901234567890123456789012345678*/
#ifdef _SUN_
#include <floatingpoint.h>
#endif
#include <stddef.h>
#include <stdio.h>
#include <float.h>
#include "error.h"
#include "ReadPrfFile.h"
#include "PrfExtr.h"
#include "ReadSeqFile.h"
#include "ReadFASTAFile.h"
#include "SeqExtr.h"
#include "PrfAlign.h"
#include "ErrTable.h"
#include "ReadPar.h"
/**************/
/* CONSTANTES */
/**************/
/*=========================*/
/* Constantes du programme */
/*=========================*/
#define TEST_NBR 1
/**********/
/* MACROS */
/**********/
/*--------------------------------------------------------------------------*/
/* Impression du format d'appel */
/*--------------------------------------------------------------------------*/
void Print_Format()\
{
fprintf(stderr, "\
Usage:\nsrch4prf -s seq_library_file [-p profile_file] [-i profile_ID]\n\
[-l cut_off_level] [-o output_file] [-f] [-a] [-b] [-y] [-u] [-t] [-x]\n\n");
fflush(stderr);
}
void main(int argc, char *argv[])
{
/*****************************/
/* DECLARATION DES VARIABLES */
/*****************************/
/*=========================*/
/* Parametres du programme */
/*=========================*/
char *SeqFilename; /* Nom du fichier de sequences */
char *PrfFilename; /* Nom du fichier de profils */
char *PrfId; /* Identificateur du profil */
double CutOffLevelDouble; /* Niveau de val. de coupure en double */
TCutOffLevel CutOffLevel; /* Niveau de la valeur de coupure */
TCutOffLevel CutOffLevelUsed; /* Niveau utilise */
TScore CutOff; /* Valeur de coupure */
TBoolean SelectAll; /* Parametre de selection */
TBoolean ReportAlign; /* Reporte les alignements */
TBoolean ReportCoord; /* Reporte les coordonnees d'align. */
TBoolean Unique; /* Trouve seulement le meill. ali. */
TBoolean UniqueForced; /* Unique force */
TBoolean FASTA; /* Format FASTA ou non */
TBoolean ComplStr; /* Teste les sequences complementaires */
FILE *OutPutFile; /* Fichier de sortie */
TBoolean TestProt; /* Test ou pas les align. prot. */
/*===================*/
/* Donnees du profil */
/*===================*/
TReadPrfFilePtr ReadPrfFilePtr; /* Donnees de lecture d'un profil */
TPrfFileDataPtr PrfFileDataPtr; /* Donnees d'un fichier de profil */
TPrfExtrPtr PrfExtrPtr; /* Donnees d'extraction d'un profil */
TPrfDataPtr PrfDataPtr; /* Donnees d'un profil */
TAlphPtr AlphPtr; /* Alphabet du profil */
/*========================*/
/* Donnees de la sequence */
/*========================*/
TReadFilePtr ReadFilePtr; /* Donnees de lecture d'une sequence */
TSeqFileDataPtr SeqFileDataPtr; /* Donnees d'un fichier de sequence */
TSeqExtrPtr SeqExtrPtr; /* Donnees d'extraction d'une sequence */
TSeqDataPtr SeqDataPtr; /* Donnees d'une sequence */
/*======================================*/
/* Donnees de l'algorithme d'alignement */
/*======================================*/
TPrfAlignPtr PrfAlignPtr; /* Donnee d'alignation */
TAlignListPtr AlignListPtr; /* Liste des alignements */
TPrfAlignPtr PrfAlignResPtr; /* Resultat de l'algorithme */
TPathMatrixPtr PathMatrixPtr; /* Matrice de chemin */
TAlignPtr AlignPtr; /* Alignement particulier */
TAlignIndex AlignIndex; /* Index d'alignement */
TCoordVectPtr CoordVectPtr; /* Vecteur de coordonnees */
TCoordVectPtr TempCoordVectPtr; /* Vecteur de coordonnees */
TAliStrPtr AliStrPtr; /* Chaine d'alignement */
TAliStrPtr TempAliStrPtr; /* Chaine d'alignement */
/*======================*/
/* Donnees du programme */
/*======================*/
TErrIndex ErrIndex; /* Index d'erreur */
char ParChar; /* Caractere du type de parametre */
char *ParStr; /* Chaine parametre */
char *EndStr; /* Ptr sur chaine apres conversion */
TScore Score; /* Score d'alignement */
char *CharPtr; /* Ptr sur un caractere */
char ParLine[UCHAR_MAX]; /* Ligne de lecture de fichier */
FILE *ParFile; /* Fichier de parametres */
TMolSeqPtr MolSeqPtr; /* Sequence de molecules */
TAlignIndex FirstCplAlign; /* Index du 1er alignement compl. */
TBoolean AccAlign; /* Temoin de calcul des align. */
TBoolean AccCplAlign; /* Temoin de calcul des align. cpl. */
TAlignPtr BestAlignPtr; /* Meilleur alignement */
TAlignPtr BestCplAlignPtr; /* Meilleur alignement cpl. */
TAlignIndex HitNbr; /* Nbr d'alignements acceptes */
TDisjointDef DisjointDef; /* Definition de l'exclusion */
TCutOffListPtr CutOffListPtr; /* Liste de valeurs de coupure */
unsigned int TestIndex;
/********/
/* CODE */
/********/
/*=====================================*/
/* Lecture des parametres du programme */
/*=====================================*/
/*-------------------------------*/
/* Initialisation des parametres */
/*-------------------------------*/
SeqFilename = NULL;
PrfFilename = NULL;
CutOff = PD_INFINITE;
PrfId = NULL;
CutOffLevelDouble = DBL_MIN;
CutOffLevel = 0;
SelectAll = FALSE;
ReportAlign = FALSE;
ReportCoord = FALSE;
UniqueForced = FALSE;
TestProt = FALSE;
FASTA = FALSE;
ComplStr = FALSE;
OutPutFile = stdout;
if (argc < 2) {
ParFile = fopen("srch4prf.par", "r");
if (!ParFile) {
/* Erreur de format */
Print_Format();
exit(1);
}
CharPtr = fgets(ParLine, UCHAR_MAX, ParFile);
if (!CharPtr) {
/* Erreur de format */
Print_Format();
exit(1);
}
printf("%s\n", ParLine);
fflush(stdout);
argc = 0;
CharPtr = strtok(ParLine, " \n");
while (CharPtr) {
argv[argc++] = CharPtr;
CharPtr = strtok(NULL, " \n");
}
}
ParChar = ProgPar(argc, argv, &ParStr, &ErrIndex);
while (ErrIndex == RP_NO_ERROR) {
switch (ParChar) {
case 's':
/* Nom du fichier de sequences */
if ((!ParStr) || (SeqFilename)) {
/* Erreur de format */
Print_Format();
exit(1);
}
SeqFilename = ParStr;
break;
case 'p':
/* Nom du fichier de profils */
if ((!ParStr) || (PrfFilename)) {
/* Erreur de format */
Print_Format();
exit(1);
}
PrfFilename = ParStr;
break;
case 'i':
/* ID du profil */
if ((!ParStr) || (PrfId)) {
/* Erreur de format */
Print_Format();
exit(1);
}
PrfId = ParStr;
break;
case 'l':
/* Niveau de la valeur de coupure */
if ((!ParStr) || (CutOffLevelDouble != DBL_MIN)) {
/* Erreur de format */
Print_Format();
exit(1);
}
CutOffLevelDouble = strtod(ParStr, &EndStr);
if (*EndStr != 0) {
/* Erreur de format */
Print_Format();
exit(1);
}
CutOffLevel = (TCutOffIndex)CutOffLevelDouble;
if ((double)CutOffLevel != CutOffLevelDouble) {
/* Erreur de format */
Print_Format();
exit(1);
}
break;
case 'a':
/* Parametre de selection */
if ((ParStr) || (SelectAll)) {
/* Erreur de format */
Print_Format();
exit(1);
}
SelectAll = TRUE;
break;
case 'y':
/* Report des alignements */
if ((ParStr) || (ReportAlign)) {
/* Erreur de format */
Print_Format();
exit(1);
}
ReportAlign = TRUE;
break;
case 'u':
/* Meilleur alignement */
if ((ParStr) || (UniqueForced)) {
/* Erreur de format */
Print_Format();
exit(1);
}
UniqueForced = TRUE;
break;
case 'f':
/* Format FASTA */
if ((ParStr) || (FASTA)) {
/* Erreur de format */
Print_Format();
exit(1);
}
FASTA = TRUE;
break;
case 'b':
/* Teste la sequence complementaire */
if ((ParStr) || (ComplStr)) {
Print_Format();
exit(1);
}
ComplStr = TRUE;
break;
case 'o':
/* Nom du fichier de sortie */
if ((!ParStr) || (OutPutFile != stdout)) {
/* Erreur de format */
Print_Format();
exit(1);
}
OutPutFile = fopen((char*)ParStr, "w");
if (!OutPutFile) {
/* Erreur d'ouverture */
fprintf(stderr, "Output file opening error");
fprintf(stderr, "\n");
exit(1);
}
break;
case 't':
/* Teste les align. prot. */
if ((ParStr) || (TestProt)) {
/* Erreur de format */
Print_Format();
exit(1);
}
TestProt = TRUE;
case 'x':
/* Report des coordonnees */
if ((ParStr) || (ReportCoord)) {
/* Erreur de format */
Print_Format();
exit(1);
}
ReportCoord = TRUE;
break;
default:
/* Erreur de format */
Print_Format();
exit(1);
}
ParChar = ProgPar(argc, argv, &ParStr, &ErrIndex);
}
/*-------------------------*/
/* Controle des parametres */
/*-------------------------*/
if (!PrfFilename) PrfFilename = "PROSITE.DAT";
/* Nom du fichier de sequence obligatoire */
if (!SeqFilename) {
/* Erreur de format */
Print_Format();
exit(1);
}
/* Verification utilite de la valeur de coupure */
if (SelectAll && Unique && (CutOffLevelDouble != DBL_MIN)) {
Print_Format();
exit(1);
}
/* Exclusion affichage alignement et coordonnees */
if (ReportCoord && ReportAlign) {
Print_Format();
exit(1);
}
/* Exclusion test des alignements et exclusion = unique */
if ((TestProt) && (UniqueForced)) {
Print_Format();
exit(1);
}
for (TestIndex = 0; TestIndex < TEST_NBR; TestIndex++) {
/*========================*/
/* Lecture de la sequence */
/*========================*/
/*---------------------------------------*/
/* Initialisation des donnees de lecture */
/*---------------------------------------*/
if (FASTA) ReadFilePtr = (TReadFilePtr)I_ReadFASTAFile(
SeqFilename, &ErrIndex);
else ReadFilePtr = (TReadFilePtr)I_ReadSeqFile(SeqFilename, &ErrIndex);
if (!ReadFilePtr) {
fprintf(stderr, "Sequences file reading initialization error:\n");
Print_ErrStr(ErrTable_ErrStrNth(RSF_ErrTable, ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
/*----------------------------------*/
/* Lecture de la prochaine sequence */
/*----------------------------------*/
if (FASTA) {
SeqFileDataPtr = ReadFASTAFile_SeqFileData(
(TReadFASTAFilePtr)ReadFilePtr, &ErrIndex);
}
else {
SeqFileDataPtr = ReadSeqFile_SeqFileData(
(TReadSeqFilePtr)ReadFilePtr, &ErrIndex);
}
if (!SeqFileDataPtr) {
fprintf(stderr, "Sequences file reading error:\n");
if (FASTA) {
Print_ErrStr(ErrTable_ErrStrNth(RFF_ErrTable, ErrIndex));
}
else {
Print_ErrStr(ErrTable_ErrStrNth(RSF_ErrTable, ErrIndex));
}
fprintf(stderr, "\n");
return;
}
Free_ReadFile(ReadFilePtr);
/*=================================================*/
/* Initialisation des donnees de lecture du profil */
/*=================================================*/
ReadPrfFilePtr = I_ReadPrfFile(PrfFilename, &ErrIndex);
if (!ReadPrfFilePtr) {
fprintf(stderr, "Profile file reading initialization error:\n");
Print_ErrStr(ErrTable_ErrStrNth(RPF_ErrTable, ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
/*====================================*/
/* Affichage des donnees du programme */
/*====================================*/
/*-----------------*/
/* Donnees general */
/*-----------------*/
printf("\n");
printf("Program: srch4prf\n");
printf("Version: v1.00\n");
printf("Author: Nicolas Moeri\n");
printf("Description: Compares a sequence against a profiles database\n");
printf("\n");
printf("Infinite negative score is %d\n", PD_INFINITE);
printf("\n");
fflush(stdout);
/*------------------------*/
/* Parametres utilisateur */
/*------------------------*/
fprintf(OutPutFile, "Profiles database: %s\n", PrfFilename);
fprintf(OutPutFile, "Sequences database: %s\n", SeqFilename);
fprintf(OutPutFile, "Sequence name: ");
Out_SeqId(OutPutFile, SeqFileData_Id(SeqFileDataPtr));
fprintf(OutPutFile, "\n");
fprintf(OutPutFile, "Sequence description: ");
Out_Sent20(OutPutFile, SeqFileData_De((SeqFileDataPtr)));
fprintf(OutPutFile, "\n\n");
/*---------------------*/
/* En-tete du resultat */
/*---------------------*/
fprintf(OutPutFile, "Alignments results\n");
fprintf(OutPutFile, "==================\n");
if ((!ReportAlign) && (!ReportCoord)) {
fprintf(OutPutFile,
"\nProfile name Description Hits Score Position \n");
fprintf(OutPutFile,
"-------------------------------------------------------------------------------\n");
}
fflush(OutPutFile);
/*===================*/
/* Boucle de lecture */
/*===================*/
while(TRUE) {
/*====================*/
/* Lecture du profil */
/*====================*/
/*------------------------------------------*/
/* Lecture des donnees du fichier de profil */
/*------------------------------------------*/
PrfFileDataPtr = ReadPrfFile_PrfFileData(ReadPrfFilePtr, PrfId,
&ErrIndex);
if (!PrfFileDataPtr) {
if (!PrfId && (ErrIndex == RPF_ID_EXP_UEOF)) {
/* Fin du fichier: on sort de la boucle */
break;
}
fprintf(stderr, "Profile file reading error:\n");
Print_ErrStr(ErrTable_ErrStrNth(RPF_ErrTable, ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
/*----------------------------------*/
/* Extraction des donnees du profil */
/*----------------------------------*/
PrfExtrPtr = I_PrfExtr(PrfFileDataPtr);
if (!PrfExtrPtr) {
fprintf(stderr, "Profile extraction initialization error:\n");
fprintf(stderr, "Allocation error\n");
exit(1);
}
PrfDataPtr = PrfExtr_PrfData(PrfExtrPtr, &ErrIndex);
if (!PrfDataPtr) {
fprintf(stderr, "Profile extraction error:\n");
Print_ErrStr(ErrTable_ErrStrNth(PE_ErrTable, ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
Free_PrfFileData(PrfFileDataPtr);
Free_PrfExtr(PrfExtrPtr);
/*-------------------------*/
/* Recherche de l'alphabet */
/*-------------------------*/
AlphPtr = GenSpec_Alph(PrfData_GenSpec(PrfDataPtr));
/*------------------------------------*/
/* Definition utilisee de l'exclusion */
/*------------------------------------*/
if (!UniqueForced) {
DisjointDef = Disjoint_Def(PrfData_Disjoint(PrfDataPtr));
if (DisjointDef == PD_UNIQUE) {
Unique = TRUE;
}
else if (DisjointDef == PD_PROTECT) {
Unique = FALSE;
}
else {
fprintf(stderr, "Program error:\n");
Print_ErrStr("Unknow disjoint definition");
fprintf(stderr, "\n");
exit(1);
}
}
else {
Unique = TRUE;
}
/*-----------------------------------*/
/* Recherche de la valeur de coupure */
/*-----------------------------------*/
/* Controle du debordement du niveau de valeur de coupure */
CutOffListPtr = PrfData_CutOffList(PrfDataPtr);
if (CutOff_Level(CutOffList_CutOffNth(CutOffListPtr, 0)) >
CutOffLevel) {
CutOffLevelUsed =
CutOff_Level(CutOffList_CutOffNth(CutOffListPtr, 0));
}
else if (CutOff_Level(CutOffList_CutOffNth(CutOffListPtr,
CutOffList_CutOffNbr(CutOffListPtr) - 1)) < CutOffLevel) {
CutOffLevelUsed = CutOff_Level(CutOffList_CutOffNth(CutOffListPtr,
CutOffList_CutOffNbr(CutOffListPtr) - 1));
}
else {
CutOffLevelUsed = CutOffLevel;
}
CutOff = CutOff_Score(CutOffList_CutOffNth(PrfData_CutOffList
(PrfDataPtr), CutOffLevelUsed));
/*=========================*/
/* Creation de la sequence */
/*=========================*/
/*-----------------------------------------*/
/* Initialisation des donnees d'extraction */
/*-----------------------------------------*/
SeqExtrPtr = I_SeqExtr(SeqFileDataPtr, AlphPtr);
if (!SeqExtrPtr) {
fprintf(stderr, "Sequence extraction initialization error:\n");
fprintf(stderr, "Allocation error\n");
exit(1);
}
/*------------------------*/
/* Extraction des donnees */
/*------------------------*/
SeqDataPtr = SeqExtr_SeqData(SeqExtrPtr);
if (!SeqDataPtr) {
fprintf(stderr, "Sequence extraction error\n");
fprintf(stderr, "Allocation error\n");
exit(1);
}
Free_SeqExtr(SeqExtrPtr);
/*============*/
/* Alignement */
/*============*/
/*-------------------------*/
/* Selection des sequences */
/*-------------------------*/
BestAlignPtr = PrfAlign_BestAlign(PrfData_PrfMatrix(PrfDataPtr),
SeqData_MolSeq(SeqDataPtr), &ErrIndex);
if (!BestAlignPtr) {
/* Erreur */
fprintf(stderr, "Best alignment algorithme error:\n");
Print_ErrStr(ErrTable_ErrStrNth(PA_ErrTable, ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
if (Align_Score(BestAlignPtr) >= CutOff) AccAlign = TRUE;
else AccAlign = FALSE;
if (ComplStr) {
/* Sequence complementaire */
MolSeqPtr = MolSeq_CplStrand(SeqData_MolSeq(SeqDataPtr),
SeqData_Alph(SeqDataPtr));
BestCplAlignPtr = PrfAlign_BestAlign(PrfData_PrfMatrix(
PrfDataPtr), SeqData_MolSeq(SeqDataPtr), &ErrIndex);
if (!BestCplAlignPtr) {
/* Erreur */
fprintf(stderr, "Best alignment algorithme error:\n");
Print_ErrStr(ErrTable_ErrStrNth(PA_ErrTable, ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
/* Retour a la sequence originelle */
MolSeqPtr = MolSeq_CplStrand(SeqData_MolSeq(SeqDataPtr),
SeqData_Alph(SeqDataPtr));
if (Align_Score(BestCplAlignPtr) >= CutOff) AccCplAlign = TRUE;
else AccCplAlign = FALSE;
}
else AccCplAlign = FALSE;
if ((!AccAlign) && (!AccCplAlign) && (!SelectAll)) {
/* Continue */
continue;
}
/*-----------------------------------------*/
/* Initialisation des donnees d'alignement */
/*-----------------------------------------*/
PrfAlignPtr = I_PrfAlign(SeqDataPtr, PrfDataPtr,
MolSeq_MolNbr(SeqData_MolSeq(SeqDataPtr)));
if (!PrfAlignPtr) {
/* Erreur d'allocation */
fprintf(stderr, "Alignment data contruction:\n");
fprintf(stderr, "Allocation error\n");
exit(1);
}
AlignListPtr = PrfAlign_AlignList(PrfAlignPtr);
/*-------------------------*/
/* Algorithme d'alignement */
/*-------------------------*/
if ((AccAlign) && (!Unique)) {
PrfAlignResPtr = PrfAlign_Align(PrfAlignPtr, CutOff, TestProt,
&ErrIndex);
if (!PrfAlignResPtr) {
/* Erreur */
fprintf(stderr, "Alignment algorithme error:\n");
Print_ErrStr(ErrTable_ErrStrNth(PA_ErrTable, ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
}
/*-------------------------*/
/* Sequence complementaire */
/*-------------------------*/
if ((AccCplAlign) && (!Unique)) {
/* Index du 1ere alignment compl. */
FirstCplAlign = AlignList_AlignNbr(AlignListPtr);
/* Conversion de la sequence */
MolSeqPtr = MolSeq_CplStrand(SeqData_MolSeq(SeqDataPtr),
SeqData_Alph(SeqDataPtr));
/* Alignement */
PrfAlignResPtr = PrfAlign_Align(PrfAlignPtr, CutOff, TestProt,
&ErrIndex);
if (!PrfAlignResPtr) {
/* Erreur */
fprintf(stderr, "Alignment algorithme error:\n");
Print_ErrStr(ErrTable_ErrStrNth(PA_ErrTable, ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
}
/*---------------------------------------*/
/* Affichage du resultat de l'alignement */
/*---------------------------------------*/
/*Print_AlignList(PrfAlign_AlignList(PrfAlignPtr));*/
/*----------------------------------*/
/* Stockage du nombre d'occurrences */
/*----------------------------------*/
HitNbr = AlignList_AlignNbr(AlignListPtr);
if ((Unique) && (AccAlign)) HitNbr++;
if ((Unique) && (AccCplAlign)) HitNbr++;
/*----------------------------------------------*/
/* Ajout des meilleurs alignments si necessaire */
/*----------------------------------------------*/
if (((SelectAll) && (!AccAlign)) || ((Unique) && (AccAlign))) {
if (AlignList_Full(AlignListPtr)) {
/* Liste d'alignement pleine */
fprintf(stderr, "Program error:\n");
Print_ErrStr("Alignments overflow");
fprintf(stderr, "\n");
exit(1);
}
/* Ajout */
AlignList_AddAlign(AlignListPtr, BestAlignPtr);
}
if (((SelectAll) && (!AccCplAlign) && (ComplStr)) ||
((Unique) && (AccCplAlign))) {
if (AlignList_Full(AlignListPtr)) {
/* Liste d'alignement pleine */
fprintf(stderr, "Program error:\n");
Print_ErrStr("Alignments flow");
fprintf(stderr, "\n");
exit(1);
}
/* Ajout */
AlignList_AddAlign(AlignListPtr, BestCplAlignPtr);
}
/* Affichage */
if ((ReportAlign) || (ReportCoord)) {
if (ComplStr) {
/* Retour a la sequence initiale */
MolSeqPtr = MolSeq_CplStrand(SeqData_MolSeq(SeqDataPtr),
SeqData_Alph(SeqDataPtr));
}
fprintf(OutPutFile, "\n");
Out_PrfId(OutPutFile, PrfData_Id(PrfDataPtr));
fprintf(OutPutFile, ", ");
Out_De45(OutPutFile, SeqData_De(SeqDataPtr));
fprintf(OutPutFile, ", Hits: ");
Out_AlignIndex(OutPutFile, HitNbr);
fprintf(OutPutFile,
"\n-------------------------------------------------------------------------------\n");
}
else {
Out_PrfId(OutPutFile, PrfData_Id(PrfDataPtr));
fprintf(OutPutFile, " ");
Out_De26(OutPutFile, SeqData_De(SeqDataPtr));
fprintf(OutPutFile, " ");
Out_AlignIndex(OutPutFile, HitNbr);
fprintf(OutPutFile, " ");
}
for (AlignIndex = 0; AlignIndex < AlignList_AlignNbr(AlignListPtr);
AlignIndex++) {
AlignPtr = AlignList_AlignNth(AlignListPtr, AlignIndex);
if ((ReportAlign) || (ReportCoord)) {
if ((AccCplAlign) && (AlignIndex == FirstCplAlign)) {
/* Retour a la sequence complementaire */
MolSeqPtr = MolSeq_CplStrand(SeqData_MolSeq(SeqDataPtr),
SeqData_Alph(SeqDataPtr));
}
fprintf(OutPutFile, "\nScore: ");
Out_Score(OutPutFile, Align_Score(AlignPtr));
fprintf(OutPutFile, " Position: ");
if ((ComplStr) && (AlignIndex >= FirstCplAlign)) {
Align_OutCplRange(OutPutFile, AlignPtr,
MolSeq_MolNbr(SeqData_MolSeq(SeqDataPtr)));
}
else {
Align_OutRange(OutPutFile, AlignPtr);
}
fprintf(OutPutFile, "\n");
/* Allocation de la matrice de chemins */
PathMatrixPtr = I_PathMatrix(Coord_PosIndex(
&Align_EndCoord(AlignPtr)) - Coord_PosIndex(
&Align_StartCoord(AlignPtr)) + 1, Coord_MolIndex(&
Align_EndCoord(AlignPtr)) - Coord_MolIndex(
&Align_StartCoord(AlignPtr)) + 1, &Align_StartCoord(
AlignPtr));
if (!PathMatrixPtr) {
/* Erreur d'allocation */
fprintf(stderr, "Path matrix allocation error\n");
exit(1);
}
/* Calcul de matrice de chemin */
if (Coord_PosIndex(&Align_InCoord(AlignPtr)) ==
PD_POS_IDX_NOT_DEF) {
Score = PathMatrix_BestCalc(PathMatrixPtr, AlignPtr,
PrfData_PrfMatrix(PrfDataPtr),
SeqData_MolSeq(SeqDataPtr));
}
else {
Score = PathMatrix_Calc(PathMatrixPtr, AlignPtr,
PrfData_PrfMatrix(PrfDataPtr),
SeqData_MolSeq(SeqDataPtr));
}
}
if (ReportAlign) {
/* Construction de la chaine d'alignement */
AliStrPtr = I_AliStr(PathMatrix_RowNbr(PathMatrixPtr) +
PathMatrix_ColumnNbr(PathMatrixPtr) - 1);
if (!AliStrPtr) {
/* Erreur d'allocation */
fprintf(stderr, "Alignment string allocation error\n");
exit(1);
}
/* Calcul de la chaine d'alignement */
TempAliStrPtr = AliStr_FromPathMatrix(AliStrPtr,
PathMatrixPtr, PrfData_PrfMatrix(PrfDataPtr), SeqDataPtr,
&ErrIndex);
if (!TempAliStrPtr) {
/* Erreur dans le calcul de la chaine d'alignement */
fprintf(stderr,
"Alignment string calculation error:\n");
Print_ErrStr(ErrTable_ErrStrNth(PA_ErrTable,
ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
/* Affichage de la chaine d'alignement */
fprintf(OutPutFile, "\n");
Out_AliStr(OutPutFile, AliStrPtr);
/* Destruction de la chaine d'alignement */
Free_AliStr(AliStrPtr);
/* Destruction de la matrice de chemin */
Free_PathMatrix(PathMatrixPtr);
}
else if (ReportCoord) {
/* Construction du vecteur de coordonnees */
CoordVectPtr = I_CoordVect(PathMatrix_RowNbr(PathMatrixPtr)
+ PathMatrix_ColumnNbr(PathMatrixPtr) - 1);
if (!CoordVectPtr) {
/* Erreur d'allocation */
fprintf(stderr, "Coordinates vector allocation error\n");
exit(1);
}
/* Calcul du vecteur de coordonnees */
TempCoordVectPtr = CoordVect_FromPathMatrix(
CoordVectPtr, PathMatrixPtr, &ErrIndex);
if (!TempCoordVectPtr) {
/* Erreur dans le calcul du vecteur de coord. */
fprintf(stderr,
"Coordinates vector calculation error:\n");
Print_ErrStr(ErrTable_ErrStrNth(PA_ErrTable, ErrIndex));
fprintf(stderr, "\n");
exit(1);
}
/* Affichage du vecteur de coordonnees */
Out_CoordVect(OutPutFile, CoordVectPtr);
/* Destruction du vecteur de coordonnees */
Free_CoordVect(CoordVectPtr);
}
else {
Out_Score(OutPutFile, Align_Score(AlignPtr));
fprintf(OutPutFile, " ");
if ((ComplStr) && (AlignIndex >= FirstCplAlign)) {
Align_OutCplRange(OutPutFile, AlignPtr,
MolSeq_MolNbr(SeqData_MolSeq(SeqDataPtr)));
}
else {
Align_OutRange(OutPutFile, AlignPtr);
}
fprintf(OutPutFile, "\n");
if (AlignIndex < AlignList_AlignNbr(AlignListPtr) - 1) {
fprintf(OutPutFile,
" ");
}
}
fflush(OutPutFile);
}
Free_PrfAlign(PrfAlignPtr);
Free_PrfData(PrfDataPtr);
Free_SeqData(SeqDataPtr);
if (PrfId) {
/* On ne test qu'un seul profil */
break;
}
}
Free_ReadPrfFile(ReadPrfFilePtr);
Free_SeqFileData(SeqFileDataPtr);
}
if (OutPutFile != stdout) {
fclose(OutPutFile);
}
exit(0);
}