19 #pragma segment ureadasn
23 #define kBaseNucleic 1
26 typedef struct tofasta {
32 } FastaDat, PNTR FastaPtr;
35 void BioseqRawToRaw(BioseqPtr bsp,
Boolean idonly,
37 char **
seq,
char **seqid,
long *seqlen)
41 Uint1 repr, code, residue;
44 char localid[256], *sp;
50 if (bsp == NULL)
return;
51 repr = Bioseq_repr(bsp);
52 if (!(repr == Seq_repr_raw || repr == Seq_repr_const))
return;
55 if (!(whichSeq == *seqnum || whichSeq == 0))
return;
57 bestid = SeqIdFindBest(bsp->id, (Uint1) 0);
58 title = BioseqGetTitle(bsp);
60 sprintf(localid,
" %d) ", *seqnum);
61 tmp= localid + strlen(localid)-1;
67 tmp = SeqIdPrint(bestid, tmp, PRINTID_FASTA_SHORT);
68 tmp = StringMove(tmp,
" ");
69 StringNCpy(tmp, title, 200);
75 outmax= strlen(localid) + 3;
77 *seqid= (
char*) malloc(outmax);
78 if (*seqid==NULL)
return;
79 strcpy(*seqid, localid);
82 outmax += strlen(*seqid) + 2;
83 *seqid= (
char*) realloc( *seqid, outmax);
84 if (*seqid==NULL)
return;
85 if (!idonly) strcat(*seqid,
"; ");
86 strcat(*seqid, localid);
94 if (ISA_na(bsp->mol)) code = Seq_code_iupacna;
95 else code = Seq_code_iupacaa;
96 spp = SeqPortNew(bsp, 0, -1, 0, code);
97 SeqPortSeek(spp, 0, SEEK_SET);
103 sp= (
char*) malloc(outmax);
107 outmax= outlen + 500;
108 sp= (
char*) realloc( sp, outmax);
110 if (sp==NULL)
return;
112 while ((residue = SeqPortGetResidue(spp)) != SEQPORT_EOF) {
113 if (outlen>=outmax) {
114 outmax= outlen + 500;
115 sp= (
char*) realloc(sp, outmax);
116 if (sp==NULL)
return;
118 sp[outlen++] = residue;
120 sp= (
char*) realloc(sp, outlen+1);
121 if (sp!=NULL) sp[outlen]=
'\0';
129 static void SeqEntryRawseq(SeqEntryPtr sep, Pointer data, Int4 index, Int2
indent)
134 if (!IS_Bioseq(sep))
return;
135 bsp = (BioseqPtr)sep->data.ptrvalue;
136 tfa = (FastaPtr) data;
137 BioseqRawToRaw(bsp, tfa->idonly, tfa->whichSeq, tfa->seqnum,
138 tfa->seq, tfa->seqid, tfa->seqlen);
141 void SeqEntryToRaw(SeqEntryPtr sep,
Boolean idonly,
short whichSeq,
short *seqnum,
142 char **seq,
char **seqid,
long *seqlen)
146 if (sep == NULL)
return;
153 SeqEntryExplore(sep, (Pointer)&tfa, SeqEntryRawseq);
159 char *listASNSeqs(
const char *filename,
const long skiplines,
161 short *nseq,
short *
error )
165 AsnTypePtr atp, atp2;
169 char *seqid = NULL, stemp[256];
178 if (! SeqEntryLoad())
goto errxit;
179 amp = AsnAllModPtr();
180 if (amp == NULL)
goto errxit;
181 atp = AsnFind(
"Bioseq-set");
182 if (atp == NULL)
goto errxit;
183 atp2 = AsnFind(
"Bioseq-set.seq-set.E");
184 if (atp2 == NULL)
goto errxit;
189 if ((aip = AsnIoOpen(filename, inIsBinary?
"rb":
"r")) == NULL)
goto errxit;
190 for (i=0; i<skiplines; i++) fgets( stemp, 255, aip->fp);
192 if (! ErrSetLog (
"stderr"))
goto errxit;
193 else ErrSetOpts(ERR_CONTINUE, ERR_LOG_ON);
197 the_set = SeqEntryAsnRead(aip, NULL);
198 SeqEntryToRaw(the_set,
true, 0, nseq, &seq, &seqid, &seqlen);
199 if (seq) free(seq); seq= NULL;
200 SeqEntryFree(the_set);
205 while ((atp = AsnReadId(aip, amp, atp)) != NULL) {
207 the_set = SeqEntryAsnRead(aip, atp);
208 SeqEntryToRaw(the_set,
true, 0, nseq, &seq, &seqid, &seqlen);
209 SeqEntryFree(the_set);
210 if (seq) free(seq); seq= NULL;
213 AsnReadVal(aip, atp, NULL);
224 if (seqid) free(seqid);
230 char *readASNSeq(
const short whichEntry,
const char *filename,
231 const long skiplines,
233 long *seqlen,
short *nseq,
234 short *error,
char **seqid )
238 AsnTypePtr atp, atp2;
241 char *
seq, stemp[200];
251 if (! SeqEntryLoad())
goto errxit;
252 amp = AsnAllModPtr();
253 if (amp == NULL)
goto errxit;
254 atp = AsnFind(
"Bioseq-set");
255 if (atp == NULL)
goto errxit;
256 atp2 = AsnFind(
"Bioseq-set.seq-set.E");
257 if (atp2 == NULL)
goto errxit;
261 if ((aip = AsnIoOpen(filename, inIsBinary?
"rb":
"r")) == NULL)
goto errxit;
262 for (i=0; i<skiplines; i++) fgets( stemp, 255, aip->fp);
264 if (! ErrSetLog (
"stderr"))
goto errxit;
265 else ErrSetOpts(ERR_CONTINUE, ERR_LOG_ON);
270 the_set = SeqEntryAsnRead(aip, NULL);
271 SeqEntryToRaw(the_set,
false, whichEntry, nseq, &seq, seqid, seqlen);
272 SeqEntryFree(the_set);
279 while ((atp = AsnReadId(aip, amp, atp)) != NULL) {
281 the_set = SeqEntryAsnRead(aip, atp);
282 SeqEntryToRaw(the_set,
false, whichEntry, nseq, &seq, seqid, seqlen);
283 SeqEntryFree(the_set);
284 if (*nseq >= whichEntry)
goto goodexit;
287 AsnReadVal(aip, atp, NULL);
AliDataPtr format(AliDataPtr data, const size_t wanted_len, GB_ERROR &error)
static void error(const char *msg)