/********************************************************************** * * MapLocToAnchor(annot, slp, anchor) * map the current slp to a position on the anchor Bioseq * annot: Seq-annot that may contain the alignment of the consistent markers * slp: the current Bioseq * anchor_id: the Seq-id for the anchor Bioseq, that is the sequece map * ************************************************************************/ SeqLocPtr MapLocToAnchor(SeqAnnotPtr annot, SeqLocPtr slp, BioseqPtr anchor_bsp) { Int2 type; Int4Ptr x_a, x; Uint2 num; SeqIdPtr anchor_id; SeqLocPtr t_slp; Int4 start, stop; SeqAlignPtr align; if(annot == NULL || slp == NULL || anchor_bsp == NULL) return NULL; if(slp->choice != SEQLOC_PNT && slp->choice != SEQLOC_INT) return NULL; anchor_id = SeqIdFindBest(anchor_bsp->id, SEQID_GI); if(anchor_id == NULL) anchor_id = anchor_bsp->id; while(annot) { if(annot->type == 2) { type = GetEquivAlignType(annot); if(type == 1) /*this is consistent*/ { align = annot->data; if(!get_anchor_coordinates(align, anchor_id, SeqLocId(slp), &x_a, &x, &num)) return NULL; if(slp->choice == SEQLOC_INT) { start = find_this_position_by_anchor (x_a, x, num, SeqLocStart(slp), anchor_bsp->length); if(SeqLocStart(slp) != SeqLocStop(slp)) stop = find_this_position_by_anchor (x_a, x, num, SeqLocStop(slp), anchor_bsp->length); else stop = start; t_slp = SeqLocIntNew(start, stop, Seq_strand_plus, anchor_id); } else { start = SeqLocStart(slp); start = find_this_position_by_anchor (x_a, x, num, start, anchor_bsp->length); t_slp = SeqLocPntNew(start, Seq_strand_plus, anchor_id, FALSE); } MemFree(x_a); MemFree(x); return t_slp; } } annot = annot->next; } return NULL; }
extern SeqLocPtr CheckOverlap (SeqLocPtr slp, Int4 ctermsig) { SeqLocPtr slphead = NULL, slptmp; Int4 start; if (ctermsig == 0) return slp; while (slp != NULL) { start = SeqLocStop (slp); if (start < ctermsig) { slptmp = slp->next; slp->next = NULL; SeqLocFree (slp); slp = slptmp; continue; } if (slphead == NULL) slphead = slp; slp = slp->next; } return slphead; }
extern DustRegionPtr DustSeqLoc (SeqLocPtr slp, DustDataPtr ddp) { BioseqPtr bsp; Int4 start, end; DustRegionPtr drp; if (slp == NULL || ddp == NULL) return NULL; if (slp->choice != SEQLOC_INT) { ErrPostEx (SEV_ERROR, 2, 1, "Will only dust a single SeqLoc interval"); ErrShow (); return NULL; } if ((bsp = BioseqLockById (SeqLocId (slp))) == NULL) { ErrPostEx (SEV_ERROR, 2, 5, "Bioseq lock failure"); ErrShow (); return NULL; } start = SeqLocStart (slp); end = SeqLocStop (slp); drp = DustBioseq (bsp, start, end, ddp); BioseqUnlock (bsp); return drp; }
extern void RemoveInternalOrfs (SeqLocPtr PNTR slpFound) { SeqLocPtr slp1, slp2, slp = NULL; SeqIdPtr id; Int4 start1, stop1, start2, stop2; Boolean flagInternal; slp1 = *slpFound; while (slp1 != NULL) { start1 = SeqLocStart (slp1); stop1 = SeqLocStop (slp1); flagInternal = FALSE; slp2 = *slpFound; while (slp2 != NULL) { start2 = SeqLocStart (slp2); stop2 = SeqLocStop (slp2); if ((start1 > start2 && start1 < stop2) && (stop1 > start2 && stop1 < stop2)) { flagInternal = TRUE; break; } slp2 = slp2->next; } if (!flagInternal) SeqLocLink (&slp, SeqLocDup (slp1)); slp1 = slp1->next; } slp1 = *slpFound; while (slp1 != NULL) { slp2 = slp1->next; id = SeqLocId (slp1); if (id != NULL) id->next = SeqIdSetFree (id->next); SeqLocFree (slp1); slp1 = slp2; } *slpFound = slp; return; }
static Int4 FindNecessaryBioseqLength (SeqFeatPtr sfp) { Int4 len = 0; while (sfp != NULL) { len = MAX (SeqLocStop (sfp->location), len); len = MAX (SeqLocStart (sfp->location), len); sfp = sfp->next; } return len + 1; }
extern Boolean SeqLocMatch (SeqLocPtr slplist, SeqLocPtr slpnew) { Int4 start1, stop1, start2, stop2; if (slpnew == NULL || slplist == NULL) { return FALSE; } while (slplist != NULL) { start1 = SeqLocStart (slpnew); stop1 = SeqLocStop (slpnew); start2 = SeqLocStart (slplist); stop2 = SeqLocStop (slplist); if (start1 == start2 && stop1 == stop2) return TRUE; slplist = slplist->next; } return FALSE; }
extern Int4 EndOfSig (SeqLocPtr slp) { Int4 stop, ctermsig = 0; while (slp != NULL) { stop = SeqLocStop (slp); if (stop > ctermsig) ctermsig = stop; slp = slp->next; } return ctermsig; }
/**************************************************************************** * * get_anchor_coordinates(h_align, anchor_id, sip, x_anchor_pos, x_pos, num) * * load the positions of framework marker of the current sequence and its * corresponding positions in the anchor map (normally the NCBI sequence) into * two arays to extrapolate the positions for map integration * h_align: the alignment of consistent markers (a.k.a good alignment) * anchor_id: the Seq-id for the anchor map (normally, the NCBI sequence map) * sip: the Seq-id for the current sequence * x_anchor_pos: the array to store the positions on the anchor map * x_pos: the array to store the positions on the current map. each * member of x_anchor_pos and x_pos is a matching pair * both arrays are ordered * num: the total number of framework markers in the current map. * This is also the size of x_anchor_pos and x_pos * * return TRUE for success and FALSE for fail * ****************************************************************************/ Boolean get_anchor_coordinates(SeqAlignPtr h_align, SeqIdPtr anchor_id, SeqIdPtr sip, Int4Ptr PNTR x_anchor_pos, Int4Ptr PNTR x_pos, Uint2Ptr num) { StdSegPtr ssp; SeqLocPtr slp; SeqIdPtr id; Int4 n, i, j; Int4 a_pos, t_pos; SeqAlignPtr align; Int4Ptr anchor_pos, pos; Boolean change; Int4 temp; *x_anchor_pos = NULL; *x_pos = NULL; *num = 0; align = h_align; if(align == NULL) return FALSE; /* count the number of the consistent markers for the current sip */ n = 0; while(align) { if(align->segtype == 3) { /*Std-segs*/ ssp = align->segs; for(slp = ssp->loc; slp != NULL; slp = slp->next) { id = SeqLocId(slp); if(SeqIdForSameBioseq(id, sip)) { ++n; break; } } } align = align->next; } if(n == 0) return FALSE; anchor_pos = MemNew((size_t)n * sizeof(Int4)); pos = MemNew((size_t)n * sizeof(Int4)); /*load the data*/ n = 0; align = h_align; while(align) { if(align->segtype == 3) { ssp = align->segs; a_pos = -1; t_pos = -1; for(slp = ssp->loc; slp != NULL; slp = slp->next) { id = SeqLocId(slp); if(SeqIdForSameBioseq(id, sip)) t_pos = (SeqLocStart(slp) + SeqLocStop(slp))/2; else if(SeqIdForSameBioseq(id, anchor_id)) a_pos = SeqLocStart(slp); } /*each time, load a matching pair*/ if(t_pos >= 0 && a_pos >=0) { anchor_pos[n] = a_pos; pos[n] = t_pos; ++n; } } align = align->next; } /*sort the array*/ change = TRUE; for(i = 0; i<n-1 && change == TRUE; ++i) { change = FALSE; for(j = 0; j<n-i-1; ++j) { if(anchor_pos[j] > anchor_pos[j+1]) { change = TRUE; temp = anchor_pos[j+1]; anchor_pos[j+1] = anchor_pos[j]; anchor_pos[j] = temp; temp = pos[j+1]; pos[j+1] = pos[j]; pos[j] = temp; } } } /*check the linear relationship between anchor_pos and pos*/ temp = pos[0]; for(i = 1, j= 1; i<n; ++i) { if(pos[i] >= temp) { temp = pos[i]; pos[j] = temp; anchor_pos[j] = anchor_pos[i]; ++j; } } *x_anchor_pos = anchor_pos; *x_pos = pos; *num = (Uint2)j; return TRUE; }
/****************************************************************** * * aa_to_dnaloc(sfp, aa_start, aa_stop) * map the amino acid sequence to a list of Seq-locs in the * DNA sequence * ******************************************************************/ NLM_EXTERN SeqLocPtr aa_to_dnaloc(SeqFeatPtr sfp, Int4 aa_start, Int4 aa_stop) { Int4 frame_offset, start_offset; /*for determine the reading frame*/ SeqLocPtr slp = NULL; CdRegionPtr crp; SeqLocPtr dna_loc, loc; /*for the dna location*/ Boolean is_end; /**is the end for process reached?**/ Int4 p_start=0, p_stop=0; /**protein start & stop in defined corresponding CdRegion Seq-loc**/ Int4 cur_pos; /**current protein position in process**/ Int4 cd_len; /**length of the cDNA for the coding region**/ Boolean is_new; /**Is cur_pos at the begin of new exon?**/ Boolean end_partial; /*the end of aa is a partial codon*/ Int4 d_start, d_stop; /*the start and the stop of the DNA sequence*/ Int4 offset; /*offset from the start of the current exon*/ Int4 aa_len; Uint1 strand; if(sfp->data.choice !=3) return NULL; crp = sfp->data.value.ptrvalue; if(!crp) return NULL; if(crp->frame>0) frame_offset = crp->frame-1; else frame_offset = 0; start_offset = frame_offset; cur_pos= aa_start; cd_len = 0; is_end = FALSE; p_start = 0; slp = NULL; dna_loc= NULL; while(!is_end && ((slp = SeqLocFindNext(sfp->location, slp))!=NULL)) { cd_len += SeqLocLen(slp); end_partial = ((cd_len - start_offset)%3 != 0); p_stop = (cd_len - start_offset)/3 -1; if(end_partial) ++p_stop; if(p_stop > aa_stop || (p_stop == aa_stop && !end_partial)) { p_stop = aa_stop; /**check if the end is reached**/ is_end = TRUE; } if(p_stop >= cur_pos) /*get the exon*/ { is_new = (p_start == cur_pos); /*start a new exon?*/ if(is_new) /**special case of the first partial**/ offset = 0; else { if(frame_offset && p_start >0) ++p_start; offset = 3*(cur_pos - p_start) + frame_offset; } strand = SeqLocStrand(slp); if(strand == Seq_strand_minus) d_start = SeqLocStop(slp) - offset; else d_start = SeqLocStart(slp) + offset; d_stop = d_start; aa_len = MIN(p_stop, aa_stop) - cur_pos +1; if(strand == Seq_strand_minus) { d_stop -= 3*aa_len; d_stop = MAX(d_stop, SeqLocStart(slp)); loc = SeqLocIntNew(d_stop, d_start, strand, SeqLocId(slp)); } else { d_stop += 3*aa_len; d_stop = MIN(d_stop, SeqLocStop(slp)); loc = SeqLocIntNew(d_start, d_stop, strand, SeqLocId(slp)); } ValNodeLink(&dna_loc, loc); if(end_partial) cur_pos = p_stop; else cur_pos = p_stop+1; } if(end_partial) p_start = p_stop; else p_start = p_stop +1; frame_offset = (cd_len - start_offset)%3; if(frame_offset >0) frame_offset = 3-frame_offset; }/**end of while(slp && !is_end) **/ return dna_loc; }
/****************************************************************** * * aa_to_codon(sfp, aa_start, aa_stop) * generate a list of CodonVecotr to show the codons of an * amino acid sequence * sfp: the Seq-feat for cds * aa_start: the start position of protein sequence * aa_stop the stop position of protein sequence * ******************************************************************/ NLM_EXTERN ValNodePtr aa_to_codon(SeqFeatPtr sfp, Int4 aa_start, Int4 aa_stop) { BioseqPtr bsp; Int4 frame_offset, start_offset; SeqLocPtr slp = NULL; SeqLocPtr cdloc; CdRegionPtr crp; Uint1 frame; Boolean is_end; /**is the end for process reached?**/ Int4 p_start=0, p_stop=0; /**protein start & stop in defined corresponding CdRegion Seq-loc**/ Int4 line_len; Int4 cur_pos; /**current protein position in process**/ Int4 cd_len; /**length of the cDNA for the coding region**/ Int2 i, j; Int2 k, n; CharPtr PNTR buf; Boolean is_new; /**Is cur_pos at the begin of new Seq-loc?**/ CharPtr temp; SeqPortPtr spp; Uint1 residue; Boolean end_partial; Int4 d_start, seq_pos; Int2 pos; ValNodePtr head= NULL; CodonVectorPtr cvp; Boolean prt_stop_codon; Uint2 exon; if(sfp->data.choice !=3) return NULL; crp = sfp->data.value.ptrvalue; if(!crp) return NULL; frame = crp->frame; cdloc = sfp->location; if(cdloc == NULL ) return NULL; if(frame>0) frame_offset = frame-1; else frame_offset = 0; start_offset = frame_offset; prt_stop_codon = (aa_stop == SeqLocStop(sfp->product)); line_len = (aa_stop - aa_start + 1) + 1; /* +1 for the possible partial start codon*/ if(prt_stop_codon)/*can be either as a stop codon or partial stop*/ ++line_len; buf = MemNew((size_t)3 * sizeof(CharPtr)); for(i =0; i<3; ++i) buf[i] = MemNew((size_t)(line_len + 1) * sizeof (Char)); cur_pos= aa_start; cd_len = 0; is_end = FALSE; p_start = 0; slp = NULL; exon = 0; while(!is_end && ((slp = SeqLocFindNext(cdloc, slp))!=NULL)) { ++exon; cd_len += SeqLocLen(slp); end_partial = ((cd_len - start_offset)%3 != 0); p_stop = (cd_len - start_offset)/3 -1; if(end_partial) ++p_stop; if(p_stop > aa_stop || (p_stop == aa_stop && !end_partial)) { p_stop = aa_stop; /**check if the end is reached**/ is_end = TRUE; } if(p_stop >= cur_pos) /*get the exon*/ { bsp = BioseqLockById(SeqLocId(slp)); if(bsp) { is_new = (p_start == cur_pos); /*start a new exon?*/ cvp = MemNew(sizeof(CodonVector)); cvp->sip = SeqIdDup(find_sip(bsp->id)); cvp->strand = SeqLocStrand(slp); cvp->exonCount = exon; if(is_new) { if(frame_offset == 0) cvp->frame = 0; else cvp->frame = 3- (Uint1)frame_offset; } else cvp->frame = 0; if(cur_pos==0 && frame_offset > 0) /*partial start codon*/ cvp->aa_index = 0; else cvp->aa_index = 1; if(is_new) /**special case of the first partial**/ d_start = SeqLocStart(slp); else { if(frame_offset && p_start >0) ++p_start; d_start = SeqLocStart(slp) + 3*(cur_pos - p_start) + frame_offset; } /**p_start is the start position of aa in the current Seq-loc cur_pos is the current aa that is in process. The offset will help to located the position on the DNA Seq-loc for translation d_start is the position of the starting DNA in the coordinates of DNA segment, used for mark the sequence **/ seq_pos = d_start - SeqLocStart(slp); /**the pos in spp**/ if(SeqLocStrand(slp)== Seq_strand_minus) d_start = SeqLocStop(slp) - seq_pos; cvp->dna_pos = d_start; n = (Int2)cur_pos - (Int2)aa_start + cvp->aa_index; /*position in buffer*/ for(i =0; i<3; ++i) make_empty(buf[i], (Int2)line_len); spp = SeqPortNewByLoc(slp, Seq_code_iupacna); SeqPortSeek(spp, seq_pos, SEEK_SET); /**store the partial codons**/ if(is_new && frame_offset > 0) { k = (Int2)frame_offset; while(k > 0) { residue = SeqPortGetResidue(spp); temp = buf[3-k]; /**the position**/ pos = n; temp[pos] = TO_LOWER(residue); --k; } ++n; if(cur_pos!=0) ++cur_pos; } /**load the codons**/ k =0; while((residue = SeqPortGetResidue(spp)) != SEQPORT_EOF && cur_pos <= p_stop) { j= (Uint1)k%3; temp = buf[j]; temp[n] = TO_LOWER(residue); if(j ==2) { /**the last base**/ ++n; if(!prt_stop_codon|| !is_end) /*for the last codon*/ /**prt_end controls to print the whole loc**/ ++cur_pos; } ++k; } /**end of while**/ SeqPortFree(spp); for(i =0; i<3; ++i) cvp->buf[i] = StringSave(buf[i]); ValNodeAddPointer(&head, 0, (Pointer)cvp); BioseqUnlock(bsp); }/*end of if(bsp)*/ }/**end of if for matched intervals**/ if(end_partial) p_start = p_stop; else p_start = p_stop +1; frame_offset = (cd_len - start_offset)%3; if(frame_offset >0) frame_offset = 3-frame_offset; }/**end of while(slp && !is_end) **/ for(i=0; i<3; ++i) MemFree(buf[i]); MemFree(buf); return head; }
static void ConsignProc (ButtoN b) { XOSPtr xosp; XISPtr xisp; ComPatPtr cpp, cpph; ValNodePtr orflist; SeqLocPtr slp, slpn; Int4 start, stop; Uint1 strand; SeqPortPtr spp; Uint1Ptr aaseq; Int4 ntpos, aapos; Uint1 cdn[3]; SeqAlignPtr sap, sapn; FloatHi probcut; Int4 clustmin, findmin; Int4 i, n, endpos, XLength, XScale, shift; Int4 iframe, frame, top, orftop[6]; FloatHiPtr score, expandscore; FloatHi maxscore; Int4Ptr tableGlobal; SeqGraphPtr sgp, sgpn; WindoW w; VieweR v; GrouP g; SegmenT seg; GraphSentPtr gsp; Char numberbuffer[32]; if ((xosp = (XOSPtr) GetObjectExtra (b)) == NULL) return; if (xosp->bsp == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "No Bioseq"); ErrShow (); return; } WatchCursor (); cpph = cpp = ReadPrositePattern (xosp->pattern_file, TRUE, -1, NULL, NULL); if (cpph == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 101, "read failed %s", xosp->pattern_file); ErrShow (); ArrowCursor (); return; } xosp->orflist = GetOrfList (xosp->bsp, (Int2) (xosp->orfcut)); xosp->orflist = ClearNonMetOrfs (xosp->orflist); orflist = xosp->orflist; while (orflist != NULL) { slp = (SeqLocPtr) orflist->data.ptrvalue; if (slp->choice == 0) { orflist = orflist->next; continue; } if (slp->choice == SEQLOC_MIX) slp = (SeqLocPtr) slp->data.ptrvalue; start = SeqLocStart (slp); stop = SeqLocStop (slp); strand = SeqLocStrand (slp); if (strand != Seq_strand_both) strand = Seq_strand_both; if (stop - start + 1 >= xosp->minimumseed) { spp = SeqPortNew (xosp->bsp, start, stop, strand, Seq_code_ncbi4na); aaseq = (Uint1Ptr) MemNew ((size_t) (sizeof (Uint1) * (((stop-start)/3)+2))); ntpos = start; aapos = 0; while (ntpos < start+3) { cdn[0] = SeqPortGetResidue (spp); ntpos++; cdn[1] = SeqPortGetResidue (spp); ntpos++; cdn[2] = SeqPortGetResidue (spp); ntpos++; aaseq[aapos] = AAForCodon (cdn, xosp->gcdi); aapos++; } while (ntpos <= stop) { cdn[0] = SeqPortGetResidue (spp); ntpos++; cdn[1] = SeqPortGetResidue (spp); ntpos++; cdn[2] = SeqPortGetResidue (spp); ntpos++; aaseq[aapos] = AAForCodon (cdn, xosp->gcd); aapos++; } SeqPortFree (spp); aaseq[aapos] = 0; cpp = cpph; while (cpp != NULL) { sap = PatternMatch (aaseq, 0, Seq_strand_plus, SeqLocId (slp), cpp, 0, Seq_strand_unknown, FALSE); if (sap != NULL) break; cpp = cpp->nextpattern; } MemFree (aaseq); if (sap != NULL) { SeqLocLink (&(xosp->slps), SeqLocDup (slp)); } while (sap != NULL) { sapn = sap->next; SeqAlignFree (sap); sap = sapn; } } orflist = orflist->next; } ComPatFree (cpph); orflist = xosp->orflist; while (orflist != NULL) { slp = (SeqLocPtr) orflist->data.ptrvalue; if (slp->choice > 0) SeqLocLink (&(xosp->slpa), SeqLocDup (slp)); while (slp != NULL) { slpn = slp->next; SeqLocFree (slp); slp = slpn; } orflist->data.ptrvalue = NULL; orflist = orflist->next; } xosp->orflist = ValNodeFree (xosp->orflist); probcut = xosp->probcut; clustmin = xosp->clustmin; findmin = xosp->findmin; xosp->slpb = FindSimilarBiasOrfs (xosp->sep, probcut, clustmin, findmin, xosp->slps, xosp->slpa); tableGlobal = CodonTableFromSeqLoc (xosp->bsp, xosp->slpb); seg = NULL; top = 0; xisp = (XISPtr) MemNew (sizeof (XIS)); frame = 0; for (iframe = 0; iframe < 6; iframe++) { endpos = (xosp->bsp->length + 3 - frame - xosp->window) / 3; if (iframe < 3) score = BiasScoreBioseq (xosp->bsp, tableGlobal, xosp->window, frame, Seq_strand_plus); else score = BiasScoreBioseq (xosp->bsp, tableGlobal, xosp->window, frame, Seq_strand_minus); maxscore = 0.0; for (i = 0; i < endpos; i++) if (score[i] > maxscore) maxscore = score[i]; expandscore = (FloatHiPtr) MemNew (sizeof (FloatHi) * xosp->bsp->length); for (i = 0; i < xosp->window/2; i++) expandscore[i] = maxscore; n = 0; while (i < xosp->bsp->length) { if (n < endpos) expandscore[i] = score[n]; else expandscore[i] = maxscore; i++; if (i%3 == 0) n++; } MemFree (score); score = expandscore; sgp = SeqGraphNew (); if (xisp->sgp == NULL) { xisp->sgp = sgp; } else { sgpn = xisp->sgp; while (sgpn->next != NULL) sgpn = sgpn->next; sgpn->next = sgp; } XLength = xosp->bsp->length; if (XLength > 1200) XLength = 1200; XScale = xosp->bsp->length / XLength; if (xosp->bsp->length % XLength != 0) XScale++; sgp->loc = SeqLocIntNew (0, xosp->bsp->length-1, xosp->bsp->strand, xosp->bsp->id); sgp->flags[2] = 1; sgp->numval = xosp->bsp->length; sgp->values = (Pointer) score; sgp->max.realvalue = maxscore; sgp->min.realvalue = 0.0; sgp->flags[1] = 1; sgp->a = 4.0; sgp->b = 0.0; if (seg == NULL) seg = CreatePicture (); if ((gsp = AddGraphSentinelToPicture (sgp, xosp->bsp, seg, 0, top, 0, NULL)) != NULL) { sprintf (numberbuffer, "%ld", 1L); AddLabel (seg, gsp->box.left, gsp->bottom-20, numberbuffer, SMALL_TEXT, 0, MIDDLE_CENTER, 0); sprintf (numberbuffer, "%ld", (long) xosp->bsp->length); AddLabel (seg, gsp->box.left+xosp->bsp->length, gsp->bottom-20, numberbuffer, SMALL_TEXT, 0, MIDDLE_CENTER, 0); } shift = (Int4) (maxscore*sgp->a); orftop[iframe] = top - shift - 38; top -= (shift+56); frame++; if (frame == 3) { top -= 24; frame = 0; } } frame = 0; for (iframe = 0; iframe < 6; iframe++) { if (iframe < 3) strand = Seq_strand_plus; else strand = Seq_strand_minus; shift = 0; if (xosp->slpa != NULL) { AddOrfClass (xosp->slpa, seg, orftop, iframe, frame, shift, strand, YELLOW_COLOR, 5); shift += 4; } if (xosp->slpk != NULL) { AddOrfClass (xosp->slpk, seg, orftop, iframe, frame, shift, strand, GREEN_COLOR, 5); shift += 4; } if (xosp->slpb != NULL) { AddOrfClass (xosp->slpb, seg, orftop, iframe, frame, shift, strand, BLUE_COLOR, 5); shift += 4; } if (xosp->slps != NULL) { AddOrfClass (xosp->slps, seg, orftop, iframe, frame, shift, strand, RED_COLOR, 5); } frame++; if (frame == 3) frame = 0; } MemFree (tableGlobal); start = 20; stop = 20 + (50*XScale); top = orftop[5] - 40; if (xosp->slpa != NULL) { top -= 12; AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), YELLOW_COLOR, SOLID_LINE, SOLID_SHADING, 5, 0); AddLine (seg, start, top, stop, top, FALSE, 0); AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), BLACK_COLOR, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH, 0); AddLabel (seg, stop+(20*XScale), top, "All Met-init'd ORFs equal to or greater than 50 codons", SMALL_TEXT, 0, MIDDLE_RIGHT, 0); } if (xosp->slpk != NULL) { top -= 12; AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), GREEN_COLOR, SOLID_LINE, SOLID_SHADING, 5, 0); AddLine (seg, start, top, stop, top, FALSE, 0); AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), BLACK_COLOR, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH, 0); AddLabel (seg, stop+(20*XScale), top, "Annotated (reported) ORFs", SMALL_TEXT, 0, MIDDLE_RIGHT, 0); } if (xosp->slpb != NULL) { top -= 12; AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), BLUE_COLOR, SOLID_LINE, SOLID_SHADING, 5, 0); AddLine (seg, start, top, stop, top, FALSE, 0); AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), BLACK_COLOR, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH, 0); AddLabel (seg, stop+(20*XScale), top, "Similar codon usage bias ORFs to seed ORFs", SMALL_TEXT, 0, MIDDLE_RIGHT, 0); } if (xosp->slps != NULL) { top -= 12; AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), RED_COLOR, SOLID_LINE, SOLID_SHADING, 5, 0); AddLine (seg, start, top, stop, top, FALSE, 0); AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), BLACK_COLOR, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH, 0); AddLabel (seg, stop+(20*XScale), top, "Pattern match seed ORFs", SMALL_TEXT, 0, MIDDLE_RIGHT, 0); } xisp->picture = seg; w = FixedWindow (10, 10, 640, 720, "Consign", CloseGraphWindowProc); SetObjectExtra (w, xisp, CleanUpGraphWindow); g = HiddenGroup (w, -1, 0, NULL); v = CreateViewer (g, 560, 640, TRUE, TRUE); AttachPicture (v, seg, INT4_MIN, INT4_MAX, UPPER_LEFT, XScale, 1, NULL); PushButton (g, "Close", CloseGraphWindowButton); RealizeWindow (w); ArrowCursor (); Show (w); return; }
static void AddOrfClass (SeqLocPtr slp, SegmenT seg, Int4Ptr orftop, Int4 iframe, Int4 frame, Int4 shift, Uint1 strand, Uint1Ptr orfcolor, Uint1 orfwidth) { SeqLocPtr slpThis, slpHead; Uint1 strandThis; Int4 start, stop, startorig, startthis, stopthis; Int4 len, runlen, extraframe; Int4 top, topold, startold, stopold; Int4 framethis; Boolean flagRTL; while (slp != NULL) { if (slp->choice == SEQLOC_MIX) slpThis = (SeqLocPtr) slp->data.ptrvalue; else slpThis = slp; strandThis = SeqLocStrand (slpThis); if (strandThis == strand || (strandThis == Seq_strand_unknown && strand == Seq_strand_plus)) { flagRTL = TRUE; runlen = 0; startold = -1; stopold = -1; topold = -1; slpHead = slpThis; if (strandThis != Seq_strand_plus && strandThis != Seq_strand_unknown) { if (slp->choice == SEQLOC_MIX) { if (slpHead->next != NULL) { if (SeqLocStart (slpHead->next) > SeqLocStart (slpHead)) { flagRTL = FALSE; while (slpHead->next != NULL) slpHead = slpHead->next; } } } } if (strandThis != Seq_strand_plus && strandThis != Seq_strand_unknown) startorig = SeqLocStop (slpHead) - 2; else startorig = SeqLocStart (slpHead); if (startorig > 0 && startorig%3 == frame) { while (slpThis != NULL) { start = SeqLocStart (slpThis); stop = SeqLocStop (slpThis); if (strandThis != Seq_strand_plus && strandThis != Seq_strand_unknown) { startthis = SeqLocStop (slpThis) - 2; stopthis = SeqLocStart (slpThis) - 2; } else { startthis = SeqLocStart (slpThis); stopthis = SeqLocStop (slpThis); } framethis = startthis % 3; extraframe = runlen % 3; framethis += extraframe; framethis %= 3; if (iframe > 2) framethis = 3 + framethis; top = orftop[framethis] - shift; len = stopthis - startthis; if (len < 0) len *= -1; len += 1; runlen += len; if (stopold >= 0) { AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), orfcolor, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH, 0); if (strand == Seq_strand_minus && flagRTL) AddLine (seg, startold, topold, stop, top, FALSE, 0); else AddLine (seg, stopold, topold, start, top, FALSE, 0); } AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), orfcolor, SOLID_LINE, SOLID_SHADING, orfwidth, 0); AddLine (seg, start, top, stop, top, FALSE, 0); AddAttribute (seg, (COLOR_ATT|STYLE_ATT|SHADING_ATT|WIDTH_ATT), BLACK_COLOR, SOLID_LINE, SOLID_SHADING, STD_PEN_WIDTH, 0); startold = start; stopold = stop; topold = top; if (slp->choice != SEQLOC_MIX) break; slpThis = slpThis->next; } } } slp = slp->next; } return; }
static int LIBCALLBACK MegaBlastPrintEndpoints(VoidPtr ptr) { BlastSearchBlkPtr search = (BlastSearchBlkPtr) ptr; CharPtr subject_descr; SeqIdPtr sip, query_id; CharPtr query_buffer, title; CharPtr subject_buffer; Int4 query_length, q_start, q_end, q_shift=0, s_shift=0; Int4 subject_end; Int4 hsp_index; Boolean numeric_sip_type = FALSE; BLAST_HSPPtr hsp; Int2 context; Char context_sign; Int4 subject_gi, score; FILE *fp = (FILE *) search->output; if (search->current_hitlist == NULL || search->current_hitlist->hspcnt <= 0) { search->subject_info = BLASTSubjectInfoDestruct(search->subject_info); return 0; } if (search->rdfp) readdb_get_descriptor(search->rdfp, search->subject_id, &sip, &subject_descr); else sip = SeqIdSetDup(search->subject_info->sip); if (sip->choice != SEQID_GENERAL || StringCmp(((DbtagPtr)sip->data.ptrvalue)->db, "BL_ORD_ID")) { if (search->pbp->mb_params->full_seqids) { subject_buffer = (CharPtr) Malloc(BUFFER_LENGTH + 1); SeqIdWrite(sip, subject_buffer, PRINTID_FASTA_LONG, BUFFER_LENGTH); } else numeric_sip_type = GetAccessionFromSeqId(SeqIdFindBest(sip, SEQID_GI), &subject_gi, &subject_buffer); } else { DbtagPtr db_tag = (DbtagPtr) sip->data.ptrvalue; if (db_tag->db && (!StringCmp(db_tag->db, "THC") || !StringICmp(db_tag->db, "TI")) && db_tag->tag->id != 0) { subject_buffer = (CharPtr) Malloc(16); sprintf(subject_buffer, "%ld", (long) db_tag->tag->id); } else { subject_buffer = StringTokMT(subject_descr, " \t", &subject_descr); subject_descr = subject_buffer; } } search->current_hitlist->hspcnt_max = search->current_hitlist->hspcnt; /* Only for the two sequences case, get offset shift if subject is a subsequence */ if (!search->rdfp && search->query_slp->next) { s_shift = SeqLocStart(search->query_slp->next); subject_end = SeqLocStop(search->query_slp->next); } else { s_shift = 0; subject_end = readdb_get_sequence_length(search->rdfp, search->subject_id); } /* Get offset shift if query is a subsequence */ q_shift = SeqLocStart(search->query_slp); for (hsp_index=0; hsp_index<search->current_hitlist->hspcnt; hsp_index++) { hsp = search->current_hitlist->hsp_array[hsp_index]; if (hsp==NULL || (search->pbp->cutoff_e > 0 && hsp->evalue > search->pbp->cutoff_e)) continue; /* Correct query context is already found in BlastGetNonSumStatsEvalue */ context = hsp->context; query_id = search->qid_array[context/2]; if (query_id == NULL) /* Bad hsp, something wrong */ continue; hsp->context = context & 1; query_length = search->query_context_offsets[context+1] - search->query_context_offsets[context] - 1; hsp->subject.end = hsp->subject.offset + hsp->subject.length; if (hsp->context) { hsp->query.end = query_length - hsp->query.offset; hsp->query.offset = hsp->query.end - hsp->query.length + 1; context_sign = '-'; } else { hsp->query.end = (++hsp->query.offset) + hsp->query.length - 1; if (hsp->query.end > query_length) { hsp->subject.end -= (hsp->query.end - query_length); hsp->query.end = query_length; } context_sign = '+'; } if (hsp->subject.end > subject_end) { hsp->query.end -= (hsp->subject.end - subject_end); hsp->subject.end = subject_end; } hsp->subject.offset++; query_buffer = NULL; if (query_id->choice == SEQID_LOCAL && search->pbp->mb_params->full_seqids) { BioseqPtr query_bsp = BioseqLockById(query_id); title = StringSave(BioseqGetTitle(query_bsp)); if (title) query_buffer = StringTokMT(title, " ", &title); else { Int4 query_gi; GetAccessionFromSeqId(query_bsp->id, &query_gi, &query_buffer); } BioseqUnlock(query_bsp); } else { query_buffer = (CharPtr) Malloc(BUFFER_LENGTH + 1); if (!search->pbp->mb_params->full_seqids) SeqIdWrite(query_id, query_buffer, PRINTID_TEXTID_ACCESSION, BUFFER_LENGTH); else SeqIdWrite(query_id, query_buffer, PRINTID_FASTA_LONG, BUFFER_LENGTH); } if (search->pbp->gap_open==0 && search->pbp->gap_extend==0) score = ((hsp->subject.length + hsp->query.length)* search->sbp->reward / 2 - hsp->score) / (search->sbp->reward - search->sbp->penalty); else score = hsp->score; if (context_sign == '+') { q_start = hsp->query.offset; q_end = hsp->query.end; } else { q_start = hsp->query.end; q_end = hsp->query.offset; } /* Adjust offsets if query is a subsequence, only for first query */ if (context < 2) { q_start += q_shift; q_end += q_shift; } hsp->subject.offset += s_shift; hsp->subject.end += s_shift; if (numeric_sip_type) fprintf(fp, "'%ld'=='%c%s' (%d %d %d %d) %d\n", (long) subject_gi, context_sign, query_buffer, hsp->subject.offset, q_start, hsp->subject.end, q_end, score); else fprintf(fp, "'%s'=='%c%s' (%d %d %d %d) %d\n", subject_buffer, context_sign, query_buffer, hsp->subject.offset, q_start, hsp->subject.end, q_end, score); MemFree(query_buffer); } if (!numeric_sip_type && subject_buffer != subject_descr) MemFree(subject_buffer); MemFree(subject_descr); sip = SeqIdSetFree(sip); return 0; }
Int2 Main (void) { Int2 argcount; Boolean flagHaveNet; Int4 gi; SeqEntryPtr sep; ComPatPtr cpp, cpph = NULL; SeqAlignPtr sap, sapn; StdSegPtr ssp; SeqLocPtr slp, slpn; Int4 start, stop; FILE *fiop; Char fastafile[256], namesfile[256]; CharPtr title; CharPtr taxon; FloatHi mw; ValNodePtr namelist = NULL; static CharPtr pattern_file = "ncbipros.dat"; static CharPtr protease_file = "ncbiendo.dat"; static CharPtr names_file = "ncbipnam.dat"; static GatherScope gs; GatherScopePtr gsp; static Gather_PBS gpbs; Gather_PBSPtr gpbsp; #ifndef NO_TAX_NET Int4 i; static Char taxdata[8]; static Gather_TaxId gti; Gather_TaxIdPtr gtip; #endif #ifndef NO_TAX_NET Int2 ia=4, ib=5, ic=6, id=7, ie=8, ig=9, ih=10, ii=11; #else Int2 ib=4, ic=5, id=6, ie=7, ig=8, ih=9, ii=10; #endif argcount = sizeof (myargs) / sizeof (Args); if (!GetArgs ("ProSiteSearch", argcount, myargs)) return 1; if (myargs[0].intvalue == 0 && myargs[1].strvalue == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 100, "No gi or FastA file given :: for help : srchaa -"); ErrShow (); exit (1); } gsp = &gs; #ifndef NO_TAX_NET gtip = >i; #endif gpbsp = &gpbs; MemSet ((Pointer) gsp, 0, sizeof (GatherScope)); MemSet ((Pointer) gsp->ignore, (int) (TRUE), (size_t) (OBJ_MAX * sizeof (Boolean))); gsp->ignore[OBJ_SEQDESC] = TRUE; gsp->ignore[OBJ_BIOSEQ] = FALSE; gpbsp->bsp = NULL; gi = myargs[0].intvalue; if (myargs[1].strvalue != NULL) StrCpy (fastafile, myargs[1].strvalue); else fastafile[0] = '\0'; if (gi > 0) { if (!EntrezInit ("srchaa", FALSE, &flagHaveNet)) { ErrPostEx (SEV_ERROR, TOP_ERROR, 102, "Entrez init failed"); ErrShow (); exit (1); } } #ifndef NO_TAX_NET if (myargs[ia].intvalue) { if (!TaxArchInit ()) { ErrPostEx (SEV_ERROR, TOP_ERROR, 103, "Taxonomy init failed"); ErrShow (); exit (1); } } #endif fiop = NULL; if (gi > 0) { sep = EntrezSeqEntryGet (gi, SEQENTRY_READ_BIOSEQ); } else { if ((fiop = FileOpen (fastafile, "r")) == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 103, "Failed to open FastA file: %s", fastafile); ErrShow (); exit (1); } sep = FastaToSeqEntry (fiop, FALSE); } if (sep == NULL) { ErrPostEx (SEV_ERROR, TOP_ERROR, 104, "No seqentry found"); ErrShow (); exit (1); } while (sep != NULL) { gsp->ignore[OBJ_SEQDESC] = TRUE; gsp->ignore[OBJ_BIOSEQ] = FALSE; gpbsp->bsp = NULL; gpbsp->gi = gi; GatherSeqEntry (sep, (Pointer) gpbsp, GetBioseq, (Pointer) gsp); taxon = NULL; #ifndef NO_TAX_NET if (myargs[ia].intvalue) { for (i = 0; i < 8; i++) taxdata[i] = '-'; taxon = taxdata; gsp->ignore[OBJ_SEQDESC] = FALSE; gsp->ignore[OBJ_BIOSEQ] = TRUE; gtip->taxid = 0; GatherSeqEntry (sep, (Pointer) gtip, GetTaxId, (Pointer) gsp); if (gtip->taxid != 0) WhatOrg (gtip->taxid, taxon); else taxon = NULL; } #endif if (gpbsp->bsp != NULL) { if (ISA_aa (gpbsp->bsp->mol)) { if (cpph == NULL) { namesfile[0] = '\0'; if (myargs[id].intvalue) StrCpy (namesfile, names_file); if (myargs[ie].strvalue != NULL) StrCpy (namesfile, myargs[ie].strvalue); if (myargs[ig].strvalue != NULL) { if ((cpph = CompilePattern (myargs[ig].strvalue, 1)) != NULL) StrCpy (cpph->name, "User Pattern"); } else { namelist = ReadPatternNames (namesfile); if (myargs[ib].intvalue) cpph = ReadPrositePattern (protease_file, (Boolean) myargs[2].intvalue, myargs[3].intvalue, taxon, NULL); else cpph = ReadPrositePattern (pattern_file, (Boolean) myargs[2].intvalue, myargs[3].intvalue, taxon, namelist); } } if (!(Boolean) myargs[ih].intvalue) { title = FastaTitle (gpbsp->bsp, ">", NULL); printf ("%s\n", title); MemFree (title); } cpp = cpph; while (cpp != NULL) { sap = PatternMatchBioseq (gpbsp->bsp, cpp, (Int4)myargs[ii].intvalue); if (myargs[ib].intvalue) { printf (">%s\n", cpp->name); if (sap != NULL) printf (" Start Stop M.W.\n"); } if (myargs[ib].intvalue) { EmbedMolecularWeightInfo (sap, gpbsp->bsp); if (myargs[ic].intvalue) URK_SeqAlignSortByMolWt (&sap); while (sap != NULL) { ssp = (StdSegPtr) sap->segs; slp = ssp->loc; start = SeqLocStart (slp); stop = SeqLocStop (slp); mw = ssp->scores->value.realvalue; printf ("%8ld %8ld %9.2f\n", (long) start+1, (long) stop+1, mw); sapn = sap->next; SeqAlignFree (sap); sap = sapn; } } else { slp = MatchSa2Sl (&sap); if (myargs[ih].intvalue && slp != NULL) { title = FastaTitle (gpbsp->bsp, ">", NULL); printf ("%s\n", title); MemFree (title); } while (slp != NULL) { start = SeqLocStart (slp); stop = SeqLocStop (slp); printf ("%8ld %8ld %s\n", (long) start+1, (long) stop+1, cpp->name); slpn = slp->next; SeqLocFree (slp); slp = slpn; } } cpp = cpp->nextpattern; } } else { ErrPostEx (SEV_ERROR, TOP_ERROR, 106, "Not a protein bioseq"); ErrShow (); exit (1); } } else { ErrPostEx (SEV_ERROR, TOP_ERROR, 105, "No bioseq found"); ErrShow (); exit (1); } SeqEntryFree (sep); sep = NULL; if (fiop != NULL) sep = FastaToSeqEntry (fiop, FALSE); } ComPatFree (cpph); ValNodeFreeData (namelist); FileClose (fiop); if (gi > 0) EntrezFini (); #ifndef NO_TAX_NET if (myargs[ia].intvalue) TaxArchFini (); #endif return 0; }
static Int2 LIBCALLBACK FilterMsgFunc (OMMsgStructPtr ommsp) { OMUserDataPtr omudp; GraphViewFormPtr gvp; SeqGraphPtr sgp; VieweR v; PoinT pt; PntInfo pw; Uint2 segID, primID, primCt, start, end, i; SegmenT s; PrimitivE p; FloatHi fval; Int4 pos; FloatHi maxVal, minVal; if ((omudp = (OMUserDataPtr) (ommsp->omuserdata)) == NULL) return OM_MSG_RET_ERROR; if ((gvp = (GraphViewFormPtr) (omudp->userdata.ptrvalue)) == NULL) return OM_MSG_RET_ERROR; switch (ommsp->message) { case OM_MSG_SELECT: if (ommsp->itemtype == OBJ_BIOSEQ) { if (ommsp->regiontype == OM_REGION_SEQLOC) { if ((sgp = gvp->sgp) == NULL) return OM_MSG_RET_ERROR; switch (sgp->flags[2]) { default: case 1: maxVal = sgp->max.realvalue; minVal = sgp->min.realvalue; break; case 2: case 3: maxVal = (FloatHi) sgp->max.intvalue; minVal = (FloatHi) sgp->min.intvalue; break; } if (gvp->slp != NULL) { v = gvp->viewer; pt.x = 0; pt.y = 0; s = FindSegment (v, pt, &segID, &primID, &primCt); ExploreSegment (s, v, UnHLSeg); /* ObjMgrDeSelectAll (); gvp->slp = NULL; */ } pos = SeqLocStart ((SeqLocPtr) ommsp->region); pos /= gvp->zoom; pw.x = (Int2) pos; v = gvp->viewer; primID = 0; fval = minVal - 1; while (primID < 1 && fval < maxVal) { fval++; pw.y = (Int2) (gvp->margin + ((Int4) (fval * sgp->a)) + (Int4) sgp->b); MapWorldToViewer (v, pw, &pt); s = FindSegment (v, pt, &segID, &primID, &primCt); } if (primCt == 0 && fval == maxVal) return OM_MSG_RET_ERROR; if (s == NULL) return OM_MSG_RET_ERROR; start = primCt; pos = SeqLocStop ((SeqLocPtr) ommsp->region); pos /= gvp->zoom; pw.x = (Int2) pos; primID = 0; fval = minVal - 1; while (primID < 1 && fval < maxVal) { fval++; pw.y = (Int2) (gvp->margin + ((Int4) (fval * sgp->a)) + (Int4) sgp->b); MapWorldToViewer (v, pw, &pt); s = FindSegment (v, pt, &segID, &primID, &primCt); } if (primCt == 0 || fval == maxVal) return OM_MSG_RET_ERROR; if (s == NULL) return OM_MSG_RET_ERROR; end = primCt; if (start > end) return OM_MSG_RET_ERROR; WatchCursor (); ExploreSegment (s, v, UnHLSeg); ArrowCursor (); for (i = start; i < end; i++) { p = GetPrimitive (s, i); HighlightPrimitive (v, s, p, FRAME_PRIMITIVE); } /* DUP/memcp and delta id gvp->slp = (Pointer) (ommsp->region); */ /* ObjMgrSelect (gvp->entityID, gvp->itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC, gvp->slp); */ } } break; case OM_MSG_DESELECT: if (ommsp->itemtype == OBJ_BIOSEQ) { if (ommsp->regiontype == OM_REGION_SEQLOC) { if (gvp->slp != NULL) { /* v = gvp->viewer; pt.x = 0; pt.y = 0; s = FindSegment (v, pt, &segID, &primID, &primCt); ExploreSegment (s, v, UnHLSeg); ObjMgrDeSelectAll (); gvp->slp = NULL; */ } } } break; case OM_MSG_DEL: case OM_MSG_CREATE: case OM_MSG_UPDATE: case OM_MSG_CACHED: case OM_MSG_UNCACHED: case OM_MSG_TO_CLIPBOARD: break; default: break; } return OM_MSG_RET_OK; }
SeqLocPtr SeqLocDust (SeqLocPtr this_slp, Int2 level, Int2 window, Int2 minwin, Int2 linker) { SeqLocPtr next_slp, slp = NULL; ValNodePtr vnp = NULL; SeqIdPtr id; BioseqPtr bsp; SeqPortPtr spp; DREGION PNTR reg, PNTR regold; Int4 nreg; Int4 start, end, l; Int2 loopDustMax = 0; /* error msg stuff */ ErrSetOptFlags (EO_MSG_CODES); if (!this_slp) { ErrPostEx (SEV_ERROR, 2, 1, "no sequence location given for dusting"); ErrShow (); return slp; } /* place for dusted regions */ regold = reg = MemNew (sizeof (DREGION)); if (!reg) { ErrPostEx (SEV_FATAL, 2, 2, "memory allocation error"); ErrShow (); return slp; } reg->from = 0; reg->to = 0; reg->next = NULL; /* count seqlocs */ next_slp = NULL; while ((next_slp = SeqLocFindNext (this_slp, next_slp)) != NULL) loopDustMax++; if (!loopDustMax) { ErrPostEx (SEV_ERROR, 2, 3, "can not find next seq loc"); ErrShow (); } /* loop for dusting as needed */ next_slp = NULL; while ((next_slp = SeqLocFindNext (this_slp, next_slp)) != NULL) { /* offsets into actual sequence */ start = SeqLocStart (next_slp); end = SeqLocStop (next_slp); /* if all goes okay should get a seqport pointer */ id = SeqLocId (next_slp); if (!id) { ErrPostEx (SEV_ERROR, 2, 4, "no bioseq id"); ErrShow (); continue; } bsp = BioseqLockById (id); if (!bsp) { ErrPostEx (SEV_ERROR, 2, 5, "no bioseq"); ErrShow (); continue; } if (!ISA_na (bsp->mol)) { ErrPostEx (SEV_WARNING, 2, 6, "not nucleic acid"); ErrShow (); BioseqUnlock (bsp); continue; } spp = SeqPortNew (bsp, start, end, 0, Seq_code_ncbi2na); BioseqUnlock (bsp); if (!spp) { ErrPostEx (SEV_ERROR, 2, 7, "sequence port open failed"); ErrShow (); continue; } l = spp->totlen; nreg = dust_segs (l, spp, start, reg, (Int4)level, (Int4)window, (Int4)minwin, (Int4)linker); slp = slpDust (spp, slp, id, &vnp, reg, nreg, loopDustMax); /* find tail - this way avoids referencing the pointer */ while (reg->next) reg = reg->next; SeqPortFree (spp); } /* clean up memory */ reg = regold; while (reg) { regold = reg; reg = reg->next; MemFree (regold); } return slp; }
static Int2 LIBCALLBACK MatrixMsgFunc (OMMsgStructPtr ommsp) { OMUserDataPtr omudp; GraphViewFormPtr gvp; SeqGraphPtr sgp; VieweR v; PoinT pt; PntInfo pw; Uint2 segID, primID, primCt; SegmenT s; PrimitivE p; Int4 pos; FloatHi maxVal; if ((omudp = (OMUserDataPtr) (ommsp->omuserdata)) == NULL) return OM_MSG_RET_ERROR; if ((gvp = (GraphViewFormPtr) (omudp->userdata.ptrvalue)) == NULL) return OM_MSG_RET_ERROR; switch (ommsp->message) { case OM_MSG_SELECT: if (ommsp->itemtype == OBJ_BIOSEQ) { if (ommsp->regiontype == OM_REGION_SEQLOC) { if ((sgp = gvp->sgp) == NULL) return OM_MSG_RET_ERROR; switch (sgp->flags[2]) { default: case 1: maxVal = sgp->max.realvalue; break; case 2: case 3: maxVal = (FloatHi) sgp->max.intvalue; break; } if (gvp->slp != NULL) { v = gvp->viewer; pt.x = 0; pt.y = 0; s = FindSegment (v, pt, &segID, &primID, &primCt); ExploreSegment (s, v, UnHLSeg); /* ObjMgrDeSelectAll (); gvp->slp = NULL; */ } pos = SeqLocStart ((SeqLocPtr) ommsp->region); pos += SeqLocStop ((SeqLocPtr) ommsp->region); pos /= 2; pos /= gvp->zoom; pw.x = (Int2) pos; if (SeqLocStrand ((SeqLocPtr) ommsp->region) == Seq_strand_plus) { pw.y = (Int2) (gvp->margin + ((Int4) (1.0 + (maxVal/2)) * sgp->a) + (Int4) sgp->b); } else { pw.y = (Int2) (gvp->margin + ((Int4) (maxVal - 1.0 - (maxVal/2)) * sgp->a) + (Int4) sgp->b); } v = gvp->viewer; primID = 0; MapWorldToViewer (v, pw, &pt); s = FindSegment (v, pt, &segID, &primID, &primCt); if (primID < 1 || s == NULL) return OM_MSG_RET_ERROR; p = GetPrimitive (s, primCt); WatchCursor (); ExploreSegment (s, v, UnHLSeg); ArrowCursor (); HighlightPrimitive (v, s, p, FRAME_PRIMITIVE); /* DUP/memcp and delta id gvp->slp = (Pointer) (ommsp->region); */ /* ObjMgrSelect (gvp->entityID, gvp->itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC, gvp->slp); */ } } break; case OM_MSG_DESELECT: if (ommsp->itemtype == OBJ_BIOSEQ) { if (ommsp->regiontype == OM_REGION_SEQLOC) { if (gvp->slp != NULL) { /* v = gvp->viewer; pt.x = 0; pt.y = 0; s = FindSegment (v, pt, &segID, &primID, &primCt); ExploreSegment (s, v, UnHLSeg); ObjMgrDeSelectAll (); gvp->slp = NULL; */ } } } break; case OM_MSG_DEL: case OM_MSG_CREATE: case OM_MSG_UPDATE: case OM_MSG_CACHED: case OM_MSG_UNCACHED: case OM_MSG_TO_CLIPBOARD: break; default: break; } return OM_MSG_RET_OK; }
extern SeqLocPtr FilterSigSeq (BioseqPtr bsp, ComProfPtr pppl, ComProfPtr pppc, FloatHi leadcutoff, FloatHi cutcutoff, Int4 range, SeqIdPtr sip, Boolean flagBoundaryCondition, Boolean flagReportIfAllFuzzyOnly) { Int4 lstart, lstop, cstart, cstop; FloatHi score; SeqAlignPtr sap1h, sap1, sap2h, sap2; StdSegPtr ssp1, ssp2; SeqLocPtr slp1, slp2; SeqLocPtr slp, slpt, slph = NULL; if (bsp == NULL || pppl == NULL || pppc == NULL) return NULL; sap1h = sap1 = ProfileMatchBioseq (bsp, pppl, NULL, leadcutoff, flagBoundaryCondition); sap2h = sap2 = ProfileMatchBioseq (bsp, pppc, NULL, cutcutoff, flagBoundaryCondition); if (flagReportIfAllFuzzyOnly) { score = leadcutoff * 0.9; score = leadcutoff + (leadcutoff - score); while (sap1 != NULL) { if (sap1->score->value.realvalue > score) { while (sap1h != NULL) { sap1 = sap1h->next; SeqAlignFree (sap1h); sap1h = sap1; } break; } sap1 = sap1->next; } score = cutcutoff * 0.9; score = cutcutoff + (cutcutoff - score); while (sap2 != NULL) { if (sap2->score->value.realvalue > score) { while (sap2h != NULL) { sap2 = sap2h->next; SeqAlignFree (sap2h); sap2h = sap2; } break; } sap2 = sap2->next; } } sap1 = sap1h; sap2 = sap2h; while (sap1 != NULL) { ssp1 = (StdSegPtr) sap1->segs; slp1 = ssp1->loc; lstart = SeqLocStart (slp1); lstop = SeqLocStop (slp1); if (range < 0 || lstop < range) { sap2 = sap2h; while (sap2 != NULL) { ssp2 = (StdSegPtr) sap2->segs; slp2 = ssp2->loc; cstart = SeqLocStart (slp2); cstop = SeqLocStop (slp2); if (cstart - lstop > 0 && cstart - lstop < 8) { slpt = slph; while (slpt != NULL) { if (cstop == SeqLocStop (slpt)) break; slpt = slpt->next; } if (slpt == NULL) { slp = SeqLocIntNew (lstart, cstop, Seq_strand_unknown, sip); ValNodeLink (&slph, slp); } } sap2 = sap2->next; } } sap1 = sap1->next; } while (sap1h != NULL) { sap1 = sap1h->next; SeqAlignFree (sap1h); sap1h = sap1; } while (sap2h != NULL) { sap2 = sap2h->next; SeqAlignFree (sap2h); sap2h = sap2; } return slph; }