ComplexSequence * init_cDNADB(cDNADB * cdnadb,int * return_status) { ComplexSequence * cs; Sequence * seq; if( cdnadb->is_single_seq == TRUE) { *return_status = DB_RETURN_OK; cdnadb->done_forward = TRUE; return hard_link_ComplexSequence(cdnadb->forw); } /* is a seq db */ seq = init_SequenceDB(cdnadb->sdb,return_status); if( seq == NULL || *return_status == DB_RETURN_ERROR || *return_status == DB_RETURN_END ) { return NULL; /** error already reported **/ } if( force_to_dna_Sequence(seq,cdnadb->error_tol,NULL) == FALSE ) { warn("first sequence below error level, have to fail at the moment. Ooops..."); free_Sequence(seq); *return_status = DB_RETURN_ERROR; return NULL; } cdnadb->current = seq; cdnadb->done_forward = TRUE; cs = new_ComplexSequence(seq,cdnadb->cses); if( cs == NULL ) { warn("Cannot make initial ComplexSequence. Unable to error catch this. Failing!"); *return_status = DB_RETURN_ERROR; return NULL; } return cs; }
ComplexSequence * init_GenomicDB(GenomicDB * gendb,int * return_status) { ComplexSequence * cs; Sequence * seq; if( gendb->is_single_seq == TRUE) { *return_status = DB_RETURN_OK; gendb->done_forward = TRUE; return hard_link_ComplexSequence(gendb->forw); } /* is a seq db */ seq = init_SequenceDB(gendb->sdb,return_status); if( seq == NULL || *return_status == DB_RETURN_ERROR || *return_status == DB_RETURN_END ) { return NULL; /** error already reported **/ } /* 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); /* map to Genomic on length of N buiness */ gendb->current = Genomic_from_Sequence_Nheuristic(seq,gendb->length_of_N); gendb->done_forward = TRUE; cs = evaluate_ComplexSequence_Genomic(gendb->current,gendb->cses,0,gendb->repeat_in_cds_score); if( cs == NULL ) { warn("Cannot make initial ComplexSequence. Unable to error catch this. Failing!"); *return_status = DB_RETURN_ERROR; return NULL; } return cs; }
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; }
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; }