/* Function: free_GenomicDB(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 [GenomicDB *] * * Return [UNKN ] Undocumented return value [GenomicDB *] * */ GenomicDB * free_GenomicDB(GenomicDB * obj) { if( obj == NULL) { warn("Attempting to free a NULL pointer to a GenomicDB obj. Should be trappable"); return NULL; } if( obj->dynamite_hard_link > 1) { obj->dynamite_hard_link--; return NULL; } if( obj->forw != NULL) free_ComplexSequence(obj->forw); if( obj->rev != NULL) free_ComplexSequence(obj->rev); if( obj->sdb != NULL) free_SequenceDB(obj->sdb); if( obj->current != NULL) free_Genomic(obj->current); if( obj->cses != NULL) free_ComplexSequenceEvalSet(obj->cses); if( obj->single != NULL) free_Genomic(obj->single); if( obj->revsingle != NULL) free_Genomic(obj->revsingle); ckfree(obj); return NULL; }
AlnBlock * Align_Sequences_ProteinBlockAligner(Sequence * one,Sequence * two,CompMat * comp,int bentry,int bexit,int b1exit,int b_self,int b_on,DPRunImpl * dpri) { ComplexSequence * cone=NULL; ComplexSequence * ctwo=NULL; AlnBlock * alb= NULL; PackAln * pal=NULL; ComplexSequenceEvalSet * evalfunc = NULL; if( one == NULL || two == NULL || comp == NULL ) { warn("Passed in NULL objects into Align_Sequences_ProteinSmithWaterman!"); return NULL; } if( one->type != SEQUENCE_PROTEIN ) { warn("Sequence %s is not typed as protein... ignoring!\n",one->name); } if( two->type != SEQUENCE_PROTEIN ) { warn("Sequence %s is not typed as protein... ignoring!\n",two->name); } evalfunc = default_aminoacid_ComplexSequenceEvalSet(); cone = new_ComplexSequence(one,evalfunc); if( cone == NULL ) goto cleanup; ctwo = new_ComplexSequence(two,evalfunc); if( ctwo == NULL ) goto cleanup; pal = PackAln_bestmemory_ProteinBlockAligner(cone,ctwo,comp,bentry,b1exit,b_on,b_self,bexit,NULL,dpri); if( pal == NULL ) goto cleanup; alb = convert_PackAln_to_AlnBlock_ProteinSW(pal); goto cleanup; cleanup : if( cone != NULL ) free_ComplexSequence(cone); if( ctwo != NULL ) free_ComplexSequence(ctwo); if( pal != NULL ) free_PackAln(pal); if( evalfunc != NULL ) free_ComplexSequenceEvalSet(evalfunc); return alb; }
/* Function: free_cDNADB(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 [cDNADB *] * * Return [UNKN ] Undocumented return value [cDNADB *] * */ cDNADB * free_cDNADB(cDNADB * obj) { int return_early = 0; if( obj == NULL) { warn("Attempting to free a NULL pointer to a cDNADB 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->forw != NULL) free_ComplexSequence(obj->forw); if( obj->rev != NULL) free_ComplexSequence(obj->rev); if( obj->sdb != NULL) free_SequenceDB(obj->sdb); if( obj->current != NULL) free_Sequence(obj->current); if( obj->cses != NULL) free_ComplexSequenceEvalSet(obj->cses); ckfree(obj); return NULL; }
boolean close_cDNADB(ComplexSequence * cs,cDNADB * cdnadb) { if( cdnadb->is_single_seq == TRUE ) { return TRUE; } if( cs != NULL) free_ComplexSequence(cs); if( cdnadb->current != NULL) cdnadb->current = free_Sequence(cdnadb->current); return close_SequenceDB(NULL,cdnadb->sdb); }
boolean close_GenomicDB(ComplexSequence * cs,GenomicDB * gendb) { if( gendb->is_single_seq == TRUE ) { return TRUE; } if( cs != NULL) free_ComplexSequence(cs); if( gendb->current != NULL) gendb->current = free_Genomic(gendb->current); return close_SequenceDB(NULL,gendb->sdb); }
ComplexSequence * reload_cDNADB(ComplexSequence * last,cDNADB * cdnadb,int * return_status) { ComplexSequence * cs; Sequence * seq,*temp; /** free Complex Sequence **/ if ( last != NULL ) { free_ComplexSequence(last); } if( cdnadb->forward_only == TRUE) { temp = reload_SequenceDB(NULL,cdnadb->sdb,return_status); if ( *return_status != DB_RETURN_OK ) { return NULL; } cs = new_ComplexSequence(temp,cdnadb->cses); return cs; } if( cdnadb->is_single_seq == TRUE ) { if( cdnadb->done_forward == TRUE ) { *return_status = DB_RETURN_OK; cdnadb->done_forward = FALSE; return hard_link_ComplexSequence(cdnadb->rev); } else { *return_status = DB_RETURN_END; return NULL; } } /** standard database **/ if( cdnadb->done_forward == TRUE ) { if( cdnadb->current == NULL ) { warn("A bad internal cDNA db error - unable to find current sequence in db reload"); *return_status = DB_RETURN_ERROR; return NULL; } temp = reverse_complement_Sequence(cdnadb->current); if( temp == NULL ) { warn("A bad internal cDNA db error - unable to reverse complements current"); *return_status = DB_RETURN_ERROR; return NULL; } cs = new_ComplexSequence(temp,cdnadb->cses); if( cs == NULL ) { warn("A bad internal cDNA db error - unable to make complex sequence in db reload"); *return_status = DB_RETURN_ERROR; return NULL; } free_Sequence(temp); cdnadb->done_forward = FALSE; return cs; } /* otherwise we have to get a new sequence */ seq = reload_SequenceDB(NULL,cdnadb->sdb,return_status); if( seq == NULL || *return_status == DB_RETURN_ERROR || *return_status == DB_RETURN_END ) { return NULL; /** error already reported **/ } uppercase_Sequence(seq); if( force_to_dna_Sequence(seq,cdnadb->error_tol,NULL) == FALSE ) { if( cdnadb->error_handling == CDNADB_READ_THROUGH ) { warn("Unable to map %s sequence to a cDNA sequence, but ignoring that for the moment...",seq->name); free_Sequence(seq); return reload_cDNADB(NULL,cdnadb,return_status); } else { warn("Unable to map %s sequence to a cDNA sequence. Failing",seq->name); *return_status = DB_RETURN_ERROR; return NULL; } } cs = new_ComplexSequence(seq,cdnadb->cses); if( cs == NULL ) { if( cdnadb->error_handling == CDNADB_READ_THROUGH ) { warn("Unable to map %s sequence to a cDNA sequence, but ignoring that for the moment...",seq->name); free_Sequence(seq); return reload_cDNADB(NULL,cdnadb,return_status); } else { warn("Unable to map %s sequence to a cDNA sequence. Failing",seq->name); *return_status = DB_RETURN_ERROR; return NULL; } } cdnadb->current = free_Sequence(cdnadb->current); cdnadb->current = seq; cdnadb->done_forward= TRUE; return cs; }
AlnBlock * Align_Sequences_ProteinSmithWaterman(Sequence * one,Sequence * two,CompMat * comp,int gap,int ext,DPRunImpl * dpri) { AlnBlock * out = NULL; ComplexSequenceEvalSet * evalfunc = NULL; ComplexSequence * query_cs = NULL; ComplexSequence * target_cs = NULL; PackAln * pal = NULL; if( one == NULL || two == NULL || comp == NULL ) { warn("Passed in NULL objects into Align_Sequences_ProteinSmithWaterman!"); return NULL; } if( one->type != SEQUENCE_PROTEIN ) { warn("Sequence %s is not typed as protein... ignoring!\n",one->name); } if( two->type != SEQUENCE_PROTEIN ) { warn("Sequence %s is not typed as protein... ignoring!\n",two->name); } if( gap > 0 || ext > 0 ) { warn("Gap penalties %d,%d only make sense if they are negative",gap,ext); return NULL; } evalfunc = default_aminoacid_ComplexSequenceEvalSet(); query_cs = new_ComplexSequence(one,evalfunc); if( query_cs == NULL ) goto cleanup; target_cs = new_ComplexSequence(two,evalfunc); if( target_cs == NULL ) goto cleanup; pal = PackAln_bestmemory_ProteinSW(query_cs,target_cs,comp,gap,ext,NULL,dpri); if( pal == NULL ) goto cleanup; out = convert_PackAln_to_AlnBlock_ProteinSW(pal); goto cleanup; cleanup : if( query_cs != NULL ) free_ComplexSequence(query_cs); if( target_cs != NULL ) free_ComplexSequence(target_cs); if( pal != NULL ) free_PackAln(pal); if( evalfunc != NULL ) free_ComplexSequenceEvalSet(evalfunc); return out; }
ComplexSequence * reload_GenomicDB(ComplexSequence * last,GenomicDB * gendb,int * return_status) { ComplexSequence * cs; Sequence * seq; Genomic *temp; Genomic * gen; /** NB - notice that we don't do silly things with free's. Maybe we should **/ if( gendb->is_single_seq == TRUE ) { if( gendb->done_forward == TRUE ) { *return_status = DB_RETURN_OK; gendb->done_forward = FALSE; return hard_link_ComplexSequence(gendb->rev); } else { *return_status = DB_RETURN_END; return NULL; } } /** standard database **/ /** free Complex Sequence **/ if ( last != NULL ) { free_ComplexSequence(last); } if( gendb->done_forward == TRUE ) { if( gendb->current == NULL ) { warn("A bad internal genomic db error - unable to find current sequence in db reload"); *return_status = DB_RETURN_ERROR; return NULL; } temp = reverse_complement_Genomic(gendb->current); if( temp == NULL ) { warn("A bad internal genomic db error - unable to reverse complements current"); *return_status = DB_RETURN_ERROR; return NULL; } cs = evaluate_ComplexSequence_Genomic(temp,gendb->cses,0,gendb->repeat_in_cds_score); if( cs == NULL ) { warn("A bad internal genomic db error - unable to make complex sequence in db reload"); *return_status = DB_RETURN_ERROR; return NULL; } free_Genomic(temp); gendb->done_forward = FALSE; return cs; } /* otherwise we have to get a new sequence */ seq = reload_SequenceDB(NULL,gendb->sdb,return_status); if( seq == NULL || *return_status == DB_RETURN_ERROR || *return_status == DB_RETURN_END ) { return NULL; /** error already reported **/ } uppercase_Sequence(seq); /* check dna status. We assumme someone knows what he is doing when he makes a genomic db!*/ if( seq->type != SEQUENCE_DNA) { warn("Sequence from %s data entry doesn't look like DNA. Forcing it to",seq->name); } force_to_dna_Sequence(seq,1.0,NULL); if( force_to_dna_Sequence(seq,0.1,NULL) == FALSE ) { if( gendb->error_handling == GENDB_READ_THROUGH ) { warn("Unable to map %s sequence to a genomic sequence, but ignoring that for the moment...",seq->name); free_Sequence(seq); return reload_GenomicDB(NULL,gendb,return_status); } else { warn("Unable to map %s sequence to a genomic sequence. Failing",seq->name); *return_status = DB_RETURN_ERROR; return NULL; } } gen = Genomic_from_Sequence_Nheuristic(seq,gendb->length_of_N); cs = evaluate_ComplexSequence_Genomic(gen,gendb->cses,0,gendb->repeat_in_cds_score); if( cs == NULL ) { if( gendb->error_handling == GENDB_READ_THROUGH ) { warn("Unable to map %s sequence to a genomic sequence, but ignoring that for the moment...",seq->name); free_Sequence(seq); return reload_GenomicDB(NULL,gendb,return_status); } else { warn("Unable to map %s sequence to a genomic sequence. Failing",seq->name); *return_status = DB_RETURN_ERROR; return NULL; } } gendb->current = free_Genomic(gendb->current); gendb->current = gen; gendb->done_forward= TRUE; return cs; }
int main(int argc,char ** argv) { Sequence * query; Sequence * target; CompMat * comp; char * comp_file; int gap = (12); int ext = (2); int a = 120; int b = 10; int c = 3; ComplexSequence * query_cs; ComplexSequence * target_cs; ComplexSequenceEvalSet * evalfunc; boolean show_label_output = FALSE; boolean show_fancy_output = FALSE; boolean use_abc = FALSE; PackAln * pal; AlnBlock * alb; DPRunImpl * dpri = NULL; /* * Process command line options * -h or -help gives us help * -g for gap value (an int) - rely on commandline error processing * -e for ext value (an int) - rely on commandline error processing * -m for matrix (a char) * -l - label output * -f - fancy output * * * Use calls to commandline.h functions * */ if( strip_out_boolean_argument(&argc,argv,"h") == TRUE || strip_out_boolean_argument(&argc,argv,"-help") == TRUE) { show_help(stdout); exit(1); } dpri = new_DPRunImpl_from_argv(&argc,argv); if( dpri == NULL ) { fatal("Unable to build DPRun implementation. Bad arguments"); } show_label_output = strip_out_boolean_argument(&argc,argv,"l"); show_fancy_output = strip_out_boolean_argument(&argc,argv,"f"); /** if all FALSE, set fancy to TRUE **/ if( show_label_output == FALSE ) show_fancy_output = TRUE; (void) strip_out_integer_argument(&argc,argv,"g",&gap); (void) strip_out_integer_argument(&argc,argv,"e",&ext); (void) strip_out_integer_argument(&argc,argv,"a",&a); (void) strip_out_integer_argument(&argc,argv,"b",&b); (void) strip_out_integer_argument(&argc,argv,"c",&c); use_abc = strip_out_boolean_argument(&argc,argv,"abc"); comp_file = strip_out_assigned_argument(&argc,argv,"m"); if( comp_file == NULL) comp_file = "blosum62.bla"; if( argc != 3 ) { warn("Must have two arguments for sequence 1 and sequence 2 %d",argc); show_help(stdout); exit(1); } /* * Read in two sequences */ if( (query=read_fasta_file_Sequence(argv[1])) == NULL ) { fatal("Unable to read the sequence in file %s",argv[1]); } if( (target=read_fasta_file_Sequence(argv[2])) == NULL ) { fatal("Unable to read the sequence in file %s",argv[2]); } /* * Open a blosum matrix. This will be opened from WISECONFIGDIR * or WISEPERSONALDIR if it is not present in the current directory. */ comp = read_Blast_file_CompMat(comp_file); if( comp == NULL ) { fatal("unable to read file %s",comp_file); } /* if abc - factor up matrix! */ if( use_abc == TRUE ) { factor_CompMat(comp,10); } /* * Make an alignment. I don't care about the implementation: * hand it over to sw_wrap function to do it * */ if( use_abc ) { evalfunc = default_aminoacid_ComplexSequenceEvalSet(); query_cs = new_ComplexSequence(query,evalfunc); if( query_cs == NULL ) fatal("Cannot build cs objects!"); target_cs = new_ComplexSequence(target,evalfunc); if( target_cs == NULL ) fatal("Cannot build cs objects!"); pal = PackAln_bestmemory_abc(query_cs,target_cs,comp,-a,-b,-c,NULL,dpri); alb = convert_PackAln_to_AlnBlock_abc(pal); free_ComplexSequence(query_cs); free_ComplexSequence(target_cs); } else { alb = Align_Sequences_ProteinSmithWaterman(query,target,comp,-gap,-ext,dpri); } /* * show output. If multiple outputs, divide using // */ if( show_label_output == TRUE ) { show_flat_AlnBlock(alb,stdout); puts("//\n"); } if( show_fancy_output == TRUE ) { write_pretty_seq_align(alb,query,target,15,50,stdout); puts("//\n"); } /* * Destroy the memory. */ free_Sequence(query); free_Sequence(target); free_CompMat(comp); free_AlnBlock(alb); return 0; }
int main(int argc,char ** argv) { Sequence * query; Sequence * target; ComplexSequence * query_cs; ComplexSequence * target_cs; ComplexSequenceEvalSet * evalfunc; CompMat * comp; char * comp_file; int gap = (12); int ext = (2); boolean show_raw_output = FALSE; boolean show_label_output = FALSE; boolean show_fancy_output = FALSE; boolean has_outputted = FALSE; PackAln * pal; AlnBlock * alb; /* * Process command line options * -h or -help gives us help * -g for gap value (an int) - rely on commandline error processing * -e for ext value (an int) - rely on commandline error processing * -m for matrix (a char) * -r - raw matrix output * -l - label output * -f - fancy output * * * Use calls to commandline.h functions * */ if( strip_out_boolean_argument(&argc,argv,"h") == TRUE || strip_out_boolean_argument(&argc,argv,"-help") == TRUE) { show_help(stdout); exit(1); } show_raw_output = strip_out_boolean_argument(&argc,argv,"r"); show_label_output = strip_out_boolean_argument(&argc,argv,"l"); show_fancy_output = strip_out_boolean_argument(&argc,argv,"f"); /** if all FALSE, set fancy to TRUE **/ if( show_raw_output == FALSE && show_label_output == FALSE ) show_fancy_output = TRUE; (void) strip_out_integer_argument(&argc,argv,"g",&gap); (void) strip_out_integer_argument(&argc,argv,"e",&ext); comp_file = strip_out_assigned_argument(&argc,argv,"m"); if( comp_file == NULL) comp_file = "blosum62.bla"; if( argc != 3 ) { warn("Must have two arguments for sequence 1 and sequence 2 %d",argc); show_help(stdout); exit(1); } /* * Read in two sequences */ if( (query=read_fasta_file_Sequence(argv[1])) == NULL ) { fatal("Unable to read the sequence in file %s",argv[1]); } if( (target=read_fasta_file_Sequence(argv[2])) == NULL ) { fatal("Unable to read the sequence in file %s",argv[2]); } /* * Open a blosum matrix. This will be opened from WISECONFIGDIR * or WISEPERSONALDIR if it is not present in the current directory. */ comp = read_Blast_file_CompMat(comp_file); if( comp == NULL ) { fatal("unable to read file %s",comp_file); } /* * Convert sequences to ComplexSequences: * To do this we need an protein ComplexSequenceEvalSet * */ evalfunc = default_aminoacid_ComplexSequenceEvalSet(); query_cs = new_ComplexSequence(query,evalfunc); if( query_cs == NULL ) { fatal("Unable to make a protein complex sequence from %s",query->name); } target_cs = new_ComplexSequence(target,evalfunc); if( target_cs == NULL ) { fatal("Unable to make a protein complex sequence from %s",target->name); } /* * Make an alignment. I don't care about the implementation: * If the sequences are small enough then it should use explicit memory. * Long sequences should use divide and conquor methods. * * Calling PackAln_bestmemory_ProteinSW is the answer * This function decides on the best method considering the * memory and changes accordingly. It frees the matrix memory * at the end as well. * */ pal = PackAln_bestmemory_ProteinSW(query_cs,target_cs,comp,-gap,-ext,NULL); if( pal == NULL ) { fatal("Unable to make an alignment from %s and %s",query->name,target->name); } /* * ok, make other alignment forms, and be ready to show */ alb = convert_PackAln_to_AlnBlock_ProteinSW(pal); /* * show output. If multiple outputs, divide using // */ if( show_raw_output == TRUE ) { show_simple_PackAln(pal,stdout); puts("//\n"); } if( show_label_output == TRUE ) { show_flat_AlnBlock(alb,stdout); } if( show_fancy_output == TRUE ) { write_pretty_seq_align(alb,query,target,15,50,stdout); puts("//\n"); } /* * Destroy the memory. */ free_Sequence(query); free_Sequence(target); free_CompMat(comp); free_ComplexSequence(query_cs); free_ComplexSequence(target_cs); free_PackAln(pal); free_AlnBlock(alb); return 0; }