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); } } } } }
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; }