Sequence * init_SequenceDB(SequenceDB * sdb,int * return_status) { sdb->current_source = 0; load_next_fs_SequenceDB(sdb); return reload_SequenceDB(NULL,sdb,return_status); }
ThreeStateModel * read_TSM_ThreeStateDB(ThreeStateDB * mdb,int * return_status) { ThreeStateModel * tsm; Protein * pro; Sequence * seq; if( mdb->hmm_model_end != -1 && mdb->current_no == mdb->hmm_model_end ) { *return_status = DB_RETURN_END; return NULL; } mdb->current_no++; switch( mdb->dbtype ) { case TSMDB_SINGLE : *return_status = DB_RETURN_END; if( mdb->single->rm == NULL ) { warn("Threestate model without an internal random model!"); mdb->single->rm = hard_link_RandomModel(mdb->rm); } return hard_link_ThreeStateModel(mdb->single); case TSMDB_HMMER1PFAM : tsm= read_next_TSM_PfamHmmer1DB(mdb->phdb,return_status); set_startend_policy_ThreeStateModel(tsm,mdb->type,30,0.2); return tsm; case TSMDB_PROTEIN : if( mdb->seq_cache != NULL ) { /* just after an open. Should actually use this sequence, and flush the cache */ pro = Protein_from_Sequence(hard_link_Sequence(mdb->seq_cache)); mdb->seq_cache = free_Sequence(mdb->seq_cache); *return_status = DB_RETURN_OK; } else { /* reload a sequence from a database */ seq = reload_SequenceDB(NULL,mdb->sdb,return_status); /* exit now if error */ if( *return_status == DB_RETURN_ERROR ) { return NULL; /* might have leaked memory. Ugh! */ } /* if we get NULL... for the moment, silent flag end */ if( seq == NULL ) { *return_status = DB_RETURN_END; return NULL; } pro = Protein_from_Sequence(seq); } if( pro == NULL ) { warn("Could not convert sequence to a protein. Exiting!"); *return_status = DB_RETURN_ERROR; return NULL; } /* convert protein to threestatemodel */ tsm = ThreeStateModel_from_half_bit_Sequence(pro,mdb->comp,mdb->rm,mdb->gap,mdb->ext); if( tsm == NULL ) { warn("Could not convert protein to threestatemode. Exiting!"); free_Protein(pro); *return_status = DB_RETURN_ERROR; return NULL; } /* DB status already set by seqdb */ return tsm; case TSMDB_GENERIC : tsm = ((*mdb->reload_generic)(mdb,return_status)); if( tsm == NULL ) { return NULL; /* means end of database */ } set_startend_policy_ThreeStateModel(tsm,mdb->type,30,0.2); return tsm; default : warn("Got an unrecognisable tsm db type in read-load"); return NULL; } }
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; }