1 #ifdef _cplusplus
2 extern "C" {
3 #endif
4 #include "hitlist.h"
5
6 /* Function: sort_HitList_by_score(hl)
7 *
8 * Descrip: Sorts by score
9 *
10 *
11 * Arg: hl [UNKN ] Undocumented argument [HitList *]
12 *
13 */
14 # line 59 "hitlist.dy"
sort_HitList_by_score(HitList * hl)15 void sort_HitList_by_score(HitList * hl)
16 {
17 sort_HitList(hl,compare_HitPair_score);
18 }
19
20
21 /* Function: compare_HitPair_score(one,two)
22 *
23 * Descrip: internal function to sort by score
24 *
25 *
26 * Arg: one [UNKN ] Undocumented argument [HitPair *]
27 * Arg: two [UNKN ] Undocumented argument [HitPair *]
28 *
29 * Return [UNKN ] Undocumented return value [int]
30 *
31 */
32 # line 68 "hitlist.dy"
compare_HitPair_score(HitPair * one,HitPair * two)33 int compare_HitPair_score(HitPair * one,HitPair * two)
34 {
35 return two->raw_score - one->raw_score;
36 }
37
38
39 /* Function: apply_SearchStat_to_HitList(hspm,ssi,database_size)
40 *
41 * Descrip: Applies statistics across a hitlist
42 *
43 *
44 * Arg: hspm [UNKN ] Undocumented argument [HitList *]
45 * Arg: ssi [UNKN ] Undocumented argument [SearchStatInterface *]
46 * Arg: database_size [UNKN ] Undocumented argument [int]
47 *
48 */
49 # line 77 "hitlist.dy"
apply_SearchStat_to_HitList(HitList * hspm,SearchStatInterface * ssi,int database_size)50 void apply_SearchStat_to_HitList(HitList * hspm,SearchStatInterface * ssi,int database_size)
51 {
52 int i;
53 int j;
54
55 hspm->stat_attrib = stringalloc((*ssi->attribution)(ssi->data));
56
57 for(i=0;i<hspm->len;i++) {
58 hspm->pair[i]->bit_score = (*ssi->calc_bits)(ssi->data,hspm->pair[i]->query->len,hspm->pair[i]->target->len,hspm->pair[i]->raw_score);
59 hspm->pair[i]->evalue = (*ssi->calc_evalue)(ssi->data,hspm->pair[i]->query,hspm->pair[i]->target,hspm->pair[i]->raw_score,database_size);
60
61 for(j=0;j<hspm->pair[i]->len;j++ ) {
62 hspm->pair[i]->aln[j]->bit_score = (*ssi->calc_bits)(ssi->data,hspm->pair[i]->query->len,hspm->pair[i]->target->len,hspm->pair[i]->aln[j]->raw_score);
63 hspm->pair[i]->aln[j]->evalue = (*ssi->calc_evalue)(ssi->data,hspm->pair[i]->query,hspm->pair[i]->target,hspm->pair[i]->aln[j]->raw_score,database_size);
64 }
65 }
66
67 }
68
69
70 /* Function: HitList_from_LinearHSPmanager(lm)
71 *
72 * Descrip: Converts a LinearHSPmanager into a HitList
73 *
74 *
75 * Arg: lm [UNKN ] Undocumented argument [LinearHSPmanager *]
76 *
77 * Return [UNKN ] Undocumented return value [HitList *]
78 *
79 */
80 # line 100 "hitlist.dy"
HitList_from_LinearHSPmanager(LinearHSPmanager * lm)81 HitList * HitList_from_LinearHSPmanager(LinearHSPmanager * lm)
82 {
83 HitList * out;
84 HitPair * pair;
85 int i;
86
87
88 out = HitList_alloc_std();
89 if( lm->mat != NULL )
90 out->mat = hard_link_CompMat(lm->mat);
91
92 for(i=0;i<lm->len;i++) {
93 pair = HitPair_from_HSPset(lm->set[i],lm->mat);
94 add_HitList(out,pair);
95 }
96
97 return out;
98 }
99
100
101
102 /* Function: HitPair_from_HSPset(set,mat)
103 *
104 * Descrip: Builds a Hitpair from an HSP, not doing
105 * alignment
106 *
107 *
108 * Arg: set [UNKN ] Undocumented argument [HSPset *]
109 * Arg: mat [UNKN ] Undocumented argument [CompMat *]
110 *
111 * Return [UNKN ] Undocumented return value [HitPair *]
112 *
113 */
114 # line 125 "hitlist.dy"
HitPair_from_HSPset(HSPset * set,CompMat * mat)115 HitPair * HitPair_from_HSPset(HSPset * set,CompMat * mat)
116 {
117 HitPair * out;
118 HitAln * aln;
119 int i;
120
121 out = HitPair_alloc_std();
122 out->query = hard_link_Sequence(set->hsp[0]->query);
123 out->target = hard_link_Sequence(set->hsp[0]->target);
124
125 out->raw_score = 0.0;
126
127 for(i=0;i<set->len;i++) {
128 aln = HitAln_alloc();
129 aln->raw_score = set->hsp[i]->score;
130 aln->bit_score = aln->raw_score/2.0;
131
132
133 aln->alb = ungapped_AlnBlock_from_HSP(set->hsp[i],out->query,out->target,mat);
134 add_HitPair(out,aln);
135 out->raw_score += set->hsp[i]->score;
136 }
137
138
139 return out;
140 }
141
142 /* Function: ungapped_AlnBlock_from_HSP(hsp,q,t,mat)
143 *
144 * Descrip: Builds an expanded AlnBlock with one AlnColumn
145 * per residue for an ungapped HSP
146 *
147 *
148 * Arg: hsp [UNKN ] Undocumented argument [HSP *]
149 * Arg: q [UNKN ] Undocumented argument [Sequence *]
150 * Arg: t [UNKN ] Undocumented argument [Sequence *]
151 * Arg: mat [UNKN ] Undocumented argument [CompMat *]
152 *
153 * Return [UNKN ] Undocumented return value [AlnBlock *]
154 *
155 */
156 # line 156 "hitlist.dy"
ungapped_AlnBlock_from_HSP(HSP * hsp,Sequence * q,Sequence * t,CompMat * mat)157 AlnBlock * ungapped_AlnBlock_from_HSP(HSP * hsp,Sequence * q,Sequence * t,CompMat * mat)
158 {
159 AlnBlock * alb;
160 AlnColumn * alc;
161 AlnColumn * prev = NULL;
162 int i;
163
164 alb = AlnBlock_alloc_len(2);
165
166 add_AlnBlock(alb,AlnSequence_alloc());
167 add_AlnBlock(alb,AlnSequence_alloc());
168
169 for(i=0;i<hsp->length && hsp->query_start+i < q->len && hsp->target_start+i < t->len;i++) {
170 alc = new_pairwise_AlnColumn();
171
172 alc->alu[0]->start = hsp->query_start+i-1;
173 alc->alu[0]->end = hsp->query_start+i;
174 alc->alu[0]->text_label = "SEQUENCE";
175
176 alc->alu[1]->start = hsp->target_start+i-1;
177 alc->alu[1]->end = hsp->target_start+i;
178 alc->alu[1]->text_label = "SEQUENCE";
179
180 if( mat != NULL ) {
181 alc->alu[0]->score[0] = alc->alu[1]->score[0] = mat->comp[toupper(q->seq[hsp->query_start+i])-'A'][toupper(t->seq[hsp->target_start+i])-'A'];
182 }
183
184
185 if( prev == NULL ) {
186 alb->start = alc;
187 prev = alc;
188 } else {
189 prev->next = alc;
190 prev = alc;
191 }
192 }
193
194 return alb;
195 }
196
197 /* Function: new_HitListOutputImpl_from_argv(argc,argv)
198 *
199 * Descrip: Builds a new HitListOutputFormat from commandline
200 *
201 *
202 * Arg: argc [UNKN ] Undocumented argument [int *]
203 * Arg: argv [UNKN ] Undocumented argument [char **]
204 *
205 * Return [UNKN ] Undocumented return value [HitListOutputImpl *]
206 *
207 */
208 # line 199 "hitlist.dy"
new_HitListOutputImpl_from_argv(int * argc,char ** argv)209 HitListOutputImpl * new_HitListOutputImpl_from_argv(int * argc,char ** argv)
210 {
211 HitListOutputImpl * out;
212 char * temp;
213
214 out = HitListOutputImpl_alloc();
215
216 if( strip_out_boolean_argument(argc,argv,"hithelp") == TRUE ) {
217 fprintf(stdout,"Hitlist help\npseudoblast gives a format similar to BLAST output\nTab gives a tab delimited format one line foreach ungapped block with columns\n<bit_score> <query-id> <query-start> <query-end> <query-strand> <query-len> <target-id> <target_start> <target_end> <target_strand> <target-len> <alignment-group-id>\n");
218 fprintf(stdout,"aln gives cumlative score align label dumping, good for debugging\n");
219 exit(0);
220 }
221
222 if( (temp = strip_out_assigned_argument(argc,argv,"hitoutput")) != NULL ) {
223 if( strcmp(temp,"pseudoblast") == 0 ) {
224 out->type = HitListOutputFormatPseudoBlast;
225 }
226 if( strcmp(temp,"xml") == 0 ) {
227 out->type = HitListOutputFormatXML;
228 }
229 if( strcmp(temp,"aln") == 0 ) {
230 out->type = HitListAlnCumlative;
231 }
232 if( strcmp(temp,"tab") == 0 ) {
233 out->type = HitListOutputFormatTab;
234 }
235 }
236 return out;
237 }
238
239 /* Function: show_help_HitListOutputImpl(ofp)
240 *
241 * Descrip: Shows help for HitList output
242 *
243 *
244 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
245 *
246 */
247 # line 232 "hitlist.dy"
show_help_HitListOutputImpl(FILE * ofp)248 void show_help_HitListOutputImpl(FILE * ofp)
249 {
250 fprintf(ofp,"Hit list output options\n");
251 fprintf(ofp," -hitoutput [pseudoblast/xml/tab] pseudoblast by default\n");
252 fprintf(ofp," -hithelp more detailed help on hitlist formats\n");
253 }
254
255
256 /* Function: show_HitList_HitListOutputImpl(hloi,hl,ofp)
257 *
258 * Descrip: Shows a hitlist wrt to output impl
259 *
260 *
261 * Arg: hloi [UNKN ] Undocumented argument [HitListOutputImpl *]
262 * Arg: hl [UNKN ] Undocumented argument [HitList *]
263 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
264 *
265 */
266 # line 243 "hitlist.dy"
show_HitList_HitListOutputImpl(HitListOutputImpl * hloi,HitList * hl,FILE * ofp)267 void show_HitList_HitListOutputImpl(HitListOutputImpl * hloi,HitList * hl,FILE * ofp)
268 {
269 switch(hloi->type) {
270
271 case HitListOutputFormatPseudoBlast :
272 write_pseudoblast_HitList(hl,ofp);
273 break;
274 case HitListOutputFormatXML :
275 write_XML_HitList(hl,ofp);
276 break;
277 case HitListOutputFormatTab :
278 write_tab_HitList(hl,ofp);
279 break;
280 case HitListAlnCumlative :
281 write_alb_HitList(hl,ofp);
282 break;
283 default :
284 error("No valid HitListOutputFormat!");
285 }
286
287 }
288
289 /* Function: write_alb_HitList(hl,ofp)
290 *
291 * Descrip: Writes Alb output
292 *
293 *
294 * Arg: hl [UNKN ] Undocumented argument [HitList *]
295 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
296 *
297 */
298 # line 268 "hitlist.dy"
write_alb_HitList(HitList * hl,FILE * ofp)299 void write_alb_HitList(HitList * hl,FILE * ofp)
300 {
301 int i,j;
302 for(i=0;i<hl->len;i++) {
303 fprintf(stdout,"%s %s\n",hl->pair[i]->query->name,hl->pair[i]->target->name);
304
305 for(j=0;j<hl->pair[i]->len;j++) {
306 fprintf(ofp,"Alignment %d\n",j);
307 if( hl->pair[i]->aln[j]->alb != NULL )
308 mapped_ascii_AlnBlock(hl->pair[i]->aln[j]->alb,Score2Bits,1,ofp);
309 }
310 }
311 }
312
313
314 /* Function: write_XML_HitList(hl,ofp)
315 *
316 * Descrip: Writes XML output
317 *
318 *
319 * Arg: hl [UNKN ] Undocumented argument [HitList *]
320 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
321 *
322 */
323 # line 286 "hitlist.dy"
write_XML_HitList(HitList * hl,FILE * ofp)324 void write_XML_HitList(HitList * hl,FILE * ofp)
325 {
326 int i,j;
327 btCanvas * btc;
328
329
330 fprintf(ofp,"<?xml version=\"1.0\"?>\n");
331 fprintf(ofp,"<!DOCTYPE SequenceHitList PUBLIC \"-//EBI//SequenceHitList\" \"SequenceHitList.dtd\">\n");
332 fprintf(ofp,"<sequencehitlist>\n");
333 for(i=0;i<hl->len;i++) {
334 fprintf(ofp," <sequencehit>\n");
335 fprintf(ofp," <hitrank>%d</hitrank>\n",i);
336 fprintf(ofp," <sequence>\n");
337 fprintf(ofp," <id>%s</id>\n",hl->pair[i]->target->name);
338 if( hl->pair[i]->target->desc != NULL ) {
339 fprintf(ofp," <desc>%s</desc>\n",hl->pair[i]->target->desc);
340 }
341 fprintf(ofp," <residues>%s</residues>\n",hl->pair[i]->target->seq);
342 fprintf(ofp," </sequence>\n");
343 fprintf(ofp," <similaritymeasure>\n");
344 fprintf(ofp," <raw_score>%d</raw_score>\n",hl->pair[i]->raw_score);
345 fprintf(ofp," <bits_score>%.2f</bits_score>\n",hl->pair[i]->bit_score);
346 fprintf(ofp," <evalue>%g</evalue>\n",hl->pair[i]->evalue);
347 fprintf(ofp," </similaritymeasure>\n");
348 for(j=0;j<hl->pair[i]->len;j++) {
349 auto HitAln * haln = hl->pair[i]->aln[j];
350
351 fprintf(ofp," <hitalignment>\n");
352 fprintf(ofp," <similaritymeasure>\n");
353 fprintf(ofp," <raw_score>%d</raw_score>\n",haln->raw_score);
354 fprintf(ofp," <bits_score>%.2f</bits_score>\n",haln->bit_score);
355 fprintf(ofp," <evalue>%g</evalue>\n",haln->evalue);
356 fprintf(ofp," </similaritymeasure>\n");
357 fprintf(ofp," <formatted_alignment>\n");
358
359 btc = new_Ascii_btCanvas(stdout,20,50,7,3);
360 write_pretty_str_blast_align_btc(hl->pair[i]->aln[j]->alb,"Query:",hl->pair[i]->query->seq,"Sbjct:",hl->pair[i]->target->seq,btc);
361 free_btCanvas(btc);
362 fprintf(ofp,"\n");
363
364 fprintf(ofp," </formatted_alignment>\n");
365 fprintf(ofp," </hitalignment>\n");
366 }
367 fprintf(ofp,"</sequencehit>\n");
368 }
369 fprintf(ofp,"</sequencehitlist>\n");
370
371 }
372
373 /* Function: write_tab_HitList(hl,ofp)
374 *
375 * Descrip: Writes tab delimited tab like output
376 *
377 *
378 * Arg: hl [UNKN ] Undocumented argument [HitList *]
379 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
380 *
381 */
382 # line 338 "hitlist.dy"
write_tab_HitList(HitList * hl,FILE * ofp)383 void write_tab_HitList(HitList * hl,FILE * ofp)
384 {
385 int i;
386 int j;
387 AlnColumn * alc;
388 int qstart;
389 int qend = 0;
390 int tstart;
391 int tend = 0;
392 int strand;
393 int tempt;
394
395 for(i=0;i<hl->len;i++) {
396 for(j=0;j<hl->pair[i]->len;j++) {
397 for(alc = hl->pair[i]->aln[j]->alb->start;alc != NULL && strcmp(alc->alu[1]->text_label,"END") != 0 ;) {
398 /* start of a block - remember start coordinates */
399 qstart = alc->alu[0]->start+1+1;
400 tstart = alc->alu[1]->start+1+1;
401 /* progress any number of cases where the progression is the same */
402 for(;alc != NULL;alc = alc->next ) {
403 if( (alc->alu[0]->end - alc->alu[0]->start) != (alc->alu[1]->end - alc->alu[1]->start) ) {
404 break;
405 }
406 /* otherwise set end points */
407
408 qend = alc->alu[0]->end+1;
409 tend = alc->alu[1]->end+1;
410 }
411
412 if( hl->pair[i]->target_reversed == 1 ) {
413 strand = -1;
414 tempt = tstart;
415 tstart = hl->pair[i]->target->len - tend+1;
416 tend = hl->pair[i]->target->len - tempt+1;
417 } else {
418 strand = 1;
419 }
420
421 /* end of a block. Print line */
422 fprintf(ofp,"%.2f\t%s\t%d\t%d\t%d\t%d\t%s\t%d\t%d\t%d\t%d\tgroup_%d_%d\n",hl->pair[i]->bit_score,hl->pair[i]->query->name,qstart,qend,1,hl->pair[i]->query->len,hl->pair[i]->target->name,tstart,tend,strand,hl->pair[i]->target->len,i,j);
423
424 /* find start of next block */
425 for(;alc != NULL && strcmp(alc->alu[1]->text_label,"END") != 0;alc = alc->next ) {
426 if( alc->alu[0]->end - alc->alu[0]->start == alc->alu[1]->end - alc->alu[1]->start ) {
427 break;
428 }
429 }
430 /* top loop will break at alc == NULL */
431 }
432 }
433 }
434
435 }
436
437
438 /* Function: write_pseudoblast_HitList(hl,ofp)
439 *
440 * Descrip: Writes pseudoblast output
441 *
442 *
443 * Arg: hl [UNKN ] Undocumented argument [HitList *]
444 * Arg: ofp [UNKN ] Undocumented argument [FILE *]
445 *
446 */
447 # line 396 "hitlist.dy"
write_pseudoblast_HitList(HitList * hl,FILE * ofp)448 void write_pseudoblast_HitList(HitList * hl,FILE * ofp)
449 {
450 int i,j;
451 btCanvas * btc;
452 char buffer[MAXLINE];
453
454 fprintf(ofp,"BLASTP 2.1.2\n");
455 fprintf(ofp,"\n\nReference: Wise2 Package, Ewan Birney\n");
456 fprintf(ofp,"BLAST like format to play well with existing parsers. Other options are available\nSee help on the program that generated this for other options\n");
457 if( hl->stat_attrib != NULL ) {
458 fprintf(ofp," Statistics from : %s\n",hl->stat_attrib);
459 }
460
461 fprintf(ofp,"\n\n");
462 fprintf(ofp,"Query= Not specified\n");
463 fprintf(ofp,"\n\nSearch.................................done\n\n");
464 fprintf(ofp," Score E\n");
465 fprintf(ofp,"Sequences producing significant alignments: (bits) Value\n");
466
467 for(i=0;i<hl->len;i++) {
468 if( hl->pair[i]->target->desc != NULL ) {
469 strcpy(buffer,hl->pair[i]->target->desc);
470 } else {
471 strcpy(buffer," ");
472 }
473
474 buffer[50] = '\0';
475 fprintf(ofp,"%15s %50s %-.2f %.2g\n",hl->pair[i]->target->name,buffer,hl->pair[i]->bit_score,hl->pair[i]->evalue);
476 }
477
478 fprintf(ofp,"\n");
479
480 for(i=0;i<hl->len;i++) {
481 fprintf(ofp,">%s %s\n Length = %d Reversed %d\n\n",hl->pair[i]->target->name,(hl->pair[i]->target->desc != NULL ? hl->pair[i]->target->desc : " "),hl->pair[i]->target->len,hl->pair[i]->target_reversed);
482 for(j=0;j<hl->pair[i]->len;j++) {
483
484 fprintf(ofp," Score = %.1f bits (%d), Expect = %g\n",
485 hl->pair[i]->aln[j]->bit_score,hl->pair[i]->aln[j]->raw_score,hl->pair[i]->aln[j]->evalue);
486 fprintf(ofp,"\n");
487
488 btc = new_Ascii_btCanvas(stdout,20,50,5,3);
489 if( hl->write_btc_func == NULL ) {
490 write_pretty_str_blast_align_btc(hl->pair[i]->aln[j]->alb,"Query:",hl->pair[i]->query->seq,"Sbjct:",hl->pair[i]->target->seq,btc);
491 } else {
492 (*hl->write_btc_func)(hl->pair[i]->aln[j]->alb,hl->pair[i]->query,hl->pair[i]->target,btc);
493 }
494 free_btCanvas(btc);
495 fprintf(ofp,"\n");
496 }
497 }
498
499 }
500
501
502 /* Function: write_pretty_Seq_blast_align_btc(alb,one,two,btc)
503 *
504 * Descrip: Chains up to char* level alignment writer
505 *
506 *
507 * Arg: alb [UNKN ] Undocumented argument [AlnBlock *]
508 * Arg: one [UNKN ] Undocumented argument [Sequence *]
509 * Arg: two [UNKN ] Undocumented argument [Sequence *]
510 * Arg: btc [UNKN ] Undocumented argument [btCanvas *]
511 *
512 * Return [UNKN ] Undocumented return value [boolean]
513 *
514 */
515 # line 453 "hitlist.dy"
write_pretty_Seq_blast_align_btc(AlnBlock * alb,Sequence * one,Sequence * two,btCanvas * btc)516 boolean write_pretty_Seq_blast_align_btc(AlnBlock * alb,Sequence * one,Sequence * two,btCanvas * btc)
517 {
518 return write_pretty_str_blast_align_btc(alb,one->name,one->seq,two->name,two->seq,btc);
519 }
520
521 /* Function: write_pretty_str_blast_align_btc(alb,qname,query,tname,target,btc)
522 *
523 * Descrip: This function writes precisely
524 * what you expect for a a simple alignment.
525 *
526 * We can reuse this routine all over the place because
527 * we dont use any hard coded structure for the
528 * query or the target sequence letters. ... but crap
529 * type checking it has to be said!
530 *
531 * Also we use a generic btCanvas that could have
532 * any implementation underneath (eg, ASCII, postscript etc).
533 *
534 *
535 * Arg: alb [UNKN ] Undocumented argument [AlnBlock *]
536 * Arg: qname [UNKN ] Undocumented argument [char *]
537 * Arg: query [UNKN ] Undocumented argument [char *]
538 * Arg: tname [UNKN ] Undocumented argument [char *]
539 * Arg: target [UNKN ] Undocumented argument [char *]
540 * Arg: btc [UNKN ] Undocumented argument [btCanvas *]
541 *
542 * Return [UNKN ] Undocumented return value [boolean]
543 *
544 */
545 # line 470 "hitlist.dy"
write_pretty_str_blast_align_btc(AlnBlock * alb,char * qname,char * query,char * tname,char * target,btCanvas * btc)546 boolean write_pretty_str_blast_align_btc(AlnBlock * alb,char * qname,char * query,char * tname,char * target,btCanvas * btc)
547 {
548 int finished = 0;
549 AlnColumn * alc;
550 AlnColumn * prev = NULL;
551 AlnUnit * q;
552 AlnUnit * t;
553 char buffer[14];
554
555 btPasteArea * btp;
556
557 for(alc=alb->start;alc != NULL && finished == 0;) {
558
559 /** put names in **/
560
561 btp = get_reserved_left_btCanvas(btc);
562 paste_string_btPasteArea(btp,0,0,qname,BC_RIGHT,0);
563 paste_string_btPasteArea(btp,0,2,tname,BC_RIGHT,0);
564
565 sprintf(buffer,"%d",alc->alu[0]->start+1+1);
566
567 paste_string_btPasteArea(btp,12,0,buffer,BC_RIGHT,0);
568
569 sprintf(buffer,"%d",alc->alu[1]->start+1+1);
570
571 paste_string_btPasteArea(btp,12,2,buffer,BC_RIGHT,0);
572
573 free_btPasteArea(btp);
574 /** now loop over this block **/
575
576 for(;finished == 0 && alc != NULL && can_get_paste_area_btCanvas(btc,1) == TRUE;prev=alc,alc=alc->next) {
577
578 q = alc->alu[0];
579 t = alc->alu[1];
580
581 /*
582 * at the end, break
583 */
584 if( strcmp(q->text_label,"END") == 0 ) {
585 finished = 1;
586 break;
587 }
588
589 /*
590 * Get the paste area, length 1, depth will be 3
591 */
592
593 btp = get_paste_area_btCanvas(btc,1);
594
595 /*
596 * Write in the query sequence
597 *
598 */
599
600 if( strcmp(q->text_label,"SEQUENCE") == 0 || strstr(q->text_label,"BOUND") != NULL ) {
601 paste_char_btPasteArea(btp,0,0,toupper((int)query[q->start+1]),0);
602 } else if( strcmp(q->text_label,"UNMATCHED_SEQUENCE") == 0 ) {
603 paste_char_btPasteArea(btp,0,0,tolower((int)query[q->start+1]),0);
604 } else {
605 /** is insert- we could check **/
606 if( strcmp(q->text_label,"INSERT") != 0 ) {
607 warn("Got an uninterpretable label, %s",q->text_label);
608 paste_char_btPasteArea(btp,0,0,'?',0);
609 } else {
610 paste_char_btPasteArea(btp,0,0,'-',0);
611 }
612 }
613
614 /*
615 * Write in the target sequence
616 *
617 */
618
619 if( strcmp(t->text_label,"SEQUENCE") == 0 ) {
620 paste_char_btPasteArea(btp,0,2,toupper((int)target[t->start+1]),0);
621 } else if( strcmp(t->text_label,"UNMATCHED_SEQUENCE") == 0 ) {
622 paste_char_btPasteArea(btp,0,2,tolower((int)target[t->start+1]),0);
623 } else {
624 /** is insert- we could check **/
625 if( strcmp(t->text_label,"INSERT") != 0 ) {
626 warn("Got an uninterpretable label, %s",t->text_label);
627 paste_char_btPasteArea(btp,0,2,'?',0);
628 } else {
629 paste_char_btPasteArea(btp,0,2,'-',0);
630 }
631 }
632
633 /*
634 * Match line
635 */
636
637
638
639 if( strcmp(q->text_label,"SEQUENCE") == 0 && strcmp(t->text_label,"SEQUENCE") == 0 ) {
640 if( q->score[0] > 0 ) {
641 if( query[q->start+1] == target[t->start+1] ) {
642 paste_char_btPasteArea(btp,0,1,target[t->start+1],0);
643 } else {
644 paste_char_btPasteArea(btp,0,1,'+',0);
645 }
646 }
647 } else
648 paste_char_btPasteArea(btp,0,1,' ',0);
649
650 free_btPasteArea(btp);
651
652 } /* end of for this block */
653
654
655 if( prev != NULL ) {
656 btp = get_reserved_right_btCanvas(btc);
657
658 sprintf(buffer,"%d",prev->alu[0]->end+1);
659
660 paste_string_btPasteArea(btp,0,0,buffer,BC_RIGHT,0);
661
662 sprintf(buffer,"%d",prev->alu[1]->end+1);
663
664 paste_string_btPasteArea(btp,0,2,buffer,BC_RIGHT,0);
665
666 free_btPasteArea(btp);
667 }
668
669 advance_line_btCanvas(btc);
670 if( alc->next != NULL && strcmp(alc->next->alu[1]->text_label,"END") == 0 ) {
671 break;
672 }
673 } /* end of for the alignment */
674
675 return TRUE; /* we never returned false. Ooops! */
676 }
677 # line 646 "hitlist.c"
678 /* Function: hard_link_HitAln(obj)
679 *
680 * Descrip: Bumps up the reference count of the object
681 * Meaning that multiple pointers can 'own' it
682 *
683 *
684 * Arg: obj [UNKN ] Object to be hard linked [HitAln *]
685 *
686 * Return [UNKN ] Undocumented return value [HitAln *]
687 *
688 */
hard_link_HitAln(HitAln * obj)689 HitAln * hard_link_HitAln(HitAln * obj)
690 {
691 if( obj == NULL ) {
692 warn("Trying to hard link to a HitAln object: passed a NULL object");
693 return NULL;
694 }
695 obj->dynamite_hard_link++;
696 return obj;
697 }
698
699
700 /* Function: HitAln_alloc(void)
701 *
702 * Descrip: Allocates structure: assigns defaults if given
703 *
704 *
705 *
706 * Return [UNKN ] Undocumented return value [HitAln *]
707 *
708 */
HitAln_alloc(void)709 HitAln * HitAln_alloc(void)
710 {
711 HitAln * out; /* out is exported at end of function */
712
713
714 /* call ckalloc and see if NULL */
715 if((out=(HitAln *) ckalloc (sizeof(HitAln))) == NULL) {
716 warn("HitAln_alloc failed ");
717 return NULL; /* calling function should respond! */
718 }
719 out->dynamite_hard_link = 1;
720 #ifdef PTHREAD
721 pthread_mutex_init(&(out->dynamite_mutex),NULL);
722 #endif
723 out->raw_score = 0;
724 out->bit_score = 0;
725 out->evalue = 0;
726 out->alb = NULL;
727
728
729 return out;
730 }
731
732
733 /* Function: free_HitAln(obj)
734 *
735 * Descrip: Free Function: removes the memory held by obj
736 * Will chain up to owned members and clear all lists
737 *
738 *
739 * Arg: obj [UNKN ] Object that is free'd [HitAln *]
740 *
741 * Return [UNKN ] Undocumented return value [HitAln *]
742 *
743 */
free_HitAln(HitAln * obj)744 HitAln * free_HitAln(HitAln * obj)
745 {
746 int return_early = 0;
747
748
749 if( obj == NULL) {
750 warn("Attempting to free a NULL pointer to a HitAln obj. Should be trappable");
751 return NULL;
752 }
753
754
755 #ifdef PTHREAD
756 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
757 #endif
758 if( obj->dynamite_hard_link > 1) {
759 return_early = 1;
760 obj->dynamite_hard_link--;
761 }
762 #ifdef PTHREAD
763 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
764 #endif
765 if( return_early == 1)
766 return NULL;
767 if( obj->alb != NULL)
768 free_AlnBlock(obj->alb);
769
770
771 ckfree(obj);
772 return NULL;
773 }
774
775
776 /* Function: swap_HitPair(list,i,j)
777 *
778 * Descrip: swap function: an internal for qsort_HitPair
779 * swaps two positions in the array
780 *
781 *
782 * Arg: list [UNKN ] List of structures to swap in [HitAln **]
783 * Arg: i [UNKN ] swap position [int]
784 * Arg: j [UNKN ] swap position [int]
785 *
786 */
787 /* swap function for qsort function */
swap_HitPair(HitAln ** list,int i,int j)788 void swap_HitPair(HitAln ** list,int i,int j)
789 {
790 HitAln * temp;
791 temp=list[i];
792 list[i]=list[j];
793 list[j]=temp;
794 }
795
796
797 /* Function: qsort_HitPair(list,left,right,comp)
798 *
799 * Descrip: qsort - lifted from K&R
800 * sorts the array using quicksort
801 * Probably much better to call sort_HitPair which sorts from start to end
802 *
803 *
804 * Arg: list [UNKN ] List of structures to swap in [HitAln **]
805 * Arg: left [UNKN ] left position [int]
806 * Arg: right [UNKN ] right position [int]
807 * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
808 *
809 */
qsort_HitPair(HitAln ** list,int left,int right,int (* comp)(HitAln *,HitAln *))810 void qsort_HitPair(HitAln ** list,int left,int right,int (*comp)(HitAln * ,HitAln * ))
811 {
812 int i,last;
813 if( left >= right )
814 return;
815
816
817 swap_HitPair(list,left,(left+right)/2);
818 last = left;
819 for ( i=left+1; i <= right;i++) {
820 if( (*comp)(list[i],list[left]) < 0)
821 swap_HitPair (list,++last,i);
822 }
823 swap_HitPair (list,left,last);
824 qsort_HitPair(list,left,last-1,comp);
825 qsort_HitPair(list,last+1,right,comp);
826 }
827
828
829 /* Function: sort_HitPair(obj,comp)
830 *
831 * Descrip: sorts from start to end using comp
832 * sorts the array using quicksort by calling qsort_HitPair
833 *
834 *
835 * Arg: obj [UNKN ] Object containing list [HitPair *]
836 * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
837 *
838 */
sort_HitPair(HitPair * obj,int (* comp)(HitAln *,HitAln *))839 void sort_HitPair(HitPair * obj,int (*comp)(HitAln *, HitAln *))
840 {
841 qsort_HitPair(obj->aln,0,obj->len-1,comp);
842 return;
843 }
844
845
846 /* Function: expand_HitPair(obj,len)
847 *
848 * Descrip: Really an internal function for add_HitPair
849 *
850 *
851 * Arg: obj [UNKN ] Object which contains the list [HitPair *]
852 * Arg: len [UNKN ] Length to add one [int]
853 *
854 * Return [UNKN ] Undocumented return value [boolean]
855 *
856 */
expand_HitPair(HitPair * obj,int len)857 boolean expand_HitPair(HitPair * obj,int len)
858 {
859
860
861 if( obj->maxlen > obj->len ) {
862 warn("expand_HitPair called with no need");
863 return TRUE;
864 }
865
866
867 if( (obj->aln = (HitAln ** ) ckrealloc (obj->aln,sizeof(HitAln *)*len)) == NULL) {
868 warn("ckrealloc failed for expand_HitPair, returning FALSE");
869 return FALSE;
870 }
871 obj->maxlen = len;
872 return TRUE;
873 }
874
875
876 /* Function: add_HitPair(obj,add)
877 *
878 * Descrip: Adds another object to the list. It will expand the list if necessary
879 *
880 *
881 * Arg: obj [UNKN ] Object which contains the list [HitPair *]
882 * Arg: add [OWNER] Object to add to the list [HitAln *]
883 *
884 * Return [UNKN ] Undocumented return value [boolean]
885 *
886 */
887 /* will expand function if necessary */
add_HitPair(HitPair * obj,HitAln * add)888 boolean add_HitPair(HitPair * obj,HitAln * add)
889 {
890 if( obj->len >= obj->maxlen) {
891 if( expand_HitPair(obj,obj->len + HitPairLISTLENGTH) == FALSE)
892 return FALSE;
893 }
894
895
896 obj->aln[obj->len++]=add;
897 return TRUE;
898 }
899
900
901 /* Function: flush_HitPair(obj)
902 *
903 * Descrip: Frees the list elements, sets length to 0
904 * If you want to save some elements, use hard_link_xxx
905 * to protect them from being actually destroyed in the free
906 *
907 *
908 * Arg: obj [UNKN ] Object which contains the list [HitPair *]
909 *
910 * Return [UNKN ] Undocumented return value [int]
911 *
912 */
flush_HitPair(HitPair * obj)913 int flush_HitPair(HitPair * obj)
914 {
915 int i;
916
917
918 for(i=0;i<obj->len;i++) { /*for i over list length*/
919 if( obj->aln[i] != NULL) {
920 free_HitAln(obj->aln[i]);
921 obj->aln[i] = NULL;
922 }
923 } /* end of for i over list length */
924
925
926 obj->len = 0;
927 return i;
928 }
929
930
931 /* Function: HitPair_alloc_std(void)
932 *
933 * Descrip: Equivalent to HitPair_alloc_len(HitPairLISTLENGTH)
934 *
935 *
936 *
937 * Return [UNKN ] Undocumented return value [HitPair *]
938 *
939 */
HitPair_alloc_std(void)940 HitPair * HitPair_alloc_std(void)
941 {
942 return HitPair_alloc_len(HitPairLISTLENGTH);
943 }
944
945
946 /* Function: HitPair_alloc_len(len)
947 *
948 * Descrip: Allocates len length to all lists
949 *
950 *
951 * Arg: len [UNKN ] Length of lists to allocate [int]
952 *
953 * Return [UNKN ] Undocumented return value [HitPair *]
954 *
955 */
HitPair_alloc_len(int len)956 HitPair * HitPair_alloc_len(int len)
957 {
958 HitPair * out; /* out is exported at the end of function */
959
960
961 /* Call alloc function: return NULL if NULL */
962 /* Warning message alread in alloc function */
963 if((out = HitPair_alloc()) == NULL)
964 return NULL;
965
966
967 /* Calling ckcalloc for list elements */
968 if((out->aln = (HitAln ** ) ckcalloc (len,sizeof(HitAln *))) == NULL) {
969 warn("Warning, ckcalloc failed in HitPair_alloc_len");
970 return NULL;
971 }
972 out->len = 0;
973 out->maxlen = len;
974
975
976 return out;
977 }
978
979
980 /* Function: hard_link_HitPair(obj)
981 *
982 * Descrip: Bumps up the reference count of the object
983 * Meaning that multiple pointers can 'own' it
984 *
985 *
986 * Arg: obj [UNKN ] Object to be hard linked [HitPair *]
987 *
988 * Return [UNKN ] Undocumented return value [HitPair *]
989 *
990 */
hard_link_HitPair(HitPair * obj)991 HitPair * hard_link_HitPair(HitPair * obj)
992 {
993 if( obj == NULL ) {
994 warn("Trying to hard link to a HitPair object: passed a NULL object");
995 return NULL;
996 }
997 obj->dynamite_hard_link++;
998 return obj;
999 }
1000
1001
1002 /* Function: HitPair_alloc(void)
1003 *
1004 * Descrip: Allocates structure: assigns defaults if given
1005 *
1006 *
1007 *
1008 * Return [UNKN ] Undocumented return value [HitPair *]
1009 *
1010 */
HitPair_alloc(void)1011 HitPair * HitPair_alloc(void)
1012 {
1013 HitPair * out; /* out is exported at end of function */
1014
1015
1016 /* call ckalloc and see if NULL */
1017 if((out=(HitPair *) ckalloc (sizeof(HitPair))) == NULL) {
1018 warn("HitPair_alloc failed ");
1019 return NULL; /* calling function should respond! */
1020 }
1021 out->dynamite_hard_link = 1;
1022 #ifdef PTHREAD
1023 pthread_mutex_init(&(out->dynamite_mutex),NULL);
1024 #endif
1025 out->query = NULL;
1026 out->target = NULL;
1027 out->raw_score = 0;
1028 out->bit_score = 0;
1029 out->evalue = 0;
1030 out->aln = NULL;
1031 out->len = out->maxlen = 0;
1032 out->target_reversed = FALSE;
1033
1034
1035 return out;
1036 }
1037
1038
1039 /* Function: free_HitPair(obj)
1040 *
1041 * Descrip: Free Function: removes the memory held by obj
1042 * Will chain up to owned members and clear all lists
1043 *
1044 *
1045 * Arg: obj [UNKN ] Object that is free'd [HitPair *]
1046 *
1047 * Return [UNKN ] Undocumented return value [HitPair *]
1048 *
1049 */
free_HitPair(HitPair * obj)1050 HitPair * free_HitPair(HitPair * obj)
1051 {
1052 int return_early = 0;
1053 int i;
1054
1055
1056 if( obj == NULL) {
1057 warn("Attempting to free a NULL pointer to a HitPair obj. Should be trappable");
1058 return NULL;
1059 }
1060
1061
1062 #ifdef PTHREAD
1063 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
1064 #endif
1065 if( obj->dynamite_hard_link > 1) {
1066 return_early = 1;
1067 obj->dynamite_hard_link--;
1068 }
1069 #ifdef PTHREAD
1070 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
1071 #endif
1072 if( return_early == 1)
1073 return NULL;
1074 if( obj->query != NULL)
1075 free_Sequence(obj->query);
1076 if( obj->target != NULL)
1077 free_Sequence(obj->target);
1078 if( obj->aln != NULL) {
1079 for(i=0;i<obj->len;i++) {
1080 if( obj->aln[i] != NULL)
1081 free_HitAln(obj->aln[i]);
1082 }
1083 ckfree(obj->aln);
1084 }
1085
1086
1087 ckfree(obj);
1088 return NULL;
1089 }
1090
1091
1092 /* Function: swap_HitList(list,i,j)
1093 *
1094 * Descrip: swap function: an internal for qsort_HitList
1095 * swaps two positions in the array
1096 *
1097 *
1098 * Arg: list [UNKN ] List of structures to swap in [HitPair **]
1099 * Arg: i [UNKN ] swap position [int]
1100 * Arg: j [UNKN ] swap position [int]
1101 *
1102 */
1103 /* swap function for qsort function */
swap_HitList(HitPair ** list,int i,int j)1104 void swap_HitList(HitPair ** list,int i,int j)
1105 {
1106 HitPair * temp;
1107 temp=list[i];
1108 list[i]=list[j];
1109 list[j]=temp;
1110 }
1111
1112
1113 /* Function: qsort_HitList(list,left,right,comp)
1114 *
1115 * Descrip: qsort - lifted from K&R
1116 * sorts the array using quicksort
1117 * Probably much better to call sort_HitList which sorts from start to end
1118 *
1119 *
1120 * Arg: list [UNKN ] List of structures to swap in [HitPair **]
1121 * Arg: left [UNKN ] left position [int]
1122 * Arg: right [UNKN ] right position [int]
1123 * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1124 *
1125 */
qsort_HitList(HitPair ** list,int left,int right,int (* comp)(HitPair *,HitPair *))1126 void qsort_HitList(HitPair ** list,int left,int right,int (*comp)(HitPair * ,HitPair * ))
1127 {
1128 int i,last;
1129 if( left >= right )
1130 return;
1131
1132
1133 swap_HitList(list,left,(left+right)/2);
1134 last = left;
1135 for ( i=left+1; i <= right;i++) {
1136 if( (*comp)(list[i],list[left]) < 0)
1137 swap_HitList (list,++last,i);
1138 }
1139 swap_HitList (list,left,last);
1140 qsort_HitList(list,left,last-1,comp);
1141 qsort_HitList(list,last+1,right,comp);
1142 }
1143
1144
1145 /* Function: sort_HitList(obj,comp)
1146 *
1147 * Descrip: sorts from start to end using comp
1148 * sorts the array using quicksort by calling qsort_HitList
1149 *
1150 *
1151 * Arg: obj [UNKN ] Object containing list [HitList *]
1152 * Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
1153 *
1154 */
sort_HitList(HitList * obj,int (* comp)(HitPair *,HitPair *))1155 void sort_HitList(HitList * obj,int (*comp)(HitPair *, HitPair *))
1156 {
1157 qsort_HitList(obj->pair,0,obj->len-1,comp);
1158 return;
1159 }
1160
1161
1162 /* Function: expand_HitList(obj,len)
1163 *
1164 * Descrip: Really an internal function for add_HitList
1165 *
1166 *
1167 * Arg: obj [UNKN ] Object which contains the list [HitList *]
1168 * Arg: len [UNKN ] Length to add one [int]
1169 *
1170 * Return [UNKN ] Undocumented return value [boolean]
1171 *
1172 */
expand_HitList(HitList * obj,int len)1173 boolean expand_HitList(HitList * obj,int len)
1174 {
1175
1176
1177 if( obj->maxlen > obj->len ) {
1178 warn("expand_HitList called with no need");
1179 return TRUE;
1180 }
1181
1182
1183 if( (obj->pair = (HitPair ** ) ckrealloc (obj->pair,sizeof(HitPair *)*len)) == NULL) {
1184 warn("ckrealloc failed for expand_HitList, returning FALSE");
1185 return FALSE;
1186 }
1187 obj->maxlen = len;
1188 return TRUE;
1189 }
1190
1191
1192 /* Function: add_HitList(obj,add)
1193 *
1194 * Descrip: Adds another object to the list. It will expand the list if necessary
1195 *
1196 *
1197 * Arg: obj [UNKN ] Object which contains the list [HitList *]
1198 * Arg: add [OWNER] Object to add to the list [HitPair *]
1199 *
1200 * Return [UNKN ] Undocumented return value [boolean]
1201 *
1202 */
1203 /* will expand function if necessary */
add_HitList(HitList * obj,HitPair * add)1204 boolean add_HitList(HitList * obj,HitPair * add)
1205 {
1206 if( obj->len >= obj->maxlen) {
1207 if( expand_HitList(obj,obj->len + HitListLISTLENGTH) == FALSE)
1208 return FALSE;
1209 }
1210
1211
1212 obj->pair[obj->len++]=add;
1213 return TRUE;
1214 }
1215
1216
1217 /* Function: flush_HitList(obj)
1218 *
1219 * Descrip: Frees the list elements, sets length to 0
1220 * If you want to save some elements, use hard_link_xxx
1221 * to protect them from being actually destroyed in the free
1222 *
1223 *
1224 * Arg: obj [UNKN ] Object which contains the list [HitList *]
1225 *
1226 * Return [UNKN ] Undocumented return value [int]
1227 *
1228 */
flush_HitList(HitList * obj)1229 int flush_HitList(HitList * obj)
1230 {
1231 int i;
1232
1233
1234 for(i=0;i<obj->len;i++) { /*for i over list length*/
1235 if( obj->pair[i] != NULL) {
1236 free_HitPair(obj->pair[i]);
1237 obj->pair[i] = NULL;
1238 }
1239 } /* end of for i over list length */
1240
1241
1242 obj->len = 0;
1243 return i;
1244 }
1245
1246
1247 /* Function: HitList_alloc_std(void)
1248 *
1249 * Descrip: Equivalent to HitList_alloc_len(HitListLISTLENGTH)
1250 *
1251 *
1252 *
1253 * Return [UNKN ] Undocumented return value [HitList *]
1254 *
1255 */
HitList_alloc_std(void)1256 HitList * HitList_alloc_std(void)
1257 {
1258 return HitList_alloc_len(HitListLISTLENGTH);
1259 }
1260
1261
1262 /* Function: HitList_alloc_len(len)
1263 *
1264 * Descrip: Allocates len length to all lists
1265 *
1266 *
1267 * Arg: len [UNKN ] Length of lists to allocate [int]
1268 *
1269 * Return [UNKN ] Undocumented return value [HitList *]
1270 *
1271 */
HitList_alloc_len(int len)1272 HitList * HitList_alloc_len(int len)
1273 {
1274 HitList * out; /* out is exported at the end of function */
1275
1276
1277 /* Call alloc function: return NULL if NULL */
1278 /* Warning message alread in alloc function */
1279 if((out = HitList_alloc()) == NULL)
1280 return NULL;
1281
1282
1283 /* Calling ckcalloc for list elements */
1284 if((out->pair = (HitPair ** ) ckcalloc (len,sizeof(HitPair *))) == NULL) {
1285 warn("Warning, ckcalloc failed in HitList_alloc_len");
1286 return NULL;
1287 }
1288 out->len = 0;
1289 out->maxlen = len;
1290
1291
1292 return out;
1293 }
1294
1295
1296 /* Function: hard_link_HitList(obj)
1297 *
1298 * Descrip: Bumps up the reference count of the object
1299 * Meaning that multiple pointers can 'own' it
1300 *
1301 *
1302 * Arg: obj [UNKN ] Object to be hard linked [HitList *]
1303 *
1304 * Return [UNKN ] Undocumented return value [HitList *]
1305 *
1306 */
hard_link_HitList(HitList * obj)1307 HitList * hard_link_HitList(HitList * obj)
1308 {
1309 if( obj == NULL ) {
1310 warn("Trying to hard link to a HitList object: passed a NULL object");
1311 return NULL;
1312 }
1313 obj->dynamite_hard_link++;
1314 return obj;
1315 }
1316
1317
1318 /* Function: HitList_alloc(void)
1319 *
1320 * Descrip: Allocates structure: assigns defaults if given
1321 *
1322 *
1323 *
1324 * Return [UNKN ] Undocumented return value [HitList *]
1325 *
1326 */
HitList_alloc(void)1327 HitList * HitList_alloc(void)
1328 {
1329 HitList * out; /* out is exported at end of function */
1330
1331
1332 /* call ckalloc and see if NULL */
1333 if((out=(HitList *) ckalloc (sizeof(HitList))) == NULL) {
1334 warn("HitList_alloc failed ");
1335 return NULL; /* calling function should respond! */
1336 }
1337 out->dynamite_hard_link = 1;
1338 #ifdef PTHREAD
1339 pthread_mutex_init(&(out->dynamite_mutex),NULL);
1340 #endif
1341 out->pair = NULL;
1342 out->len = out->maxlen = 0;
1343 out->mat = NULL;
1344 out->write_btc_func = NULL;
1345 out->stat_attrib = NULL;
1346
1347
1348 return out;
1349 }
1350
1351
1352 /* Function: free_HitList(obj)
1353 *
1354 * Descrip: Free Function: removes the memory held by obj
1355 * Will chain up to owned members and clear all lists
1356 *
1357 *
1358 * Arg: obj [UNKN ] Object that is free'd [HitList *]
1359 *
1360 * Return [UNKN ] Undocumented return value [HitList *]
1361 *
1362 */
free_HitList(HitList * obj)1363 HitList * free_HitList(HitList * obj)
1364 {
1365 int return_early = 0;
1366 int i;
1367
1368
1369 if( obj == NULL) {
1370 warn("Attempting to free a NULL pointer to a HitList obj. Should be trappable");
1371 return NULL;
1372 }
1373
1374
1375 #ifdef PTHREAD
1376 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
1377 #endif
1378 if( obj->dynamite_hard_link > 1) {
1379 return_early = 1;
1380 obj->dynamite_hard_link--;
1381 }
1382 #ifdef PTHREAD
1383 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
1384 #endif
1385 if( return_early == 1)
1386 return NULL;
1387 if( obj->pair != NULL) {
1388 for(i=0;i<obj->len;i++) {
1389 if( obj->pair[i] != NULL)
1390 free_HitPair(obj->pair[i]);
1391 }
1392 ckfree(obj->pair);
1393 }
1394 if( obj->mat != NULL)
1395 free_CompMat(obj->mat);
1396 /* obj->write_btc_func is a function pointer */
1397 if( obj->stat_attrib != NULL)
1398 ckfree(obj->stat_attrib);
1399
1400
1401 ckfree(obj);
1402 return NULL;
1403 }
1404
1405
1406 /* Function: hard_link_HitListOutputImpl(obj)
1407 *
1408 * Descrip: Bumps up the reference count of the object
1409 * Meaning that multiple pointers can 'own' it
1410 *
1411 *
1412 * Arg: obj [UNKN ] Object to be hard linked [HitListOutputImpl *]
1413 *
1414 * Return [UNKN ] Undocumented return value [HitListOutputImpl *]
1415 *
1416 */
hard_link_HitListOutputImpl(HitListOutputImpl * obj)1417 HitListOutputImpl * hard_link_HitListOutputImpl(HitListOutputImpl * obj)
1418 {
1419 if( obj == NULL ) {
1420 warn("Trying to hard link to a HitListOutputImpl object: passed a NULL object");
1421 return NULL;
1422 }
1423 obj->dynamite_hard_link++;
1424 return obj;
1425 }
1426
1427
1428 /* Function: HitListOutputImpl_alloc(void)
1429 *
1430 * Descrip: Allocates structure: assigns defaults if given
1431 *
1432 *
1433 *
1434 * Return [UNKN ] Undocumented return value [HitListOutputImpl *]
1435 *
1436 */
HitListOutputImpl_alloc(void)1437 HitListOutputImpl * HitListOutputImpl_alloc(void)
1438 {
1439 HitListOutputImpl * out;/* out is exported at end of function */
1440
1441
1442 /* call ckalloc and see if NULL */
1443 if((out=(HitListOutputImpl *) ckalloc (sizeof(HitListOutputImpl))) == NULL) {
1444 warn("HitListOutputImpl_alloc failed ");
1445 return NULL; /* calling function should respond! */
1446 }
1447 out->dynamite_hard_link = 1;
1448 #ifdef PTHREAD
1449 pthread_mutex_init(&(out->dynamite_mutex),NULL);
1450 #endif
1451 out->type = HitListOutputFormatPseudoBlast;
1452
1453
1454 return out;
1455 }
1456
1457
1458 /* Function: free_HitListOutputImpl(obj)
1459 *
1460 * Descrip: Free Function: removes the memory held by obj
1461 * Will chain up to owned members and clear all lists
1462 *
1463 *
1464 * Arg: obj [UNKN ] Object that is free'd [HitListOutputImpl *]
1465 *
1466 * Return [UNKN ] Undocumented return value [HitListOutputImpl *]
1467 *
1468 */
free_HitListOutputImpl(HitListOutputImpl * obj)1469 HitListOutputImpl * free_HitListOutputImpl(HitListOutputImpl * obj)
1470 {
1471 int return_early = 0;
1472
1473
1474 if( obj == NULL) {
1475 warn("Attempting to free a NULL pointer to a HitListOutputImpl obj. Should be trappable");
1476 return NULL;
1477 }
1478
1479
1480 #ifdef PTHREAD
1481 assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
1482 #endif
1483 if( obj->dynamite_hard_link > 1) {
1484 return_early = 1;
1485 obj->dynamite_hard_link--;
1486 }
1487 #ifdef PTHREAD
1488 assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
1489 #endif
1490 if( return_early == 1)
1491 return NULL;
1492
1493
1494 ckfree(obj);
1495 return NULL;
1496 }
1497
1498
1499
1500 #ifdef _cplusplus
1501 }
1502 #endif
1503