int indicate_intron_used(GenomeEvidenceSet * set,AlnBlock * alb) { AlnColumn * alc; int i; int j; int has_used = 0; for(alc=alb->start;alc!=NULL;alc=alc->next ) { if( strstartcmp(alc->alu[1]->text_label,"5SS") == 0 ) { for(i=0;i<set->len;i++) { auto EstEvidence * evi; evi = (EstEvidence*) set->geu[i]->data; for(j=0;j<evi->len;j++) { if( abs(evi->exon[i]->end - alc->alu[1]->start) < 4 ) { /* this is used */ if( evi->exon[i]->used != 1 ) { evi->exon[i]->used = 1; has_used = 1; } } } } } } return has_used; }
CompProb * read_Blast_CompProb(FILE * ifp) { char buffer[MAXLINE]; int alphabet[MAXLINE]; char * runner; int len; int linenum; int row; CompProb * out; /*** Skip over # lines... read first line: is alphabet ie A R T G .... * ***/ while( fgets(buffer,MAXLINE,ifp) != NULL) if( buffer[0] != '#') break; /** loop over line, getting letters: warn if longer than one, or not a letter **/ for(len=0,runner=strtok(buffer,spacestr);runner != NULL;runner=strtok(NULL,spacestr)) { if( *runner == '*' ) break; /* end column */ if( !isalpha((int)*runner) || strlen(runner) > 1 ) { warn("In read Blast comp mat, probably an error: trying to interpret [%s] as an amino acid",runner); return NULL; } alphabet[len++] = toupper((int)*runner) -'A'; } out = blank_CompProb(); linenum = 0; /** get len lines, each line, get len numbers and put them away **/ while( fgets(buffer,MAXLINE,ifp) != NULL ) { if( strstartcmp(buffer,"//") == 0 ) break; if( linenum >= len ) break; for(runner=strtok(buffer,spacestr),row = 0;runner != NULL && row < len;runner=strtok(NULL,spacestr),row++) { if( is_double_string(runner,&out->comp[alphabet[linenum]][alphabet[row]]) == FALSE ) { warn("In read Blast comp prob, probably an error: trying to interpret [%s] as a number ... continuing",runner); } } linenum++; } return out; }
Method * read_Method_line(char * line,FILE * ifp) { Method * out; char buffer[MAXLINE]; char * temp; MethodArg * m; if( strstartcmp(line,"method") != 0 ) { warn("Attempting to read a method with no method line!"); return NULL; } out = Method_alloc_std(); out->logical = second_word_alloc(line,spacestr); while( fgets(buffer,MAXLINE,ifp) != NULL ) { chop_newline(buffer); if( strstartcmp(buffer,"end") == 0 ) break; else if( strstartcmp(buffer,"map") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->real != NULL ) { warn("For method [%s], second map replacing [%s] with [%s]",out->logical,out->real,temp); ckfree(out->real); } out->real = temp; } else if ( strstartcmp(buffer,"arg") == 0 ) { m = MethodArg_from_line(buffer); if( m == NULL ) { warn("Got a NULL method arg. Yikes!"); } else { add_Method(out,m); } } else if ( strstartcmp(buffer,"return") == 0 ) { out->retstr = second_word_alloc(buffer,spacestr); } else { warn("In method [%s] did not understand %s",out->logical,buffer); } } return out; }
boolean read_into_MethodTypeSet(MethodTypeSet * mts,FILE * ifp) { char buffer[MAXLINE]; Method * me; Type * ty; Input * in; while( fgets(buffer,MAXLINE,ifp) != NULL) { chop_newline(buffer); if( buffer[0] == '#' || strwhitestartcmp(buffer,"#",spacestr) == 0 ) continue; if( only_whitespace(buffer,spacestr) == TRUE) continue; if( strstartcmp(buffer,"method") == 0 ) { if( (me=read_Method_line(buffer,ifp)) == NULL ) { warn("Unable to read method in line [%s] ",buffer); } else { add_me_MethodTypeSet(mts,me); } } else if ( strstartcmp(buffer,"type") == 0 ) { if( (ty=read_Type_line(buffer,ifp)) == NULL ) { warn("Unable to read type in line [%s] ",buffer); } else { add_ty_MethodTypeSet(mts,ty); } } else if ( strstartcmp(buffer,"input") == 0 ) { if( (in = read_Input_line(buffer,ifp)) == NULL ) { warn("Unable to read type in line [%s]",buffer); } else { add_in_MethodTypeSet(mts,in); } } else { warn("In reading only method/types got an impossible line [%s]",buffer); } } return TRUE; }
MethodArg * MethodArg_from_line(char * line) { MethodArg * out; if( strstartcmp(line,"arg") != 0 ) { warn("Attempting to read a method argument with no arg line!"); return NULL; } out = MethodArg_alloc(); out->type = second_word_alloc(line,spacestr); return out; }
SequenceDB * read_SequenceDB_line(char * line,FILE * ifp) { SequenceDB * out = NULL; FileSource * fs; char buffer[MAXLINE]; char * runner; if( strstartcmp(line,"seqdb") != 0 ) { warn("Attempting to read a sequence line without a seqdb start"); return NULL; } runner = strtok(line,spacestr); runner = strtok(line,spacestr); if( runner == NULL ) { out->name = stringalloc("UnNamedDatabase"); } else out->name = stringalloc(runner); out = SequenceDB_alloc_std(); while( fgets(buffer,MAXLINE,ifp) != NULL ){ if( strstartcmp(buffer,"#") == 0 ) continue; if( strstartcmp(buffer,"end") == 0 ) break; fs = FileSource_from_line(buffer); if( fs != NULL ) add_SequenceDB(out,fs); } return out; }
void listen_and_respond_SimpleBufferedServer(SimpleBufferedServer * sbs) { int i; char buf[1024]; int ret; int len; int curr; int ms; int new_socket; listen(sbs->socket, 5); while( 1 ) { fprintf(stderr,"blocking at accept...\n"); ms = accept(sbs->socket, 0, 0); fprintf(stderr,"Accepted socket...\n"); read(ms,buf,sizeof(buf)); fprintf(stderr,"Read buffer...\n"); if( strstartcmp(buf,"<WISE2-START-SIMPLE-STREAM>") == 0 ) { for(i=0;i<sbs->len;i++) { fprintf(stderr,"Going to send position %d\n",i); len = strlen(sbs->buffer[i]); curr = 0; while( curr < len ) { fprintf(stderr,"Going to send at position %d\n",curr); ret = write(ms,sbs->buffer[i]+curr,len-curr); if( ret == -1 ) { warn("error sending with %d\n",errno); } fprintf(stderr,"...sent at position %d, sent %d bytes [%.6s]\n",curr,ret,sbs->buffer[i]); if( ret+curr >= len ) { break; } curr += ret; sleep(2); } } buf[0] = '\0'; write(ms,buf,1); close(ms); } else { fatal("Bad client initialisation string...%s\n",buf); } } }
ModuleInfo * read_ModuleInfo_line(char * line,FILE * ifp) { ModuleInfo * out; char buffer[MAXLINE]; if( strstartcmp(line,"%module") != 0 ) { warn("Attempting to read module help with line starting [%30s] not %module",line); return NULL; } out = ModuleInfo_alloc(); out->ft = read_Ftext(buffer,MAXLINE,ifp,"%",fgets); return out; }
void debug_genomewise(AlnBlock * alb,GenomeEvidenceSet * ges,CodonTable * ct,Sequence * gen,FILE * ofp) { AlnColumn *alc; int cstart; for(alc=alb->start;alc != NULL;alc = alc->next ) { fprintf(ofp,"%4d %12s %12s [%3d][%5d %5d] ",alc->alu[1]->score[0],alc->alu[0]->text_label,alc->alu[1]->text_label,alc->alu[0]->start,alc->alu[1]->start+1,alc->alu[1]->end); if( strstartcmp(alc->alu[1]->text_label,"CODON") == 0 ) { cstart = alc->alu[1]->start+1; fprintf(ofp,"%c%c%c %c\n",gen->seq[cstart],gen->seq[cstart+1],gen->seq[cstart+2],aminoacid_from_seq(ct,gen->seq+cstart)); } else { fprintf(ofp,"\n"); } } }
boolean user_DebugMatrix(DebugMatrix * de) { char buffer[MAXLINE]; char ** base; char ** brk; FILE * in; FILE * out; DebugBreakPoint * bp; assert(de); assert(de->in); assert(de->out); in = de->in; out = de->out; /* set reset to FALSE */ de->reset = 0; fprintf(out,"Entering dynamite debugger. Type help for help\n"); while(1) { fprintf(out,"Dy %5d:%5d max: %d >",de->currenti,de->currentj,de->max_score); fgets(buffer,MAXLINE,in); if( strstartcmp(buffer,"quit") == 0 ) { exit(1); } if( strstartcmp(buffer,"show") == 0 ) { show_DebugMatrix(de,buffer); continue; } if( strstartcmp(buffer,"run") == 0 ) { /* return to calling function */ return 0; } if( strstartcmp(buffer,"break") == 0 ) { base = brk = breakstring(buffer,spacestr); brk++; if( *brk == NULL || *(brk+1) == NULL ) { fprintf(out,">>>> break must have i j positions\n"); continue; } else { bp = DebugBreakPoint_alloc(); bp->type = MDBP_Cursor; /* reset cursor positions */ if( is_integer_string(*brk,&bp->posi) == FALSE ) { fprintf(out,">>>> i position not an integer.\n"); } brk++; if( is_integer_string(*brk,&bp->posj) == FALSE ) { fprintf(out,">>>> j position not an integer.\n"); } fprintf(out,"Adding cursor break point %d,%d\n",bp->posi,bp->posj); add_bp_DebugMatrix(de,bp); } ckfree(base); continue; } if( strstartcmp(buffer,"set") == 0 ) { base = brk = breakstring(buffer,spacestr); brk++; if( *brk == NULL || *(brk+1) == NULL ) { fprintf(out,">>>> set must have i j positions\n"); } else { /* reset cursor positions */ if( is_integer_string(*brk,&de->currenti) == FALSE ) { fprintf(out,">>>> i position not an integer.\n"); } if( is_integer_string(*brk,&de->currenti) == FALSE ) { fprintf(out,">>>> j position not an integer.\n"); } } de->reset = 1; ckfree(base); continue; } } }
boolean do_a_file(char * sourcename,MethodTypeSet * mts,boolean write_html_now,int c_protection_level,boolean should_hard_link,boolean should_warn_undocs,boolean addnumbers,char * package,APIpara * api_para,FailureType * ft) { FILE * ifp = NULL; DYNFILE * dfp = NULL; char * outputname = NULL; char * runner; char * rt; char c; char buffer[MAXLINE]; Dynamite * dyn; ModuleFunctionList * mfl = NULL; boolean end_of_file; ParseError pfail; int no; int i; #ifdef COMPUGEN OneModel * om; #endif /* Read first block */ /* read_plain_scan_and_replace("test.kar"); */ /*** open source ***/ ifp = openfile(sourcename,"r"); if( ifp == NULL ){ warn("Could not open [%s] as Dynamite source",sourcename); return FALSE; } open_watch_file(ifp); parsed_file = stringalloc(sourcename); push_errormsg_stack_call(parse_line_error); /*** open DYNFILE ***/ runner = strrchr(sourcename,'.'); if( runner == NULL ) { warn("Source %s has no . character. Not critical, but worrying...",sourcename); runner = sourcename + strlen(sourcename); } /*** hard coding debug for the moment ***/ c = *runner; *runner = '\0'; if( (dfp = open_std_no_html_dynfile(sourcename)) == NULL) { warn("Could not open DYNFILE system for output %s\n",outputname); goto error; } dfp->code_debug_level = c_protection_level; dfp->should_hard_link = should_hard_link; if( package != NULL ) { dfp->package_name = stringalloc(package); } *runner = c; /* Skip to %{ */ while( (rt=get_watched_line(buffer,MAXLINE,ifp)) != NULL) { if(strstartcmp(buffer,"%{") == 0) break; } if( rt == NULL) { log_full_error(WARNING,0,"Exhausted dynamite source [%s] without reading any blocks - consult man/help pages!",sourcename); goto error; } /* * Header region * Dump until next block %} * */ while( (rt=get_watched_line(buffer,MAXLINE,ifp)) != NULL) { if(strstartcmp(buffer,"%}") == 0) break; fputs(buffer,dfp->head); } if( rt == NULL) { warn("had only header information in dynamite file, no close header %}"); goto error; } /* Load in Dynamite */ dyn = read_Dynamite(ifp,"%{",&end_of_file,mts); if( dyn == NULL ) { log_full_error(WARNING,0,"Unable to read Dynamite models. Parse error."); goto error; } /* probably should check it now! */ pop_errormsg_stack(); pfail = (PERR_ARG_MISTYPE | PERR_ARG_NUM_MIS | PERR_SYNTAX); if( prepare_Dynamite(dyn,mts,dpi->dycw,pfail) == FALSE ) { log_full_error(FATAL,0,"A Dynamite blueprint fails semantic checks. Please refer to previous errors for the precise problem"); goto error; } if( tele_file != NULL ) { for(i=0;i<dyn->len;i++) { if( dyn->list[i]->type == DYNAMITETYPEGENERICMATRIX ) { write_Telegraph_grammar((GenericMatrix*)dyn->list[i]->data,tele_file); } } } /*** writes out user functions ***/ if( end_of_file == FALSE) { push_errormsg_stack_call(parse_line_error); mfl = parse_function_section(ifp,dfp,ft,addnumbers); pop_errormsg_stack(); } else { write_Dynamite_minimal_func(dfp); mfl = NULL; } /*** write out the header ***/ write_Dynamite_header(dyn,dpi,dfp); /*** writes out dynamite functions ***/ /*** should write line number now ***/ fprintf(dfp->func,"# line %d \"%s.c\"\n",dfp->funcpos,dfp->sourceroot); dfp->funcpos++; write_Dynamite_func(dyn,mfl,dpi,dfp); #ifdef COMPUGEN if( dyn->len > 0 && dyn->list[0]->type == DYNAMITETYPEGENERICMATRIX && dpi->doone == TRUE) { om = OneModel_from_GenericMatrix((GenericMatrix *) dyn->list[0]->data); if( om == NULL ) { warn("Cannot built Compugen port!"); } else { write_cugen_funcs(om,mts,dfp); } } #endif positionify_DYNFILE(dfp); /* check errors... could fail here */ if( have_got_unknown_func_DYNFILE(dfp,&no,should_warn_undocs) == TRUE) { *ft = (*ft | FailureType_dyc_UF); warn("You have %d undocumented functions",no); } if( should_make_API(api_para) == TRUE ) make_API(dfp,dyn,api_para); place_declarations_DYNFILE(dfp,FO_CUI_POSITION); /*** close Dynfile ***/ if(dyn != NULL) free_Dynamite(dyn); if( mfl != NULL ) free_ModuleFunctionList(mfl); close_dynfile(dfp); close_watch_file(); fclose(ifp); return TRUE; error : if( ifp != NULL) { fclose(ifp); close_watch_file(); } if( dfp != NULL) close_dynfile(dfp); return FALSE; }
Gene * read_EMBL_feature_Gene(char * buffer,int maxlen,FILE * ifp) { Gene * gene; Transcript * tr; Translation * ts; Exon * exon; char * runner; char * base; char * next; int i; int exon_start[MAX_EMBL_EXON_PARSE]; int exon_end[MAX_EMBL_EXON_PARSE]; int number; int exon_no = 0; int isstart = 1; int is_complement = 0; int is_cds = 0; int break_at_end = 0; if( strstartcmp(buffer,"FT") != 0 ) { warn("passed in a bad line [%s] to be used for feature table parsing",buffer); return NULL; } if( (runner=strtok(buffer+2,spacestr)) == NULL ) { warn("Bad embl feature line [%s]",buffer); return NULL; } if( strcmp(runner,"CDS") != 0 && strcmp(runner,"mRNA") != 0 ) { warn("passed in a feature line to read_EMBL_feature_Gene with a %s tag. This only handles CDS and mRNA tags",runner); return NULL; } if( strcmp(runner,"CDS") == 0 ) { is_cds = TRUE; } runner = strtok(NULL,spacestr); if( runner == NULL ) { warn("Bad embl feature line [%s]",buffer); return NULL; } if( strstartcmp(runner,"complement") == 0 ) { runner = strchr(runner,'('); if( runner == NULL) { warn("Could not find bracket on EMBL feature complement line"); return NULL; } is_complement = 1; runner++; } if( strstartcmp(runner,"join") == 0 ) { runner = strchr(runner,'('); runner++; } else if( isdigit((int)*runner) || *runner == '<' ) { /** ok - starts with the numbers. We'll cope!**/ } else { warn("Expecting a join statement, got a [%s]",runner); return NULL; } /*** ok, now the major number loop ***/ for(;;) { base= runner; for(;*runner && *runner != ')' && *runner != '.' && *runner != ',' && *runner != '>' && !isspace((int)*runner);runner++) ; /*fprintf(stderr,"Got a runner of %s\n ",runner); */ if( *runner == '\0' ) next = runner; else next = runner+1; if( *runner == ')' ) { break_at_end = TRUE; /* out of reading exons */ } *runner='\0'; if( strstartcmp(base,"complement(") == 0 ) { is_complement = TRUE; for(;*base != '(';base++) ; base++; break_at_end = FALSE; /* we found an bracket too early! */ } if( is_integer_string(base,&number) == FALSE ) { warn("Got a non integer [%s] in the middle of a join statement in EMBL parsing",runner); return NULL; } /** put this number away **/ if( isstart ) { exon_start[exon_no] = number; isstart = 0; } else { exon_end[exon_no++] = number; isstart = 1; } if( break_at_end == TRUE) break; for(runner=next;*runner && (*runner == '.' || isspace((int)*runner));runner++) ; if( *runner == '\0' ) { if( next_feature_tab_line(buffer,maxlen,ifp) == FALSE) { warn("In the middle of getting a join statement, got a [%s]. Yuk!",buffer); return NULL; } if( !isdigit((int)buffer[0]) && buffer[0] != '.' && buffer[0] != ',') { /*** ok - sometimes people very boring end things in here ***/ /* warn("In the middle of getting a join statement, got a [%s]. Ugh!",buffer); */ break; } runner = buffer; } } if( isstart == 0 ) { warn("I have read an uneven number of start-end points in the exon thing. Yuk!"); return NULL; } /** runner should now be on bracket **/ if( is_complement == 1 ) { /** ok . should be another bracket. Do we care? **/ } gene = Gene_alloc_len(1); tr = Transcript_alloc_len(exon_no); add_Gene(gene,tr); tr->parent = gene; if( is_complement == 1 ) { gene->start = exon_end[exon_no-1]-1; gene->end = exon_start[0] -1; for(i=exon_no -1;i >= 0;i--) { exon = Exon_alloc(); exon->start = (gene->start+1) - exon_end[i]; exon->end = (gene->start+1) - exon_start[i] +1; add_ex_Transcript(tr,exon); } } else { gene->start = exon_start[0] -1; gene->end = exon_end[exon_no-1] -1; for(i=0;i<exon_no;i++) { exon = Exon_alloc(); exon->start = exon_start[i] - (gene->start+1); exon->end = exon_end[i] - (gene->start+1)+1; add_ex_Transcript(tr,exon); } } if( is_cds == TRUE ) { ts = Translation_alloc(); ts->start = 0; ts->end = length_Transcript(tr); ts->parent = tr; add_Transcript(tr,ts); } /*** read the rest of this feature ***/ while( next_feature_tab_line(buffer,maxlen,ifp) == TRUE) ; return gene; }
FuncInfo * read_FuncInfo_line(char * line,FILE * ifp) { FuncInfo * out; ArgInfo * ari; char buffer[MAXLINE]; char * runner; if( strstartcmp(line,"%func") != 0 ) { warn("Attempting to read in-line function help with line starting [%30s] not %func",line); return NULL; } out = FuncInfo_alloc_std(); out->functype = FI_CALLABLE; out->ft = read_Ftext(buffer,MAXLINE,ifp,"%",get_watched_line); if( strstartcmp(buffer,"%%") == 0 ) return out; /*** could be in any order ***/ for(;;) { /* fprintf(stderr,"Looking at [%s]\n",buffer); */ if( feof(ifp) || ferror(ifp) ) { warn("End of file or file read error while in FuncInfo read. Not good!"); break; } else if ( strstartcmp(buffer,"%%") == 0 ) { break; } else if ( strstartcmp(buffer,"%simple") == 0 ) { if( (runner=strtok(buffer+7,spacestr)) == NULL ) { warn("Got a simple name specification, but no name!"); } else { out->simple = stringalloc(runner); } get_watched_line(buffer,MAXLINE,ifp); } else if( strstartcmp(buffer,"%arg") == 0) { while( get_watched_line(buffer,MAXLINE,ifp) != NULL ) { if( buffer[0] == '%' ) break; ari = read_ArgInfo_line(buffer); if( strcmp(ari->name,"return") == 0 ) { out->ret = ari; } else if( ari != NULL ) { add_FuncInfo(out,ari); } } } else if ( strstartcmp(buffer,"%short") == 0 ) { for(runner=buffer;*runner && !isspace(*runner);runner++) ; for(;*runner && isspace(*runner);runner++) ; out->sdesc=stringalloc(runner); get_watched_line(buffer,MAXLINE,ifp); } else if ( strstartcmp(buffer,"%type") == 0 ) { if( strstr(buffer,"call") != NULL ) { out->functype = FI_CALLABLE; } else if ( strstr(buffer,"int") != NULL ) { out->functype = FI_INTERNAL; } get_watched_line(buffer,MAXLINE,ifp); } else { warn("Cannot understand %% tag %20s\n",buffer); while( get_watched_line(buffer,MAXLINE,ifp) != NULL ) { if( buffer[0] == '%' ) break; } } if( buffer[0] == '%') continue; /*** back to for(;;) ***/ /* else */ warn("In funcinfo line, could not understand [%s], going to skip to next %% tag",buffer); while( get_watched_line(buffer,MAXLINE,ifp) != NULL ) { chop_newline(buffer); if( buffer[0] == '%' ) break; else { warn("Did not interpret line [%s]\n",buffer); } } } return out; }
ModuleFunctionList * parse_function_section(FILE * input,DYNFILE * dfp,FailureType * ft,boolean addnumbers) { ModuleFunctionList * out; boolean outoffunction=TRUE; char * name; boolean next_line_alloc = FALSE; boolean next_line_free = FALSE; char buffer[MAXLINE]; char * tempb; ModuleFunction * mf; FuncInfo * fi = NULL; out = ModuleFunctionList_alloc_std(); while( get_watched_line(buffer,MAXLINE,input) != NULL) { chop_newline(buffer); if( strstartcmp(buffer,"%}") == 0) break; if( strstartcmp(buffer,"%func") == 0 ) { /* fprintf(stderr,"Getting info line!\n"); */ fi = read_FuncInfo_line(buffer,input); fi->is_hand_written = TRUE; if( fi == NULL ) { warn("Unable to read function info line at %s. Probably going to give a parse error",buffer); } else add_DYNFILE(dfp,fi); continue; } if( outoffunction == TRUE ) { if( buffer[0] == '{' ) { outoffunction = FALSE; fputs_func_DYNFILE(buffer,dfp); continue; } /* fprintf(stderr,"Got here [%s]\n",buffer); */ if( buffer[0] == '\0' || isspace(buffer[0]) || strstartcmp(buffer,"static") == 0 || buffer[0] == '#' || buffer[0] == '/' || buffer[0] == '*' ) { next_line_alloc = next_line_free = FALSE; fputs_func_DYNFILE(buffer,dfp); continue; } /*** if the line starts with a ! we want to interpret it ***/ /*** as a dynamite specific tag ***/ if( strstartcmp(buffer,"!constructor") == 0 ) { next_line_alloc = TRUE; continue; } if( strstartcmp(buffer,"!deconstructor") == 0 ) { next_line_free = TRUE; continue; } if ( buffer[0] == '!' ) { next_line_alloc = next_line_free = FALSE; continue; } /*fprintf(stderr,"Got here again [%s]\n",buffer);*/ /*** ok this should be a function! ****/ if( next_line_alloc == TRUE || next_line_free == TRUE ) { tempb = stringalloc(buffer); name = parse_and_get_module_name_from_func(tempb,next_line_alloc); if(name == NULL) { warn("Function [%s] specified as cons/decons, but no module name parsed...",buffer); } else { if( (mf=get_ModuleFunction_from_name(out,name)) == NULL ) mf = new_ModuleFunction(out,name); if( next_line_alloc == TRUE ) { if( mf->has_cons == TRUE ) warn("Module %s already has a constructor... double overload!",name); else mf->has_cons = TRUE; } else { if( mf->has_decons == TRUE ) warn("Module %s already has a deconstructor... double overload",name); else mf->has_decons = TRUE; } ckfree(name); } ckfree(tempb); } /*** end of if cons/decons ***/ next_line_alloc = next_line_free = FALSE; /*** reconcile with fi if any ***/ if( fi != NULL ) { reconcile_FuncInfo_with_funcstr(fi,buffer); dfp->funcpos += show_eddystyle_FuncInfo(fi,dfp->func); /** already added to DYNFILE **/ } else { /* fprintf(stderr,"Using [%s] as an unknown function\n",buffer); */ fi = unknown_user_FuncInfo(buffer); /* fprintf(stderr,"Unknown function %s...\n",fi->name);*/ add_DYNFILE(dfp,fi); } /*** put #line compiler information ***/ /*** using global parsed file which is also used for errors... sort of yukky. ***/ if( addnumbers == TRUE) { fprintf(dfp->func,"# line %d \"%s\"\n",get_watched_linecount(),parsed_file); dfp->funcpos++; } /*** put line ***/ fi->line_in_c = dfp->funcpos; fi = NULL; fputs_func_DYNFILE(buffer,dfp); /*** put away function now ***/ /*** header information will be put away in dfp call ***/ } else { /*** actually inside a function ***/ if( buffer[0] == '}' ) outoffunction = TRUE; fputs_func_DYNFILE(buffer,dfp); } } return out; }
boolean reconcile_FuncInfo_with_funcstr(FuncInfo * fi,char * pass_str) { /** ok, stupid parsing for the moment **/ boolean ret = TRUE; char * runner; char * run2; char * arg; char ** base; char ** brk; char * fstr; int count; fstr = stringalloc(pass_str); if( fi->complete_name == NULL ) { fi->complete_name = stringalloc(fstr); } /** get the return type **/ if( strstartcmp(fstr,"const") == 0 ) { runner = fstr+5; for(;isspace(*runner);runner++) ; } else { runner = fstr; } if( strstartcmp(runner,"signed") == 0 ) { runner = fstr+6; for(;isspace(*runner);runner++) ; } if( strstartcmp(runner,"long") == 0 ) { runner = fstr+6; for(;isspace(*runner);runner++) ; } if( strstartcmp(runner,"struct") == 0 ) { runner = fstr+6; for(;isspace(*runner);runner++) ; } for(;isalnum(*runner) || *runner == '_' ;runner++) ; for(run2=runner;isspace(*runner);runner++) ; if( *runner == '*' ) { for(;*runner == '*';runner++) ; } else { runner = run2; } *runner = '\0'; if( fi->ret == NULL ) { fi->ret = ArgInfo_alloc(); fi->ret->name = stringalloc("return"); fi->ret->desc = stringalloc("Undocumented return value"); } fi->ret->type = stringalloc(fstr); /** got to the end of the return value **/ for(run2=runner+1;isspace(*run2);run2++) ; fi->stripped_return = stringalloc(run2); /** get the name of the function ***/ runner = strchr(run2,'(') ; if( runner == NULL ) { warn("reconciling function [%s] - no bracket!",pass_str); return FALSE; } arg = runner+1; *(runner) = '\0'; /** run2 now at the name **/ if( fi->name != NULL ) { if( strcmp(fi->name,run2) != 0 ) { warn("In reconciling function different names [%s] [%s]",fi->name,run2); } }else { fi->name = stringalloc(run2); } /*** now, process the argument list ***/ runner = arg + strlen(arg) -1; for(;runner > arg && *runner != ')';runner--) ; *runner = '\0'; base = brk = breakstring_protect(arg,",","()"); if( *brk != NULL && strcmp(*brk,"void") != 0 ) { for(count=0;*brk != NULL;brk++) { if( reconcile_FuncInfo_with_argstr(fi,*brk,count++) == FALSE ) ret = FALSE; } } ckfree(base); ckfree(fstr); sort_FuncInfo_by_position(fi); return ret; }
int css_select_into(dom_iter *walker, void *root, css_target *target, void **result, size_t n, int offset, int nest) { /* Iterate over all dom objects in root */ void *iter = root; while (iter) { css_target *filter; char *cmp; int ok; /* Update iterator */ (*walker->pick)(walker, iter); /* Cycle all filters until a test fails */ for (filter = target, ok = 1; (filter && ok); filter = filter->next) { ok = 0; /* Each test starts out in 'NOT PASSED' state */ switch (filter->rela) { /* If it's a relationship test, recurse */ case ' ': filter->rela = '&'; offset = css_select_into(walker, walker->kids, filter, result, n, offset, 1); filter->rela = ' '; return offset; break; case '>': filter->rela = '&'; offset = css_select_into(walker, walker->kids, filter, result, n, offset, 0); filter->rela = '>'; return offset; break; case '+': filter->rela = '&'; offset = css_select_into(walker, walker->next, filter, result, n, offset, 0); filter->rela = '+'; return offset; break; case '&': default: if (walker->filter) ok = (*walker->filter)(iter, filter); else { dom_iter* tx1 = iter; const char* tx2 = filter->name; cmp = (*walker->test)(tx1, tx2); switch (filter->type) { /* Take the test */ case '~': if (cmp && !strspacecmp(cmp, filter->value)) ok=1; break; case '|': if (cmp && !strstartcmp(cmp, filter->value)) ok=1; break; case '=': default: if (filter->value[0] == '*' || (cmp && !strcasecmp(cmp, filter->value))) ok=1; } } } } if (ok) { result[offset++] = iter; if (offset >= n) break; } if (!nest) break; /* Next object: */ iter = NULL; if (walker->kids) iter = walker->kids; else if (walker->next) iter = walker->next; else if (walker->parent) iter = walker->cousin; } result[offset] = NULL; return offset; }
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; }
boolean protdna_btc_display(AlnBlock * alb,char * protsequence,char * protname_in,int protoff,Sequence * dna,CodonTable * ct,int name,int main,btCanvas * btc,char (*match_central_line)(char,int,char),boolean multalign) { AlnColumn * alc; AlnColumn * alc_temp,*alc_endscore; int a_phase, d_phase; int intron_number = 1; int aln_score; int aln_num = 1; btPasteArea * btp; char tempbuf[2]; char protname[60]; char dnaname[60]; char dnatemp[4]; char protc; char transc; boolean is_reversed = FALSE; boolean issplit; if( strlen(protname_in) > name ) { info("Name %s is longer than allowed name block (%d). Truncating\n",protname_in,name); strncpy(protname,protname_in,name); protname[name] = '\0'; } else { strcpy(protname,protname_in); } if( strlen(dna->name) > name ) { info("Name %s is longer than allowed name block (%d). Truncating\n",dna->name,name); strncpy(dnaname,dna->name,name); dnaname[name] = '\0'; } else { strcpy(dnaname,dna->name); } if( dna->offset > dna->end ) { is_reversed = TRUE; } for(alc=alb->start;alc != NULL;) { if ( strcmp(alc->alu[1]->text_label,"END") == 0 ) break; /* end of alignment */ for(;alc != NULL && is_random_AlnColumn_genewise(alc) == TRUE;alc = alc->next) ; if( alc == NULL) break; /* end of alignment */ if( multalign == TRUE ) { /* get the end score */ for(aln_score = 0,alc_endscore=alc;alc_endscore->next != NULL;alc_endscore = alc_endscore->next) { if( is_random_AlnColumn_genewise(alc_endscore) == TRUE) break; aln_score += alc_endscore->alu[0]->score[0]; } /*aln_score += alc_endscore->alu[0]->score[0];*/ write_alignment_separator(btc,aln_num++,aln_score); } while( alc != NULL ) { write_name_start_stuff(btc,protname,protoff,dnaname,dna,name,alc); for(; alc != NULL;alc=alc->next ) { if( is_random_AlnColumn_genewise(alc) == TRUE ) break; if( strcmp(alc->alu[1]->text_label,"INSERT") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE) break; /* back to upper for, to place names and starts */ btp = get_paste_area_btCanvas(btc,1); paste_char_btPasteArea(btp,0,0,protsequence[alc->alu[0]->start+1],0); paste_char_btPasteArea(btp,0,2,'-',0); free_btPasteArea(btp); } else if ( strcmp(alc->alu[1]->text_label,"SEQUENCE_INSERTION") == 0 || strcmp(alc->alu[1]->text_label,"SEQUENCE_DELETION") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE) break; /* back to upper for, to place names and starts */ btp = get_paste_area_btCanvas(btc,1); if( strcmp(alc->alu[0]->text_label,"INSERT_STATE")== 0 ) { paste_char_btPasteArea(btp,0,0,'-',0); } else { paste_char_btPasteArea(btp,0,0,protsequence[alc->alu[0]->end],0); } sprintf(tempbuf,"%d",alc->alu[1]->end - alc->alu[1]->start); paste_char_btPasteArea(btp,0,3,tempbuf[0],0); paste_char_btPasteArea(btp,0,2,'!',0); free_btPasteArea(btp); } else if (strcmp(alc->alu[1]->text_label,"END") == 0 && strcmp(alc->alu[0]->text_label,"END") == 0) { break; /* end of alignment */ } else if ( strcmp(alc->alu[1]->text_label,"RANDOM_SEQUENCE") == 0 ) { break; } else if( strcmp(alc->alu[1]->text_label,"CODON") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE) break; /* back to upper for, to place names and starts */ btp = get_paste_area_btCanvas(btc,1); if( strcmp(alc->alu[0]->text_label,"INSERT_STATE")== 0 ) { write_codon_match(btp,'-',' ',alc->alu[1]->start+1,aminoacid_from_seq(ct,dna->seq+alc->alu[1]->start+1),dna->seq+alc->alu[1]->start+1); } else { write_codon_match(btp,protsequence[alc->alu[0]->end],(*match_central_line)(protsequence[alc->alu[0]->end],alc->alu[0]->score[0],aminoacid_from_seq(ct,dna->seq+alc->alu[1]->start+1)),alc->alu[1]->start+1,aminoacid_from_seq(ct,dna->seq+alc->alu[1]->start+1),dna->seq+alc->alu[1]->start+1); } free_btPasteArea(btp); continue; } else if ( strstartcmp(alc->alu[1]->text_label,"5SS") == 0 ) { /* * intron stuff. Figure out the start and end, * then place the 5'SS Central and End. * * If we can't fit in the intron, loop over * in this region before returning to higher loop. * */ if( strcmp(alc->alu[1]->text_label,"5SS_PHASE_0") == 0 ) { d_phase = 0; } else if ( strcmp(alc->alu[1]->text_label,"5SS_PHASE_1") == 0 ) { d_phase = 1; } else if ( strcmp(alc->alu[1]->text_label,"5SS_PHASE_2") == 0 ) { d_phase = 2; } else { warn("No no no. You have a non 0,1,2 phase intron (god knows how!). Not displaying it %s",alc->alu[1]->text_label); advance_line_btCanvas(btc); return FALSE; } alc_temp = alc->next; if( strcmp(alc_temp->alu[1]->text_label,"CENTRAL_INTRON") != 0 ) { warn("Bad news. I have found a 5SS in your alignment, but it is not followed by a central intron node. Don't like it!"); advance_line_btCanvas(btc); return FALSE; } for(alc_temp = alc_temp->next ;alc_temp != NULL && strstartcmp(alc_temp->alu[1]->text_label,"3SS") != 0;alc_temp = alc_temp->next) ; if( alc_temp == NULL ) { warn("Got to the end of the alignment in the middle of an intron from %s. Weird!",alc->alu[1]->text_label); advance_line_btCanvas(btc); return FALSE; } if( strcmp(alc_temp->alu[1]->text_label,"3SS_PHASE_0") == 0 ) { a_phase = 0; } else if ( strcmp(alc_temp->alu[1]->text_label,"3SS_PHASE_1") == 0 ) { a_phase = 1; } else if ( strcmp(alc_temp->alu[1]->text_label,"3SS_PHASE_2") == 0 ) { a_phase = 2; } else { warn("No no no. You have a non 0,1,2 phase intron (god knows how!). Not displaying it %s",alc_temp->alu[1]->text_label); advance_line_btCanvas(btc); return FALSE; } /* * At this point we have alc on 5SS alc_temp on 3SS. * * Check to see if we can place 5SS and Central intron piece * on the line, if not advance. * */ if( can_get_paste_area_btCanvas(btc,d_phase+7+13) == FALSE) { advance_line_btCanvas(btc); write_name_start_stuff(btc,protname,protoff,dnaname,dna,name,alc); } /*** ok, if we can't get it now then we are f****d ***/ if( can_get_paste_area_btCanvas(btc,d_phase+7+13) == FALSE) { warn("You have specified a length of your main canvas too small. I need at least 23 characters long."); advance_line_btCanvas(btc); return FALSE; } btp = get_paste_area_btCanvas(btc,d_phase+7); /* ? split phase */ if( a_phase == 0 || (a_phase != d_phase ) ) { protc = ' '; transc = ' '; dnatemp[0]= '\0'; issplit = FALSE; } else { if( strcmp(alc_temp->alu[0]->text_label,"INSERT_STATE")== 0 ) { protc = '-'; } else { protc = protsequence[alc->alu[0]->start+1]; } dnatemp[0] = tolower((int)dna->seq[alc->alu[1]->start+1]); if( d_phase == 2) { dnatemp[1] = tolower((int)dna->seq[alc->alu[1]->start+2]); } else { dnatemp[1] = tolower((int)dna->seq[alc_temp->alu[1]->end-1]); } dnatemp[2] = tolower((int)dna->seq[alc_temp->alu[1]->end]); dnatemp[3] = '\0'; transc = aminoacid_from_seq(ct,dnatemp); issplit = TRUE; } write_5intron_match(btp,d_phase,7,dna->seq+alc->alu[1]->start+1); free_btPasteArea(btp); btp = get_paste_area_btCanvas(btc,13); if( is_reversed == FALSE ) write_intron_desc(btp,alc->alu[1]->start+1+d_phase+dna->offset,alc_temp->alu[1]->start+3+dna->offset,intron_number++,issplit,protc,transc,dnatemp); else write_intron_desc(btp,dna->offset - (alc->alu[1]->start+d_phase+1),dna->offset - (alc_temp->alu[1]->start+3),intron_number++,issplit,protc,transc,dnatemp); free_btPasteArea(btp); /* * written the start of the intron, now to deal with the * acceptor. We need to loop here, because we might go over the * line length. */ alc = alc->next->next; /*** move alc forward two columns ***/ while( alc != alc_temp ) { for(; alc != alc_temp;alc = alc->next) { /** alc_temp is 3SS **/ if( strcmp(alc->alu[1]->text_label,"PYRIMIDINE_TRACT") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE ) break; btp = get_paste_area_btCanvas(btc,1); paste_char_btPasteArea(btp,0,3,dna->seq[alc->alu[1]->start+1],0); paste_char_btPasteArea(btp,0,4,'+',0); free_btPasteArea(btp); } else if( strcmp(alc->alu[1]->text_label,"SPACER") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE ) break; btp = get_paste_area_btCanvas(btc,1); paste_char_btPasteArea(btp,0,3,dna->seq[alc->alu[1]->start+1],0); free_btPasteArea(btp); } else { warn("Sorry, don't know how to print %s. Skipping...",alc->alu[1]->text_label); } } /** end for for loop **/ if ( alc == alc_temp ) { break; } /*** run out of space ***/ advance_line_btCanvas(btc); write_name_start_stuff(btc,protname,protoff,dnaname,dna,name,alc); } /** end of while still in central->3SS **/ /* * Now do 3SS * */ if( can_get_paste_area_btCanvas(btc,a_phase == 0 ? 3 : 3- a_phase + 3) == FALSE ) { advance_line_btCanvas(btc); write_name_start_stuff(btc,protname,protoff,dnaname,dna,name,alc); } if( a_phase != 0 ) { btp = get_paste_area_btCanvas(btc,3 - a_phase + 3); write_3intron_match(btp,a_phase,3,dna->seq + alc->alu[1]->start+1); free_btPasteArea(btp); } else { btp = get_paste_area_btCanvas(btc,3); write_3intron_match(btp,a_phase,3,dna->seq + alc->alu[1]->start+1); free_btPasteArea(btp); } /* * Finished with intron !!! */ } else { warn("Sorry, could not print the alignment %s:%s column",alc->alu[0]->text_label,alc->alu[1]->text_label); } } /*** in this loop ***/ advance_line_btCanvas(btc); if( alc == NULL) break; if ( is_random_AlnColumn_genewise(alc) == TRUE) break; } /* end of while over alignments */ } /* end of foreach alignment */ /*** end of print ! **/ return TRUE; }
GeneStats * read_GeneStats(FILE * ifp) { char buffer[MAXLINE]; GeneStats * out; SeqAlign * temp; char **base; char **brk; out = GeneStats_alloc(); out->rnd = NULL; while( fgets(buffer,MAXLINE,ifp) != NULL ) { /* fprintf(stderr,"Reading (main loop) %s",buffer); */ if( buffer[0] == '#' ) continue; if( buffer[0] == '%' && buffer[1] == '%' ) break; if( strstartcmp(buffer,"splice5") == 0 ) { base = brk = breakstring(buffer,spacestr); if( *brk == NULL || *(brk+1) == NULL || is_integer_string(*(brk+1),&out->splice5_offset) == 0) { warn("Cannot read splice5 offset - must be splice5 <number>"); return NULL; } ckfree(base); temp = read_selex_SeqAlign(ifp); if( temp == NULL ) { warn("Could not read in selex alignment for splice5"); continue; } out->splice5 = temp; continue; } if( strstartcmp(buffer,"splice3") == 0 ) { base = brk = breakstring(buffer,spacestr); if( *brk == NULL || *(brk+1) == NULL || is_integer_string(*(brk+1),&out->splice3_offset) == 0) { warn("Cannot read splice3 offset - must be splice3 <number>"); return NULL; } ckfree(base); temp = read_selex_SeqAlign(ifp); if( temp == NULL ) { warn("Could not read in selex alignment for splice5"); continue; } out->splice3 = temp; continue; } if( strstartcmp(buffer,"intron_emission") == 0 ) { if( fgets(buffer,MAXLINE,ifp) == NULL ) { warn("Could not read in intron emission line"); break; } out->intron = get_genestat_emission(buffer); if( fgets(buffer,MAXLINE,ifp) != NULL ) { continue; } else { break; } } if( strstartcmp(buffer,"polyp_emission") == 0 ) { if( fgets(buffer,MAXLINE,ifp) == NULL ) { warn("Could not read in polyp emission line"); break; } out->polyp = get_genestat_emission(buffer); if( fgets(buffer,MAXLINE,ifp) != NULL ) { continue; } else { break; } } if( strstartcmp(buffer,"rnd_emission") == 0 ) { if( fgets(buffer,MAXLINE,ifp) == NULL ) { warn("Could not read in rnd emission line"); break; } out->rnd = get_genestat_emission(buffer); if( fgets(buffer,MAXLINE,ifp) != NULL ) { continue; } else { break; } } if( strstartcmp(buffer,"rndcodon") == 0 ) { if( read_codon_GeneStats(out->codon,buffer,ifp) == FALSE ) { warn("Problem in reading codon line!"); } continue; } if( isalpha(buffer[0]) ) { warn("Could not read line %s in genestats reading\n",buffer); } } assert(out); assert(out->splice5); assert(out->splice3); return out; }
Type * read_Type_line(char * line,FILE * ifp) { Type * out; char * temp; char buffer[MAXLINE]; if( strstartcmp(line,"type") != 0 ) { warn("Attempting to read a method with no method line!"); return NULL; } out = Type_alloc(); out->logical = second_word_alloc(line,spacestr); while( fgets(buffer,MAXLINE,ifp) != NULL ) { chop_newline(buffer); if( strstartcmp(buffer,"end") == 0 ) break; else if( strstartcmp(buffer,"real") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->real != NULL ) { warn("For type [%s], second real replacing [%s] with [%s]",out->logical,out->real,temp); ckfree(out->real); } out->real = temp; } else if( strstartcmp(buffer,"threadsafe") == 0 ) { out->is_thread_safe = TRUE; } else if ( strstartcmp(buffer,"dbtype") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->database_type != NULL ) { warn("For type [%s], second database type replacing [%s] with [%s]",out->logical,out->database_type,temp); ckfree(out->database_type); } out->database_type = temp; } else if ( strstartcmp(buffer,"init") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->init_func != NULL ) { warn("For type [%s], second init replacing [%s] with [%s]",out->logical,out->init_func,temp); ckfree(out->init_func); } out->init_func = temp; } else if ( strstartcmp(buffer,"maxlen") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->maxlen != NULL ) { warn("For type [%s], second maxlen replacing [%s] with [%s]",out->logical,out->maxlen,temp); ckfree(out->maxlen); } out->maxlen = temp; } else if ( strstartcmp(buffer,"reload") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->reload_func != NULL ) { warn("For type [%s], second reload function replacing [%s] with [%s]",out->logical,out->reload_func,temp); ckfree(out->reload_func); } out->reload_func = temp; } else if ( strstartcmp(buffer,"addentry") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->dataentry_add != NULL ) { warn("For type [%s], second dataentry_add function replacing [%s] with [%s]",out->logical,out->dataentry_add,temp); ckfree(out->dataentry_add); } out->dataentry_add = temp; } else if ( strstartcmp(buffer,"close") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->close_func != NULL ) { warn("For type [%s], second close func replacing [%s] with [%s]",out->logical,out->close_func,temp); ckfree(out->close_func); } out->close_func = temp; } else if ( strstartcmp(buffer,"hardlink") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->hard_link_func != NULL ) { warn("For type [%s], second hard_link func replacing [%s] with [%s]",out->logical,out->hard_link_func,temp); ckfree(out->hard_link_func); } out->hard_link_func = temp; } else if ( strstartcmp(buffer,"free") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->free_func != NULL ) { warn("For type [%s], second free func replacing [%s] with [%s]",out->logical,out->free_func,temp); ckfree(out->free_func); } out->free_func = temp; } else if ( strstartcmp(buffer,"name") == 0 ) { temp = second_word_alloc(buffer,spacestr); if( out->get_id_func != NULL ) { warn("For type [%s], second get name func replacing [%s] with [%s]",out->logical,out->get_id_func,temp); ckfree(out->get_id_func); } out->get_id_func = temp; } else { warn("In reading type [%s] did not understand [%s]",out->logical,buffer); } } if( out->is_thread_safe == TRUE ) { if( out->hard_link_func == NULL || out->free_func == NULL ) { warn("Trying to make type %s threadsafe but have not supplied hardlink and free functions",out->logical); out->is_thread_safe = FALSE; } } out->is_database = is_database_type(out); return out; }
GenomeEvidenceSet * read_est_evidence(FILE * ifp,CodonTable * ct) { char buffer[MAXLINE]; GenomeEvidenceUnit * geu; EstEvidence * evi; EstExon * exon; GenomeEvidenceSet * ges; EstIndel * indel; assert(ct); assert(ifp); ges = GenomeEvidenceSet_alloc_std(); evi = EstEvidence_alloc_std(); evi->ct = hard_link_CodonTable(ct); while( fgets(buffer,MAXLINE,ifp) != NULL ) { if( buffer[0] == '#' ) { continue; } if( strstartcmp(buffer,"//") == 0 ) { geu = new_est_GenomeEvidenceUnit(evi); add_GenomeEvidenceSet(ges,geu); evi = EstEvidence_alloc_std(); evi->ct = hard_link_CodonTable(ct); continue; } if( strstartcmp(buffer,"exon") == 0 ) { exon = EstExon_alloc(); exon->intron_3_score = 0; if( sscanf(buffer,"exon %d %d %d",&exon->start,&exon->end,&exon->intron_3_score) < 2 ) { fatal("Unable to read exon line as evidence [%s]"); } exon->start--; exon->end--; add_EstEvidence(evi,exon); } else if( strstartcmp(buffer,"cds") == 0 ) { exon = EstExon_alloc(); sscanf(buffer,"cds %d %d %d",&exon->start,&exon->end,&exon->phase); exon->start--; exon->end--; if( exon->phase > 2 || exon->phase < 0 ) { fprintf(stderr,"Exon has a non clear phase - %d\n",exon->phase); return NULL; } exon->is_coding = TRUE; add_EstEvidence(evi,exon); } else if ( strstartcmp(buffer,"indel") == 0 ) { indel = EstIndel_alloc(); sscanf(buffer,"indel %d %d",&indel->start,&indel->end); indel->start--; indel->end--; add_indel_EstEvidence(evi,indel); } else { fprintf(stderr,"Unable to read as est evidence - %s",buffer); } } if( evi->len > 0 ) { geu = new_est_GenomeEvidenceUnit(evi); add_GenomeEvidenceSet(ges,geu); } return ges; }