Debian Codegraph @

NDist/NDist.c

raw symbols ◀ ▶ SCIP
2 Debian patches touch this file
1 /*
2 August 2012 Code has been optimised for speed by Tessella, funded by Unilever.
3 See comments in code for details of optimisation changes.
4 Output has been verified to be unaffected by these changes.
5 */
6
7 /**System includes****/
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <float.h>
12 #include <assert.h>
•13 #include <ctype.h>
14 #include <math.h>
15 #include <mpi.h>
16
17 #include "NDist.h"cxx . . $ `<file>/NDist/NDist.h`/
18
19 /*global constants*/
20 static char *usagecxx . . $ usage.[] = {"NDist - pairwise Needleman-Wunsch sequence distance matrix from a fasta file\n",
21 "-in string fata file name\n",
22 "Options:\n",
23 "-i output identifiers\n"};
24
25 static int nLinescxx . . $ nLines. = 4;
26
27 static char szSequencecxx . . $ szSequence.[] = "acgturynACGTURYN-";
28
29 void broadcastDatacxx . . $ broadcastData(4c549200977ca370).(t_Datacxx . . $ t_Data# *ptData)
30 {
31 int i = 0;
32
33 MPI_Bcastcxx . . $ MPI_Bcast(5696b3abcecc6bf7).((void *) &ptData->nSeqcxx . . $ s_Data#nSeq., 1, MPI_INTcxx . . $ `<external>/6934199238193867845/mpi.h:1237:9`!, 0, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
34
35 MPI_Bcastcxx . . $ MPI_Bcast(5696b3abcecc6bf7).((void *) &ptData->nMaxLencxx . . $ s_Data#nMaxLen., 1, MPI_INTcxx . . $ `<external>/6934199238193867845/mpi.h:1237:9`!, 0, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
36
37 MPI_Bcastcxx . . $ MPI_Bcast(5696b3abcecc6bf7).((void *) ptData->anLencxx . . $ s_Data#anLen., ptData->nSeqcxx . . $ s_Data#nSeq., MPI_INTcxx . . $ `<external>/6934199238193867845/mpi.h:1237:9`!, 0, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
38
39 for(i = 0; i < ptData->nMaxLencxx . . $ s_Data#nMaxLen.;i++){
40 MPI_Bcastcxx . . $ MPI_Bcast(5696b3abcecc6bf7).((void *) &ptData->acSequencescxx . . $ s_Data#acSequences.[i*ptData->nSeqcxx . . $ s_Data#nSeq.], ptData->nSeqcxx . . $ s_Data#nSeq., MPI_CHARcxx . . $ `<external>/6934199238193867845/mpi.h:1235:9`!, 0, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
41 }
42 }
43
44 void receiveDatacxx . . $ receiveData(4c549200977ca370).(t_Datacxx . . $ t_Data# *ptData)
45 {
46 int i = 0;
47 MPI_Bcastcxx . . $ MPI_Bcast(5696b3abcecc6bf7).((void *) &ptData->nSeqcxx . . $ s_Data#nSeq., 1, MPI_INTcxx . . $ `<external>/6934199238193867845/mpi.h:1237:9`!, 0, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
48
49 MPI_Bcastcxx . . $ MPI_Bcast(5696b3abcecc6bf7).((void *) &ptData->nMaxLencxx . . $ s_Data#nMaxLen., 1, MPI_INTcxx . . $ `<external>/6934199238193867845/mpi.h:1237:9`!, 0, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
50
51 ptData->anLencxx . . $ s_Data#anLen. = (int *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(ptData->nSeqcxx . . $ s_Data#nSeq.*sizeof(int));
52 if(!ptData->anLencxx . . $ s_Data#anLen.)
53 goto memoryError;
54
55 MPI_Bcastcxx . . $ MPI_Bcast(5696b3abcecc6bf7).((void *) ptData->anLencxx . . $ s_Data#anLen., ptData->nSeqcxx . . $ s_Data#nSeq., MPI_INTcxx . . $ `<external>/6934199238193867845/mpi.h:1237:9`!, 0, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
56
57 ptData->acSequencescxx . . $ s_Data#acSequences. = (char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(ptData->nSeqcxx . . $ s_Data#nSeq.*ptData->nMaxLencxx . . $ s_Data#nMaxLen.*sizeof(char));
58 if(!ptData->acSequencescxx . . $ s_Data#acSequences.)
59 goto memoryError;
60
61 for(i = 0; i < ptData->nMaxLencxx . . $ s_Data#nMaxLen.; i++){
62 MPI_Bcastcxx . . $ MPI_Bcast(5696b3abcecc6bf7).((void *) &ptData->acSequencescxx . . $ s_Data#acSequences.[i*ptData->nSeqcxx . . $ s_Data#nSeq.], ptData->nSeqcxx . . $ s_Data#nSeq., MPI_CHARcxx . . $ `<external>/6934199238193867845/mpi.h:1235:9`!, 0, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
63 }
64 return;
65 memoryError:
66 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed allocating memory in receiveData\n");
67 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
68 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
69 }
70
71
72 int maincxx . . $ main(afcd3168fc1188a4).(int argc, char* argv[]){
73 int a = 0, nN = 0, nM = 0;
74 unsigned long i = 0, j = 0;
75 t_Paramscxx . . $ t_Params# tParams;
76 t_Datacxx . . $ t_Data# tData;
77 double *adDists = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
78 int numtasks, rank, rc;
79 unsigned long ulNumTasks, ulOffset, ulA, ulA0, ulSize, ulCount, ulStart, ulFinish;
80 int nTag = 1;
81 unsigned long ulPackets = 0, ulPacketSize = 0, ulPacketCurr = 0;
82 double **aadFMatrix = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
83 int **aanMoves = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
84 MPI_Statuscxx . . $ MPI_Status# status;
85
86 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
87
88 rc = MPI_Initcxx . . $ MPI_Init(f0be292331509a4d).(&argc,&argv);
89 if (rc != MPI_SUCCESScxx . . $ `<external>/6934199238193867845/mpi.h:661:9`!) {
90 printfcxx . . $ printf(581fddd72a8db8fc). ("Error starting MPI program. Terminating.\n");
91 MPI_Abortcxx . . $ MPI_Abort(7034fd9ff3fb719).(MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!, rc);
92 }
93
94 MPI_Comm_sizecxx . . $ MPI_Comm_size(a06bd325f371412f).(MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!,&numtasks);
95 MPI_Comm_rankcxx . . $ MPI_Comm_rank(a06bd325f371412f).(MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!,&rank);
96
97 /*get command line params*/
98 getCommandLineParamscxx . . $ getCommandLineParams(e21a2e221db30366).(&tParams, argc, argv);
99
100 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
101
102 if(rank == 0){ /*head node reads data*/
103
104 //fprintf(stdout, "%d read data\n",rank); fflush(stdout);
105
106 readDatacxx . . $ readData(c6e12b0313806329).(&tData, &tParams);
107
108 //fprintf(stdout, "%d broadcast data\n",rank); fflush(stdout);
109
110 /*sends it out to other nodes*/
111 broadcastDatacxx . . $ broadcastData(4c549200977ca370).(&tData);
112
113 //fprintf(stdout, "%d start calculations\n",rank); fflush(stdout);
114
115 /*do my bit*/
116 nN = tData.nSeqcxx . . $ s_Data#nSeq.; nM = tData.nMaxLencxx . . $ s_Data#nMaxLen.;
117
118 /*allocate memory for whole dist matrix*/
119 ulSize = ((unsigned long) nN*( (unsigned long) nN - 1))/2;
120
121 ulNumTasks = (unsigned long) numtasks;
122 ulA = (unsigned long) (floor(ulSize / ulNumTasks));
123
124 ulA0 = ulA + (ulSize % ulNumTasks);
125
126 //fprintf(stderr, "%d allocate memory %lu %lu\n",rank, ulSize, ulA); fflush(stderr);
127
128 adDists = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(ulA*sizeof(double));
129 if(!adDists)
130 goto memoryError;
131
132 printfcxx . . $ printf(581fddd72a8db8fc).("%d\n",nN);
133 /*output identifiers here*/
134 if(tParams.bIdentcxx . . $ s_Params#bIdent. == TRUEcxx . . $ `NDist/NDist.h:38:9`!){
135 for(i = 0; i < tData.nSeqcxx . . $ s_Data#nSeq.; i++){
136 printfcxx . . $ printf(581fddd72a8db8fc).("%s\n", tData.aszIDcxx . . $ s_Data#aszID.[i]);
137 }
138 }
139
140 /* Start 1A August 2012
141 Speed optimisation 1: allocate memory here once for the whole set of comparisons
142 We use the max sequence length to size the matrix and rely on each run of the needlemanWunsch algorithm to
143 initialise the values in the sub-set of the matrix space it will use
144 The change is repeated in head and slave node sections */
145 aadFMatrix = (double **) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nM + 1)*sizeof(double *));
146 aanMoves = (int **) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nM + 1)*sizeof(int *));
147 if(!aadFMatrix || !aanMoves)
148 goto memoryError;
149 for(i = 0; i <= nM; i++){
150 aadFMatrix[i] = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nM + 1)*sizeof(double));
151 aanMoves[i] = (int *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nM + 1)*sizeof(int));
152 if(!aadFMatrix[i] || !aanMoves[i])
153 goto memoryError;
154
155 /* August 2012
156 Speed optimisation 3A: leave matrix empty initially except for edges*/
157 aadFMatrix[i][0] = GAP_PENALTYcxx . . $ `NDist/NDist.h:48:9`!*i;
158 aanMoves[i][0] = UPcxx . . $ `NDist/NDist.h:53:9`!;
159 /* Because this master matrix is square, we can initialise the edges in 1 pass */
160 aadFMatrix[0][i] = GAP_PENALTYcxx . . $ `NDist/NDist.h:48:9`!*i;
161 aanMoves[0][i] = LEFTcxx . . $ `NDist/NDist.h:52:9`!;
162 }
163 /* End 1A */
164
165 ulCount = 0;
166 for(i = 0; i < nN; i++){
167 for(j = 0; j < i; j++){
168 t_Aligncxx . . $ t_Align# tAlign;
169 double dDist = 0.0;
170
171 needlemanWunschcxx . . $ needlemanWunsch(e2a4651a76c49494).(&tAlign, &tData.acSequencescxx . . $ s_Data#acSequences.[i*nM], &tData.acSequencescxx . . $ s_Data#acSequences.[j*nM],
172 tData.anLencxx . . $ s_Data#anLen.[i], tData.anLencxx . . $ s_Data#anLen.[j], aadFMatrix, aanMoves);
173
174 dDist = tAlign.dDistcxx . . $ s_Align#dDist.;
175 printfcxx . . $ printf(581fddd72a8db8fc).("%.8e\n",dDist);
176
177 ulCount++;
178 if(ulCount == ulA0){
179 goto finish;
180 }
181 }
182 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
183 }
184
185 finish:
186 ulPackets = ((ulA - 1)/MAX_PACKET_SIZEcxx . . $ `NDist/NDist.h:55:9`!) + 1;
187
188 for (i = 1; i < numtasks; i++){
189
190 ulPacketCurr = 0;
191 for(j = 0; j < ulPackets; j++){
192
193 if(j < ulPackets - 1){
194 ulPacketSize = MAX_PACKET_SIZEcxx . . $ `NDist/NDist.h:55:9`!;
195 }
196 else{
197 ulPacketSize = ulA % MAX_PACKET_SIZEcxx . . $ `NDist/NDist.h:55:9`!;
198 }
199
200 MPI_Recvcxx . . $ MPI_Recv(feef67b9b3d9bd36).((void *) (&adDists[ulPacketCurr]), ulPacketSize,
201 MPI_DOUBLEcxx . . $ `<external>/6934199238193867845/mpi.h:1240:9`!, i, nTag, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!, &status);
202
203 ulPacketCurr += ulPacketSize;
204 }
205
206
207 for(j = 0; j < ulA; j++){
208 printfcxx . . $ printf(581fddd72a8db8fc).("%.8e\n",adDists[j]);
209 }
210 }
211
212 }
213 else{
214 /* receive data*/
215
216 //fprintf(stdout,"%d receive data\n",rank); fflush(stderr);
217
218 receiveDatacxx . . $ receiveData(4c549200977ca370).(&tData);
219
220 nN = tData.nSeqcxx . . $ s_Data#nSeq.; nM = tData.nMaxLencxx . . $ s_Data#nMaxLen.;
221
222 ulSize = ((unsigned long) nN*( (unsigned long) nN - 1))/2;
223 ulNumTasks = (unsigned long) numtasks;
224 ulA = (unsigned long) floor(ulSize / ulNumTasks);
225
226 ulA0 = ulA + (ulSize % ulNumTasks);
227
228 //fprintf(stdout,"%d allocate memory %lu %lu\n",rank, ulSize, ulA); fflush(stdout);
229 adDists = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(ulA*sizeof(double));
230 if(!adDists)
231 goto memoryError;
232
233 /* Start 1B August 2012
234 Speed optimisation 1: allocate memory here once for the whole set of comparisons
235 We use the max sequence length to size the matrix and rely on each run of the needlemanWunsch algorithm to
236 initialise the values in the sub-set of the matrix space it will use
237 The change is repeated in head and slave node sections */
238 aadFMatrix = (double **) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nM + 1)*sizeof(double *));
239 aanMoves = (int **) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nM + 1)*sizeof(int *));
240 if(!aadFMatrix || !aanMoves)
241 goto memoryError;
242 for(i = 0; i <= nM; i++){
243 aadFMatrix[i] = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nM + 1)*sizeof(double));
244 aanMoves[i] = (int *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nM + 1)*sizeof(int));
245 if(!aadFMatrix[i] || !aanMoves[i])
246 goto memoryError;
247
248 /* August 2012
249 Speed optimisation 3B: leave matrix empty initially except for edges*/
250 aadFMatrix[i][0] = GAP_PENALTYcxx . . $ `NDist/NDist.h:48:9`!*i;
251 aanMoves[i][0] = UPcxx . . $ `NDist/NDist.h:53:9`!;
252 /* Because this master matrix is square, we can initialise the edges in 1 pass */
253 aadFMatrix[0][i] = GAP_PENALTYcxx . . $ `NDist/NDist.h:48:9`!*i;
254 aanMoves[0][i] = LEFTcxx . . $ `NDist/NDist.h:52:9`!;
255 }
256 /* End 1B */
257
258 ulCount = 0; ulStart = ulA0 + (rank - 1)*ulA; ulFinish = ulA0 + rank*ulA;
259
260 //fprintf(stdout,"%d begin calculations\n",rank); fflush(stdout);
261 for(i = 0; i < nN; i++){
262 for(j = 0; j < i; j++){
263 t_Aligncxx . . $ t_Align# tAlign;
264 double dDist = 0.0;
265
266 if(ulCount >= ulStart){
267
268 needlemanWunschcxx . . $ needlemanWunsch(e2a4651a76c49494).(&tAlign, &tData.acSequencescxx . . $ s_Data#acSequences.[i*nM], &tData.acSequencescxx . . $ s_Data#acSequences.[j*nM],
269 tData.anLencxx . . $ s_Data#anLen.[i], tData.anLencxx . . $ s_Data#anLen.[j], aadFMatrix, aanMoves);
270 dDist = tAlign.dDistcxx . . $ s_Align#dDist.;
271
272 adDists[ulCount - ulStart] = dDist;
273 }
274
275 ulCount++;
276 if(ulCount == ulFinish){
277 goto finish2;
278 }
279
280 }
281 }
282
283 finish2:
284
285 ulPackets = ((ulA - 1)/MAX_PACKET_SIZEcxx . . $ `NDist/NDist.h:55:9`!) + 1;
286
287 ulPacketCurr = 0;
288 for(j = 0; j < ulPackets; j++){
289 if(j < ulPackets - 1){
290 ulPacketSize = MAX_PACKET_SIZEcxx . . $ `NDist/NDist.h:55:9`!;
291 }
292 else{
293 ulPacketSize = ulA % MAX_PACKET_SIZEcxx . . $ `NDist/NDist.h:55:9`!;
294 }
295
296 //printf("Send %d %d %d\n",rank, nPacketCurr, nPacketSize);
297 MPI_Sendcxx . . $ MPI_Send(496a97ba6af68f33).((void *) (&adDists[ulPacketCurr]), ulPacketSize,
298 MPI_DOUBLEcxx . . $ `<external>/6934199238193867845/mpi.h:1240:9`!, 0, nTag, MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
299 ulPacketCurr += ulPacketSize;
300 }
301
302 if(ulPacketCurr != ulA){
303 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Message error\n");
304 }
305 }
306
307 /* Start 1C August 2012
308 Speed optimisation 1: free allocated matrix*/
309 /*free allocated memory*/
310 freecxx . . $ free(5d22bdacc48458e8).(adDists);
311 freecxx . . $ free(5d22bdacc48458e8).(tData.acSequencescxx . . $ s_Data#acSequences.);
312 freecxx . . $ free(5d22bdacc48458e8).(tData.anLencxx . . $ s_Data#anLen.);
313 for(i = 0; i <= nM; i++){
314 freecxx . . $ free(5d22bdacc48458e8).(aadFMatrix[i]);
315 freecxx . . $ free(5d22bdacc48458e8).(aanMoves[i]);
316 }
317 freecxx . . $ free(5d22bdacc48458e8).(aadFMatrix);
318 freecxx . . $ free(5d22bdacc48458e8).(aanMoves);
319 /* End1C August 2012 */
320
321 // Wait for everyone to stop
322 MPI_Barriercxx . . $ MPI_Barrier(32bb3867d6d27899).(MPI_COMM_WORLDcxx . . $ `<external>/6934199238193867845/mpi.h:1209:9`!);
323
324 // Always use MPI_Finalize as the last instruction of the program
325
326 MPI_Finalizecxx . . $ MPI_Finalize(b126dc7c1de90089).();
327 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!);
328
329 memoryError:
330 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed allocating memory in main\n");
331 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
332 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
333 }
334
335 void writeUsagecxx . . $ writeUsage(8d4262d45fc644ab).(FILEcxx . . $ FILE#* ofp)
336 {
337 int i = 0;
338 char *line;
339
340 for(i = 0; i < nLinescxx . . $ nLines.; i++){
341 line = usagecxx . . $ usage.[i];
342 fputscxx . . $ fputs(874fa6a5e59ab9bd).(line,ofp);
343 }
344 }
345
346 char *extractParametercxx . . $ extractParameter(7ef250a81ca880e6).(int argc, char **argv, char *param,int when)
347 {
348 int i = 0;
349
350 while((i < argc) && (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(param,argv[i]))){
351 i++;
352 }
353
354 if(i < argc - 1){
355 return(argv[i + 1]);
356 }
357
358 if((i == argc - 1) && (when == OPTIONcxx . . $ `NDist/NDist.h:41:9`!)){
359 return "";
360 }
361
362 if(when == ALWAYScxx . . $ `NDist/NDist.h:42:9`!){
363 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!,"Can't find asked option %s\n",param);
364 }
365
366 return (char *) NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
367 }
368
369 void getCommandLineParamscxx . . $ getCommandLineParams(e21a2e221db30366).(t_Paramscxx . . $ t_Params# *ptParams,int argc,char *argv[])
370 {
371 char *szTemp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
372 char *cError = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
373
374 /*get parameter file name*/
375 ptParams->szInputFilecxx . . $ s_Params#szInputFile. = extractParametercxx . . $ extractParameter(7ef250a81ca880e6).(argc,argv, INPUT_FILEcxx . . $ `NDist/NDist.h:44:9`!,ALWAYScxx . . $ `NDist/NDist.h:42:9`!);
376 if(ptParams->szInputFilecxx . . $ s_Params#szInputFile. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
377 goto error;
378
379 /*identifiers*/
380 szTemp = extractParametercxx . . $ extractParameter(7ef250a81ca880e6).(argc, argv, IDENTcxx . . $ `NDist/NDist.h:45:9`!, OPTIONcxx . . $ `NDist/NDist.h:41:9`!);
381 if(szTemp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){
382 ptParams->bIdentcxx . . $ s_Params#bIdent. = TRUEcxx . . $ `NDist/NDist.h:38:9`!;
383 }
384 else{
385 ptParams->bIdentcxx . . $ s_Params#bIdent. = FALSEcxx . . $ `NDist/NDist.h:37:9`!;
386 }
387
388 szTemp = extractParametercxx . . $ extractParameter(7ef250a81ca880e6).(argc, argv, PHYLIPcxx . . $ `NDist/NDist.h:46:9`!, OPTIONcxx . . $ `NDist/NDist.h:41:9`!);
389 if(szTemp != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){
390 ptParams->bPhylipcxx . . $ s_Params#bPhylip. = TRUEcxx . . $ `NDist/NDist.h:38:9`!;
391 }
392 else{
393 ptParams->bPhylipcxx . . $ s_Params#bPhylip. = FALSEcxx . . $ `NDist/NDist.h:37:9`!;
394 }
395
396 return;
397
398 error:
399 writeUsagecxx . . $ writeUsage(8d4262d45fc644ab).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!);
400 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
401 }
402
403 /* August 2012
404 Speed optimisation 5B: inline loop functions */
405
406 double calcDistancecxx . . $ calcDistance(cb1b737e7e8abbef).(char* acA, char* acB, int nLen)
407 {
408 int gap_alert1 = 0, gap_alert2 = 0;
409 int start_seq1 = 0;
410 int start_seq2 = 0;
411 int end_seq1 = nLen;
412 int end_seq2 = nLen;
413 double residuecount = 0.0, distance = 0.0;
414 int k = 0;
415 int start_seq = 0, end_seq = 0;
416
417 /* get left side gaps */
418 k = 0;
419 while(acA[k] == GAPcxx . . $ `NDist/NDist.h:49:9`! && k < nLen) k++;
420 start_seq1 = k;
421
422 k = 0;
423 while(acB[k] == GAPcxx . . $ `NDist/NDist.h:49:9`! && k < nLen) k++;
424 start_seq2 = k;
425
426 /* get right side gaps */
427 k = nLen - 1;
428 while(acA[k] == GAPcxx . . $ `NDist/NDist.h:49:9`! && k >= 0) k--;
429 end_seq1 = k + 1; /* add one on for < not <= further on down */
430
431 k = nLen - 1;
432 while(acB[k] == GAPcxx . . $ `NDist/NDist.h:49:9`! && k >= 0) k--;
433 end_seq2 = k + 1;
434
435 start_seq = start_seq1;
436 if(start_seq < start_seq2){
437 start_seq = start_seq2;
438 }
439
440 end_seq = end_seq1;
441 if(end_seq > end_seq2){
442 end_seq = end_seq2;
443 }
444
445 gap_alert1 = 0;
446 gap_alert2 = 0;
447
448 if(end_seq - start_seq <= 0){
449 return 1.0;
450 }
451
452 for(k = start_seq; k < end_seq; k++){
453
454 if (acA[k] == GAPcxx . . $ `NDist/NDist.h:49:9`! && acB[k] == GAPcxx . . $ `NDist/NDist.h:49:9`!){
455 continue;
456 }
457
458 if(acA[k] == GAPcxx . . $ `NDist/NDist.h:49:9`!){
459 if(gap_alert1 == 0){
460 residuecount+=1.0;
461 distance+=1.0;
462 }
463 gap_alert1 = 1;
464 gap_alert2 = 0;
465
466 continue;
467 }
468
469 if(acB[k] == GAPcxx . . $ `NDist/NDist.h:49:9`!){
470 if(gap_alert2 == 0){
471 residuecount+=1.0;
472 distance+=1.0;
473 }
474 gap_alert1 = 0;
475 gap_alert2 = 1;
476
477 continue;
478 }
479
480 /* ok no gaps , check for mismatch */
481 if(acA[k] != 'N' && acB[k] != 'N'){
482
483 if (acA[k] != acB[k]){
484 distance += 1.0;
485 residuecount+=1.0;
486 gap_alert1 = 0;
487 gap_alert2 = 0;
488
489 continue;
490 }
491
492 if(acA[k] == acB[k]){
493 residuecount+= 1.0;
494 gap_alert1 = 0;
495 gap_alert2 = 0;
496
497 continue;
498 }
499 }
500 else{
501 residuecount+= 1.0;
502
503 gap_alert1 = 0;
504 gap_alert2 = 0;
505
506 continue;
507 }
508
509 printfcxx . . $ printf(581fddd72a8db8fc).("FELL THROUGH \n");
510 }
511
512 if (residuecount > 0) {
513 distance = distance / residuecount;
514 }
515 else {
516 distance = 1.0;
517 }
518
519 return distance;
520 }
521
522 void needlemanWunschcxx . . $ needlemanWunsch(e2a4651a76c49494).(t_Aligncxx . . $ t_Align# *ptAlign, const char* acA, const char* acB, int nLenA, int nLenB, double** aadFMatrix, int** aanMoves)
523 {
524 char *acAlignA = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *acAlignB = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
525 int nCount = 0;
526 int i = 0, j = 0;
527
528 /* August 2012
529 Speed optimisation 2: don't initialise the whole matrix space: once the top and left edge values have
530 been initialised the algorithm always refers to values that have just been set */
531
532 /* August 2012
533 Speed optimisation 3C: don't re-initialise the matrix edges as they dont change*/
534
535
536 /* August 2012
537 Speed optimisation 5A: streamline loop code */
538 double dChoice1, dChoice2, dChoice3, dPenaltyi, dPenaltyj;
539 for(i = 1; i <= nLenA; i++){
540 dPenaltyi = i != nLenA ? GAP_PENALTYcxx . . $ `NDist/NDist.h:48:9`! : 0;
541
542 for(j = 1; j <= nLenB; j++){
543 dPenaltyj = j != nLenB ? GAP_PENALTYcxx . . $ `NDist/NDist.h:48:9`! : 0;
544
545 dChoice1 = aadFMatrix[i-1][j-1] + distcxx . . $ `NDist/NDist.h:69:9`!(acA[i - 1], acB[j - 1]);
546 dChoice2 = aadFMatrix[i][j-1] + dPenaltyi;
547 dChoice3 = aadFMatrix[i-1][j] + dPenaltyj;
548
549 aanMoves[i][j] = getMovecxx . . $ `NDist/NDist.h:73:9`!(dChoice1, dChoice2, dChoice3);
550 aadFMatrix[i][j] = dmin3cxx . . $ `NDist/NDist.h:77:9`!(dChoice1, dChoice2, dChoice3);
551 }
552 }
553
554 ptAlign->dDistcxx . . $ s_Align#dDist. = aadFMatrix[nLenA][nLenB];
555
556 acAlignA = (char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nLenA + nLenB)*sizeof(char));
557 if(!acAlignA)
558 goto memoryError;
559
560 acAlignB = (char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).((nLenA + nLenB)*sizeof(char));
561 if(!acAlignB)
562 goto memoryError;
563
564 for(i = 0; i < nLenA + nLenB; i++){
565 acAlignA[i] = GAPcxx . . $ `NDist/NDist.h:49:9`!; acAlignB[i] = GAPcxx . . $ `NDist/NDist.h:49:9`!;
566 }
567
568 nCount = 0;
569 i = nLenA; j = nLenB;
570 while(i > 0 && j > 0){
571
572 switch(aanMoves[i][j]){
573 case DIAGcxx . . $ `NDist/NDist.h:51:9`!:
574
575 acAlignA[nCount] = acA[i - 1];
576 acAlignB[nCount] = acB[j - 1];
577
578 i--;
579 j--;
580 break;
581 case UPcxx . . $ `NDist/NDist.h:53:9`!:
582 acAlignA[nCount] = acA[i - 1];
583 acAlignB[nCount] = GAPcxx . . $ `NDist/NDist.h:49:9`!;
584
585 i--;
586 break;
587 case LEFTcxx . . $ `NDist/NDist.h:52:9`!:
588 acAlignA[nCount] = GAPcxx . . $ `NDist/NDist.h:49:9`!;
589 acAlignB[nCount] = acB[j - 1];
590
591 j--;
592 break;
593 }
594
595 nCount++;
596 }
597
598 while(i > 0){
599 acAlignA[nCount] = acA[i - 1];
600 acAlignB[nCount] = GAPcxx . . $ `NDist/NDist.h:49:9`!;
601 i--;
602 nCount++;
603 }
604
605 while(j > 0){
606 acAlignA[nCount] = GAPcxx . . $ `NDist/NDist.h:49:9`!;
607 acAlignB[nCount] = acB[j - 1];
608 j--;
609 nCount++;
610 }
611
612 ptAlign->nLencxx . . $ s_Align#nLen. = nCount;
613
614 //for(i = 0; i < ptAlign->nLen; i++){
615 //fprintf(stderr,"%c %c\n",acAlignA[i],acAlignB[i]);
616 //}
617 //fprintf(stderr,"\n\n");
618 ptAlign->dDistcxx . . $ s_Align#dDist. = calcDistancecxx . . $ calcDistance(cb1b737e7e8abbef).(acAlignA, acAlignB, ptAlign->nLencxx . . $ s_Align#nLen.);
619
620
621 freecxx . . $ free(5d22bdacc48458e8).(acAlignA);
622 freecxx . . $ free(5d22bdacc48458e8).(acAlignB);
623 return;
624
625 memoryError:
626 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to allocate memory in needlemanWunsch\n");
627 fflushcxx . . $ fflush(89bc1efcdac0ca22).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!);
628 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
629 }
630
631 static char szNoisycxx . . $ szNoisy.[] = "N";
632
633 void readDatacxx . . $ readData(c6e12b0313806329).(t_Datacxx . . $ t_Data# *ptData, t_Paramscxx . . $ t_Params# *ptParams)
634 {
635 FILEcxx . . $ FILE# *ifp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
636 char szLine[MAX_LINE_LENGTHcxx . . $ `NDist/NDist.h:34:9`!];
637 int nPos = 0, i = 0, j = 0, nM = 0, nSequences = 0;
638 char *szBrk;
639 char *szRet;
640
641 /*first count sequences and get length*/
642 ptData->nSeqcxx . . $ s_Data#nSeq. = 0;
643 ptData->nMaxLencxx . . $ s_Data#nMaxLen. = 0;
644
645 ifp = fopencxx . . $ fopen(82ec0787cd37e0a3).(ptParams->szInputFilecxx . . $ s_Params#szInputFile., "r");
646
647 if(ifp){
648 while(fgetscxx . . $ fgets(efb0aaba7ac866ae).(szLine, MAX_LINE_LENGTHcxx . . $ `NDist/NDist.h:34:9`!, ifp)){
649 if(szLine[0] == '>'){
650 if(nPos > ptData->nMaxLencxx . . $ s_Data#nMaxLen.){
651 ptData->nMaxLencxx . . $ s_Data#nMaxLen. = nPos;
652 }
653
654 ptData->nSeqcxx . . $ s_Data#nSeq.++;
655 nPos = 0;
656 }
657 else{
•658 //If there is no > on first line we're heading for a segfault.
659 if(! ptData->nSeqcxx . . $ s_Data#nSeq.)
660 {
661 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "File %s does not appear to be in FASTA format.\n", ptParams->szInputFilecxx . . $ s_Params#szInputFile.);
662 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
663 }
664
665 i = 0;
666 while(strrchrcxx . . $ strrchr(2050848944e00d54).(szSequencecxx . . $ szSequence.,szLine[i]) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){
667 i++;
668 nPos++;
669 }
670 }
671 }
•672 //Maybe the final sequence was the longest?
673 if(nPos > ptData->nMaxLencxx . . $ s_Data#nMaxLen.){
674 ptData->nMaxLencxx . . $ s_Data#nMaxLen. = nPos;
675 }
676
677 fclosecxx . . $ fclose(89bc1efcdac0ca22).(ifp);
678 }
679 else{
680 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Can't open input file %s\n", ptParams->szInputFilecxx . . $ s_Params#szInputFile.);
681 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
682 }
683
684 ptData->aszIDcxx . . $ s_Data#aszID. = (char **) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(ptData->nSeqcxx . . $ s_Data#nSeq.*sizeof(char *));
685
686 nM = ptData->nMaxLencxx . . $ s_Data#nMaxLen.;
687 ptData->acSequencescxx . . $ s_Data#acSequences. = (char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(ptData->nSeqcxx . . $ s_Data#nSeq.*nM*sizeof(char));
688 ptData->anLencxx . . $ s_Data#anLen. = (int *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(ptData->nSeqcxx . . $ s_Data#nSeq.*sizeof(int));
689
690 ifp = fopencxx . . $ fopen(82ec0787cd37e0a3).(ptParams->szInputFilecxx . . $ s_Params#szInputFile., "r");
691
692 if(ifp){
693 while(szRet = fgetscxx . . $ fgets(efb0aaba7ac866ae).(szLine, MAX_LINE_LENGTHcxx . . $ `NDist/NDist.h:34:9`!, ifp)){
694 if(szLine[0] == '>'){
695 if(nSequences > 0){
696 ptData->anLencxx . . $ s_Data#anLen.[nSequences - 1] = nPos;
697 }
698
699 szBrk = strpbrkcxx . . $ strpbrk(a713fe7b9a57cf96).(szLine, " \n");
700 (*szBrk) = '\0';
701 ptData->aszIDcxx . . $ s_Data#aszID.[nSequences] = strdupcxx . . $ strdup(a8b8e32347182212).(szLine + 1);
702 nPos = 0;
703 nSequences++;
704 }
705
706 i = 0;
707 while(szLine[i] != '\0' && strrchrcxx . . $ strrchr(2050848944e00d54).(szSequencecxx . . $ szSequence.,szLine[i]) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){
708 ptData->acSequencescxx . . $ s_Data#acSequences.[(nSequences - 1)*nM + nPos] = touppercxx . . $ `<external>/17904084882347303253/ctype.h:221:11`!(szLine[i]);
709
710 nPos++; i++;
711 }
712 }
713
714 ptData->anLencxx . . $ s_Data#anLen.[nSequences - 1] = nPos;
715
716 fclosecxx . . $ fclose(89bc1efcdac0ca22).(ifp);
717 }
718 else{
719 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Can't open input file %s\n", ptParams->szInputFilecxx . . $ s_Params#szInputFile.);
720 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!);
721 }
722 }