/***************************************************************************** * * PrintIdDefLine * SeqEntryExplore callback routine that prints the seqids and definition * lines. * *****************************************************************************/ static void PrintIdDefLine (SeqEntryPtr sep, Pointer data, Int4 index, Int2 indent) { BioseqPtr bsp; FILE * fp; Char buf[40]; CharPtr title = NULL; if (IS_Bioseq (sep)) { *buf = '\0'; bsp = (BioseqPtr) sep->data.ptrvalue; fp = (FILE *) data; title = BioseqGetTitle(bsp); /* this does not deal with all cases */ SeqIdPrint(bsp->id, buf, PRINTID_FASTA_LONG); /* print SeqId */ if (pmon != NULL) MonitorStrValue(pmon, buf); fprintf(fp, ">%s", buf); if (title != NULL) fprintf(fp, " %s", title); fprintf(fp, "\n"); } return; }
static void PrintSequence (BioseqPtr bsp, SeqFeatPtr sfp, FILE *fp, Boolean is_na) { Char buffer [255]; Uint1 code; Int2 count; Uint1 repr; Uint1 residue; SeqPortPtr spp; CharPtr title; CharPtr tmp; if (bsp != NULL && fp != NULL) { if ((Boolean) ISA_na (bsp->mol) == is_na) { repr = Bioseq_repr (bsp); if (repr == Seq_repr_raw || repr == Seq_repr_const) { title = BioseqGetTitle (bsp); tmp = StringMove (buffer, ">"); tmp = SeqIdPrint (bsp->id, tmp, PRINTID_FASTA_LONG); tmp = StringMove (tmp, " "); StringNCpy (tmp, title, 200); fprintf (fp, "%s\n", buffer); if (pmon != NULL) MonitorStrValue(pmon, buffer); if (is_na) { code = Seq_code_iupacna; } else { code = Seq_code_iupacaa; } if (sfp != NULL) { spp = SeqPortNewByLoc (sfp->location, code); } else { spp = SeqPortNew (bsp, 0, -1, 0, code); } if (spp != NULL) { count = 0; while ((residue = SeqPortGetResidue (spp)) != SEQPORT_EOF) { if (! IS_residue (residue)) { buffer [count] = '\0'; fprintf (fp, "%s\n", buffer); count = 0; switch (residue) { case SEQPORT_VIRT : fprintf (fp, "[Gap]\n"); break; case SEQPORT_EOS : fprintf (fp, "[EOS]\n"); break; default : fprintf (fp, "[Invalid Residue]\n"); break; } } else { buffer [count] = residue; count++; if (count >= CHARSPERLINE) { buffer [count] = '\0'; fprintf (fp, "%s\n", buffer); count = 0; } } } if (count != 0) { buffer [count] = '\0'; fprintf (fp, "%s\n", buffer); } SeqPortFree (spp); } } } } }
static void GetPubFromGenBank (SeqEntryPtr sep, Pointer data, Int4 index, Int2 indent) { BioseqPtr bsp; BioseqContextPtr bcp; SeqFeatPtr sfp; ValNodePtr vnp; FILE * fp; CharPtr accession = NULL; ValNode tpub; TextSeqIdPtr tsip; PubdescPtr pdp; Char buf[40]; if (! IS_Bioseq(sep)) return; fp = (FILE *) data; /* get the output file pointer */ bsp = (BioseqPtr) sep->data.ptrvalue; if (pmon != NULL) { *buf = '\0'; SeqIdPrint(bsp->id, buf, PRINTID_FASTA_LONG); MonitorStrValue(pmon, buf); } for (vnp = bsp->id; ((vnp != NULL) && (accession == NULL)); vnp = vnp->next) { switch (vnp->choice) { case SEQID_GENBANK: case SEQID_EMBL: case SEQID_DDBJ: tsip = (TextSeqIdPtr)(vnp->data.ptrvalue); if (tsip->accession != NULL) accession = tsip->accession; break; default: break; } } if (accession == NULL) return; bcp = BioseqContextNew(bsp); if (bcp == NULL) return; vnp = NULL; tpub.choice = PUB_Equiv; tpub.next = NULL; /* get any pub descriptors */ while ((vnp = BioseqContextGetSeqDescr(bcp, (Int2)Seq_descr_pub, vnp, NULL)) != NULL) { pdp = (PubdescPtr)(vnp->data.ptrvalue); /* it's a Pubdesc */ tpub.data.ptrvalue = pdp->pub; /* make Pub-equiv into a Pub */ PubWrite(accession, &tpub, fp); } sfp = NULL; while ((sfp = BioseqContextGetSeqFeat(bcp, 0, sfp, NULL, 0)) != NULL) { if (sfp->data.choice == 6) /* a pub feature */ { pdp = (PubdescPtr)(sfp->data.value.ptrvalue); tpub.data.ptrvalue = pdp->pub; PubWrite(accession, &tpub, fp); } /* get any feature citations */ if (sfp->cit != NULL) { for (vnp = sfp->cit->data.ptrvalue; vnp != NULL; vnp = vnp->next) PubWrite(accession, vnp, fp); } } BioseqContextFree(bcp); return; }
void BioseqRawToRaw(BioseqPtr bsp, Boolean idonly, short whichSeq, short *seqnum, char **seq, char **seqid, long *seqlen) { SeqPortPtr spp; SeqIdPtr bestid; Uint1 repr, code, residue; CharPtr tmp, title; long outlen, outmax; char localid[256], *sp; /* !!! this may be called several times for a single sequence because SeqEntryExplore looks for parts and joins them... assume seq, seqid, seqlen may contain data (or NULL) */ if (bsp == NULL) return; repr = Bioseq_repr(bsp); if (!(repr == Seq_repr_raw || repr == Seq_repr_const)) return; (*seqnum)++; if (!(whichSeq == *seqnum || whichSeq == 0)) return; bestid = SeqIdFindBest(bsp->id, (Uint1) 0); title = BioseqGetTitle(bsp); if (idonly) { sprintf(localid, " %d) ", *seqnum); tmp= localid + strlen(localid)-1; } else { strcpy(localid," "); tmp= localid; } tmp = SeqIdPrint(bestid, tmp, PRINTID_FASTA_SHORT); tmp = StringMove(tmp, " "); StringNCpy(tmp, title, 200); /* fprintf(stderr,"BioseqRawToRaw: localid='%s'\n",localid); */ /* < seqid is fixed storage */ /* strcpy( *seqid, localid); */ /* < seqid is variable sized */ outmax= strlen(localid) + 3; if (*seqid==NULL) { *seqid= (char*) malloc(outmax); if (*seqid==NULL) return; strcpy(*seqid, localid); } else { outmax += strlen(*seqid) + 2; *seqid= (char*) realloc( *seqid, outmax); if (*seqid==NULL) return; if (!idonly) strcat(*seqid, "; "); strcat(*seqid, localid); } if (idonly) { strcat(*seqid,"\n"); return; } if (ISA_na(bsp->mol)) code = Seq_code_iupacna; else code = Seq_code_iupacaa; spp = SeqPortNew(bsp, 0, -1, 0, code); SeqPortSeek(spp, 0, SEEK_SET); sp= *seq; if (sp==NULL) { /* this is always true now !? */ outlen= 0; outmax= 500; sp= (char*) malloc(outmax); } else { outlen= strlen(sp); outmax= outlen + 500; sp= (char*) realloc( sp, outmax); } if (sp==NULL) return; while ((residue = SeqPortGetResidue(spp)) != SEQPORT_EOF) { if (outlen>=outmax) { outmax= outlen + 500; sp= (char*) realloc(sp, outmax); if (sp==NULL) return; } sp[outlen++] = residue; } sp= (char*) realloc(sp, outlen+1); if (sp!=NULL) sp[outlen]= '\0'; *seq= sp; *seqlen= outlen; SeqPortFree(spp); return; }