static void find_positions (bool *revcompp, Genomicpos_T *leftposition, Genomicpos_T *rightposition, Genomicpos_T *startposition, Genomicpos_T *endposition, Genomicpos_T *truelength, int *contigtype, char *accession, IIT_T contig_iit) { int index; Interval_T interval; char firstchar; if ((index = IIT_find_one(contig_iit,accession)) == -1) { fprintf(stderr,"Can't find accession %s in contig IIT file\n", accession); exit(9); } else { interval = IIT_interval(contig_iit,index); *leftposition = Interval_low(interval); *rightposition = Interval_high(interval); if (IIT_version(contig_iit) <= 1) { firstchar = IIT_annotation_firstchar(contig_iit,index); if (firstchar == '-') { *revcompp = true; *startposition = Interval_high(interval) + 1U; *endposition = Interval_low(interval) + 1U; } else { *revcompp = false; *startposition = Interval_low(interval); *endposition = Interval_high(interval); } } else { if (Interval_sign(interval) < 0) { *revcompp = true; *startposition = Interval_high(interval) + 1U; *endposition = Interval_low(interval) + 1U; } else { *revcompp = false; *startposition = Interval_low(interval); *endposition = Interval_high(interval); } } *truelength = Interval_length(interval); *contigtype = Interval_type(interval); debug(printf("revcompp = %d, leftposition = %d, rightposition = %d, startposition = %d, endposition = %d\n", *revcompp,*leftposition,*rightposition,*startposition,*endposition)); return; } }
/* Need to store just the part of the query specified (e.g., 1..10) */ static double compute_logtotal_tally (long int *total, int *n, Chrpos_T coordstart, Chrpos_T coordend, int indexi, IIT_T iit) { double logtotal = 0.0; Interval_T interval; char *annotation, *restofheader, *ptr; bool allocp; Chrpos_T chrpos, intervalend; long int count; annotation = IIT_annotation(&restofheader,iit,indexi,&allocp); interval = IIT_interval(iit,indexi); chrpos = Interval_low(interval); intervalend = Interval_high(interval); ptr = annotation; while (chrpos < coordstart) { if ((ptr = index(ptr,'\n')) == NULL) { fprintf(stderr,"Premature end of tally from %u to %u\n", Interval_low(interval),Interval_high(interval)); return logtotal; } else { ptr++; } chrpos++; } while (chrpos <= intervalend && chrpos <= coordend) { count = 0; ptr = get_total_tally(&count,ptr); logtotal += log((double) count + 1.0); *total += count; *n += 1; ptr++; chrpos++; } if (allocp == true) { FREE(restofheader); } return logtotal; }
/* Need to store just the part of the query specified (e.g., 1..10) */ static void print_interval_runlength (Chrpos_T *lastcoord, char *divstring, Chrpos_T coordstart, Chrpos_T coordend, int indexi, IIT_T iit, bool zeroesp) { Interval_T interval; char *label; bool allocp; Chrpos_T chrpos, intervalend; int value; label = IIT_label(iit,indexi,&allocp); value = atoi(label); interval = IIT_interval(iit,indexi); chrpos = Interval_low(interval); intervalend = Interval_high(interval); if (zeroesp == true) { while (*lastcoord < chrpos) { printf("%s\t%u\t%d\n",divstring,*lastcoord,0); (*lastcoord)++; } } while (chrpos < coordstart) { chrpos++; } while (chrpos <= intervalend && chrpos <= coordend) { printf("%s\t%u\t%d\n",divstring,chrpos,value); chrpos++; } *lastcoord = chrpos; if (allocp == true) { FREE(label); } return; }
/* coordstart used only if centerp or tallyp is true */ static long int print_interval (Chrpos_T *lastcoord, long int total, char *divstring, Chrpos_T coordstart, Chrpos_T coordend, int index, IIT_T iit, int ndivs, int fieldint) { Interval_T interval; char *label, *annotation, *restofheader; bool allocp; if (centerp == true) { print_interval_centered(divstring,coordstart,index,iit,fieldint); return 0; } else if (tallyp == true) { total += print_interval_tally(&(*lastcoord),divstring,coordstart,coordend,index,iit,zeroesp); return total; } else if (runlengthp == true) { print_interval_runlength(&(*lastcoord),divstring,coordstart,coordend,index,iit,zeroesp); return 0; } if (annotationonlyp == false) { label = IIT_label(iit,index,&allocp); printf(">%s ",label); if (allocp == true) { FREE(label); } if (ndivs > 1) { if (divstring == NULL) { /* For example, if interval was retrieved by label */ divstring = IIT_divstring_from_index(iit,index); } printf("%s:",divstring); } debug(printf("index is %d\n",index)); interval = IIT_interval(iit,index); if (signedp == false) { printf("%u..%u",Interval_low(interval),Interval_high(interval)); } else if (Interval_sign(interval) < 0) { printf("%u..%u",Interval_high(interval),Interval_low(interval)); } else { printf("%u..%u",Interval_low(interval),Interval_high(interval)); } if (Interval_type(interval) > 0) { printf(" %s",IIT_typestring(iit,Interval_type(interval))); } #if 0 /* Unnecessary because of "\n" after restofheader below */ if (IIT_version(iit) < 5) { printf("\n"); } #endif } if (fieldint < 0) { annotation = IIT_annotation(&restofheader,iit,index,&allocp); printf("%s\n",restofheader); printf("%s",annotation); if (allocp == true) { FREE(restofheader); } } else { annotation = IIT_annotation(&restofheader,iit,index,&allocp); printf("%s\n",restofheader); if (allocp == true) { FREE(restofheader); } annotation = IIT_fieldvalue(iit,index,fieldint); printf("%s\n",annotation); FREE(annotation); } return 0; }
/* Need to store just the part of the query specified (e.g., 1..10) */ static long int print_interval_tally (Chrpos_T *lastcoord, char *divstring, Chrpos_T coordstart, Chrpos_T coordend, int indexi, IIT_T iit, bool zeroesp) { long int total = 0, subtotal; Interval_T interval; char *annotation, *restofheader, *ptr, *nextptr; bool allocp; Chrpos_T chrpos, intervalend; annotation = IIT_annotation(&restofheader,iit,indexi,&allocp); interval = IIT_interval(iit,indexi); chrpos = Interval_low(interval); intervalend = Interval_high(interval); ptr = annotation; if (zeroesp == true) { while (*lastcoord < chrpos) { if (statsp == false) { printf("%s\t%u\t%d\t\n",divstring,*lastcoord,0); } (*lastcoord)++; } } while (chrpos < coordstart) { if ((ptr = index(ptr,'\n')) == NULL) { fprintf(stderr,"Premature end of tally from %u to %u\n", Interval_low(interval),Interval_high(interval)); return total; } else { ptr++; } chrpos++; } while (chrpos <= intervalend && chrpos <= coordend) { subtotal = 0; nextptr = get_total_tally(&subtotal,ptr); if (subtotal > 0 || zeroesp == true) { if (statsp == false) { printf("%s\t%u\t%ld\t",divstring,chrpos,total); print_line(ptr); printf("\n"); } } total += subtotal; ptr = nextptr; if ((ptr = index(ptr,'\n')) == NULL) { fprintf(stderr,"Premature end of tally from %u to %u\n", Interval_low(interval),Interval_high(interval)); return total; } else { ptr++; } chrpos++; } *lastcoord = chrpos; if (allocp == true) { FREE(restofheader); } return total; }
/* Need to store just the part of the query specified (e.g., 1..10) */ static void print_interval_centered (char *divstring, Chrpos_T coordstart, int index, IIT_T iit, int fieldint) { Interval_T interval; char *label, *annotation, *restofheader, centerchar; bool allocp; int annotlength, left, centerpos; if (fieldint < 0) { annotation = IIT_annotation(&restofheader,iit,index,&allocp); if (allocp == true) { FREE(restofheader); } } else { annotation = IIT_fieldvalue(iit,index,fieldint); allocp = true; } annotlength = strlen(annotation); if (annotation[annotlength-1] == '\n') { annotlength--; } interval = IIT_interval(iit,index); left = coordstart - Interval_low(interval); /* + length(query) - queryend */ if (Interval_sign(interval) < 0) { centerpos = annotlength-left-1; } else { centerpos = left; } centerchar = annotation[centerpos]; if (centeruc == true && islower(centerchar)) { if (fieldint >= 0 && allocp == true) { FREE(annotation); } } else { print_spaces(centerlength-left); if (Interval_sign(interval) < 0) { print_complement(annotation,annotlength-1,centerpos+1); printf("[%c]",complCode[(int) centerchar]); print_complement(annotation,centerpos-1,0); } else { print_forward(annotation,0,centerpos-1); printf("[%c]",centerchar); print_forward(annotation,centerpos+1,annotlength-1); } print_spaces(centerlength+left-annotlength); if (fieldint >= 0 && allocp == true) { FREE(annotation); } printf("\t"); if (Interval_type(interval) > 0) { printf("%s\t",IIT_typestring(iit,Interval_type(interval))); } if (divstring != NULL) { if (Interval_sign(interval) < 0) { printf("-%s:",divstring); } else { printf("+%s:",divstring); } } if (signedp == false) { printf("%u..%u",Interval_low(interval),Interval_high(interval)); } else if (Interval_sign(interval) < 0) { printf("%u..%u",Interval_high(interval),Interval_low(interval)); } else { printf("%u..%u",Interval_low(interval),Interval_high(interval)); } printf("\t"); label = IIT_label(iit,index,&allocp); printf("%s",label); if (allocp == true) { FREE(label); } printf("\n"); } return; }