/* Function: free_GeneStats(obj) * * Descrip: Free Function: removes the memory held by obj * Will chain up to owned members and clear all lists * * * Arg: obj [UNKN ] Object that is free'd [GeneStats *] * * Return [UNKN ] Undocumented return value [GeneStats *] * */ GeneStats * free_GeneStats(GeneStats * obj) { if( obj == NULL) { warn("Attempting to free a NULL pointer to a GeneStats obj. Should be trappable"); return NULL; } if( obj->dynamite_hard_link > 1) { obj->dynamite_hard_link--; return NULL; } if( obj->splice5 != NULL) free_SeqAlign(obj->splice5); if( obj->splice3 != NULL) free_SeqAlign(obj->splice3); if( obj->intron != NULL) free_RandomModelDNA(obj->intron); if( obj->polyp != NULL) free_RandomModelDNA(obj->polyp); if( obj->rnd != NULL) free_RandomModelDNA(obj->rnd); ckfree(obj); return NULL; }
/* Function: free_GeneStats(obj) * * Descrip: Free Function: removes the memory held by obj * Will chain up to owned members and clear all lists * * * Arg: obj [UNKN ] Object that is free'd [GeneStats *] * * Return [UNKN ] Undocumented return value [GeneStats *] * */ GeneStats * free_GeneStats(GeneStats * obj) { int return_early = 0; if( obj == NULL) { warn("Attempting to free a NULL pointer to a GeneStats obj. Should be trappable"); return NULL; } #ifdef PTHREAD assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0); #endif if( obj->dynamite_hard_link > 1) { return_early = 1; obj->dynamite_hard_link--; } #ifdef PTHREAD assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0); #endif if( return_early == 1) return NULL; if( obj->splice5 != NULL) free_SeqAlign(obj->splice5); if( obj->splice3 != NULL) free_SeqAlign(obj->splice3); if( obj->intron != NULL) free_RandomModelDNA(obj->intron); if( obj->polyp != NULL) free_RandomModelDNA(obj->polyp); if( obj->rnd != NULL) free_RandomModelDNA(obj->rnd); ckfree(obj); return NULL; }
/* Function: free_DnaHmmProb(obj) * * Descrip: Free Function: removes the memory held by obj * Will chain up to owned members and clear all lists * * * Arg: obj [UNKN ] Object that is free'd [DnaHmmProb *] * * Return [UNKN ] Undocumented return value [DnaHmmProb *] * */ DnaHmmProb * free_DnaHmmProb(DnaHmmProb * obj) { int return_early = 0; int i; if( obj == NULL) { warn("Attempting to free a NULL pointer to a DnaHmmProb obj. Should be trappable"); return NULL; } #ifdef PTHREAD assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0); #endif if( obj->dynamite_hard_link > 1) { return_early = 1; obj->dynamite_hard_link--; } #ifdef PTHREAD assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0); #endif if( return_early == 1) return NULL; if( obj->unit != NULL) { for(i=0;i<obj->len;i++) { if( obj->unit[i] != NULL) free_DnaHmmProbUnit(obj->unit[i]); } ckfree(obj->unit); } if( obj->ref_align != NULL) free_SeqAlign(obj->ref_align); if( obj->consensus != NULL) ckfree(obj->consensus); ckfree(obj); return NULL; }
DnaProfileSet * DnaProfileSet_from_leaf_leaf(Sequence * one,Sequence * two,DnaProfileEnginePara * dpep) { DnaProfileSet * out; DnaMatrix * dm; DnaProbMatrix * dmp; PairwiseShortDna * psd; LocalCisHitSet * set; Sequence * two_rev; DnaProfile * dp; SeqAlign * sa; Sequence * temp1; Sequence * temp2; char * temp_seq1; char * temp_seq2; int unmatched; int seq1_i,seq2_i; AlnColumn * alc; int i; two_rev = reverse_complement_Sequence(two); dmp = DnaProbMatrix_from_match(0.65,NMaskType_BANNED); assert(dmp); flat_null_DnaProbMatrix(dmp); dm = DnaMatrix_from_DnaProbMatrix(dmp); show_DnaMatrix(dm,stderr); psd = query_to_reverse_target(one,two,dm,0,one->len,0,two->len); set = make_LocalCisHitSet(one,two,two_rev,psd->forward,psd->reverse,dpep->setpara,dpep->lchs,NULL,NULL,NULL,NULL,0,dpep->dpri); temp_seq1 = calloc(one->len > two->len ? one->len : two->len,sizeof(char)); temp_seq2 = calloc(one->len > two->len ? one->len : two->len,sizeof(char)); out = DnaProfileSet_alloc_std(); for(i=0; i<set->len; i++) { unmatched = 1; sa = NULL; /* * Main loop over DBA style alignment. We need to make one * DnaProfile per matching block, which are separated by unmatched * blocks. Could potentially be no blocks. * * Extra annoyance provided by the "wrong" convention being used in * DBA alignments, meaning that "inserts" label the "sequence" containing * strand, not the non-sequence containing strand. Stupid, but dbadisplay * uses this convention, so if we changed, would have to fix lots of exisiting * code. Not ideal. * */ for(alc=set->lch[i]->alb->start; alc != NULL; alc=alc->next) { /* hitting an unmatched block */ if( unmatched == 0 && (strcmp(alc->alu[0]->text_label,"UM") == 0 || strcmp(alc->alu[0]->text_label,"UI") == 0 || strcmp(alc->alu[0]->text_label,"END") == 0) ) { /* if we have an alignment, put it away now */ if( sa != NULL ) { temp_seq1[seq1_i] = '\0'; temp_seq2[seq2_i] = '\0'; temp1 = Sequence_from_static_memory(one->name,temp_seq1); temp2 = Sequence_from_static_memory(two->name,temp_seq2); add_SeqAlign(sa,temp1); add_SeqAlign(sa,temp2); dp = naive_DnaProfile_from_SeqAlign(sa,0.15,0.1,0.1,0.8,0.8); fold_RandomModel_DnaProfile(dp,dpep->rm); add_DnaProfileSet(out,dp); free_SeqAlign(sa); /* hard linked inside DP */ sa = NULL; } continue; } else if( unmatched == 1 && (strstartcmp(alc->alu[0]->text_label,"MM") == 0 || strstartcmp(alc->alu[0]->text_label,"MI") == 0 ) ) { unmatched = 0; sa = SeqAlign_alloc_len(2); seq1_i = 0; seq2_i = 0; } /* only if we are in a matched block */ if( unmatched == 0 ) { /* Bloody twisted DBA convention - Niclas has alot to answer for. Evil stuff -- MI is on the wrong strand! */ if( strstartcmp(alc->alu[0]->text_label,"MI") == 0 ) { /* means 0 has sequence, other has gap */ temp_seq1[seq1_i++] = one->seq[alc->alu[0]->end]; temp_seq2[seq2_i++] = '-'; } else if ( strstartcmp(alc->alu[1]->text_label,"MI") == 0 ) { temp_seq1[seq1_i++] = '-'; temp_seq2[seq2_i++] = two->seq[alc->alu[1]->end]; } else if ( strstartcmp(alc->alu[0]->text_label,"MM") == 0 && strstartcmp(alc->alu[1]->text_label,"MM") == 0 ) { temp_seq1[seq1_i++] = one->seq[alc->alu[0]->end]; temp_seq2[seq2_i++] = two->seq[alc->alu[1]->end]; } else { warn("Impossible label pair reached in matched block local cis hit stuff, %s,%s",alc->alu[0]->text_label,alc->alu[1]->text_label); } } } } free(temp_seq1); free(temp_seq2); free_PairwiseShortDna(psd); free_LocalCisHitSet(set); free_DnaMatrix(dm); free_DnaProbMatrix(dmp); return out; }