static void DoFastaTrans ( SeqFeatPtr sfp, Pointer userdata ) { ByteStorePtr bs; CSpeedFlagPtr cfp; CharPtr seq, str; if (sfp == NULL) return; cfp = (CSpeedFlagPtr) userdata; if (cfp == NULL) return; if (sfp->data.choice != SEQFEAT_CDREGION) return; bs = ProteinFromCdRegion (sfp, FALSE); if (bs == NULL) return; seq = (CharPtr) BSMerge (bs, NULL); BSFree (bs); if (seq == NULL) return; if (cfp->ofp != NULL) { str = SeqLocPrint (sfp->location); if (str != NULL) { fprintf (cfp->ofp, "> (%s)\n", str); MemFree (str); } fprintf (cfp->ofp, "%s\n", seq); } MemFree (seq); }
/***************************************************************************** * * StdAuthListNamesPrint(dvp) * prints just Auth-list.names to a string * *****************************************************************************/ NLM_EXTERN CharPtr StdAuthListNamesPrint(DataValPtr dvp) { AuthListPtr alp; Boolean first = TRUE; ValNodePtr vnp; PersonIdPtr pip; AuthorPtr ap; ByteStorePtr bsp; CharPtr str; Char buf[60]; if (dvp == NULL) return NULL; alp = (AuthListPtr)(dvp->ptrvalue); if (alp == NULL) return NULL; bsp = BSNew(80); for (vnp = alp->names; vnp != NULL; vnp = vnp->next) { if (! first) /* separators for names after first one */ { if (vnp->next != NULL) BSPutByte(bsp, (Int2)','); else { BSPutByte(bsp, (Int2)' '); BSPutByte(bsp, (Int2)'&'); } BSPutByte(bsp, (Int2)' '); } first = FALSE; if (alp->choice == 3 || alp->choice == 2) /* ml or str */ { BSWrite(bsp, vnp->data.ptrvalue, (Int4)(StringLen((CharPtr)(vnp->data.ptrvalue)))); } else if (alp->choice == 1) /* std */ { ap = (AuthorPtr) (vnp->data.ptrvalue); if (ap != NULL) { pip = ap->name; PersonIdPrint(pip, buf); BSWrite(bsp, buf, (Int4)StringLen(buf)); } else BSPutByte(bsp, (Int2)'?'); } } str = BSMerge(bsp, NULL); BSFree(bsp); return str; }
static Pointer AsnLexReadStringEx (AsnIoPtr aip, AsnTypePtr atp, Uint1 fix_non_print) { Int2 token; ByteStorePtr ssp; CharPtr result=NULL; Int4 bytes; token = AsnLexWordEx (aip, fix_non_print); /* read the start */ if (token != START_STRING) { AsnIoErrorMsg(aip, 43, AsnErrGetTypeName(atp->name), aip->linenumber); return NULL; } ssp = BSNew(0); if (ssp == NULL) return result; token = AsnLexWordEx (aip, fix_non_print); /* read the string(s) */ while (token == IN_STRING) { bytes = BSWrite(ssp, aip->word, (Int4)aip->wordlen); if (bytes != (Int4)(aip->wordlen)) { BSFree(ssp); return result; } token = AsnLexWord(aip); } if (token == ERROR_TOKEN) return NULL; if (token != END_STRING) { AsnIoErrorMsg(aip, 44, AsnErrGetTypeName(atp->name), aip->linenumber); return NULL; } if (AsnFindBaseIsa(atp) == STRSTORE_TYPE) /* string store */ return ssp; result = (CharPtr) BSMerge(ssp, NULL); BSFree(ssp); return result; }
/***************************************************************************** * * StdFormatPrint(data, func, templatename, options) * *****************************************************************************/ NLM_EXTERN Boolean StdFormatPrint (Pointer data, AsnWriteFunc func, CharPtr templatename, StdPrintOptionsPtr options) { PrintStackPtr psp; CharPtr ptr = NULL; PrintFormatListPtr pflp; if ((data == NULL) || (func == NULL) || (templatename == NULL) || (options == NULL)) return FALSE; pflp = PrintFormatListGet(templatename); if (pflp == NULL) return FALSE; if (options->fp == NULL) { options->bstp = BSNew(80); options->ptr = NULL; } psp = PrintStackBuild(data, func, pflp); /*** printf("Before sort\n"); PrintStackDump(psp, stdout, 0); ***/ PrintStackSort(psp); /*** printf("After sort\n"); PrintStackDump(psp, stdout, 0); printf("\n\n"); ***/ PrintStackPrint(psp, options); PrintStackFree(psp); if (options->fp == NULL) { if (BSLen(options->bstp)) options->ptr = BSMerge(options->bstp, NULL); BSFree(options->bstp); } return TRUE; }
static void Get_Sequence (FILE *f, SeqRecPtr seqrp) { Char ch; CharPtr chptr; Boolean goOn; IdRecPtr last; Int4 len; Char str [256]; IdRecPtr this; Int4 total; if (f != NULL && seqrp != NULL) { if (seqrp->rawSeq == NULL) { seqrp->rawSeq = BSNew (1000); } if (seqrp->segLens == NULL) { seqrp->segLens = BSNew (10); } len = 0; total = 0; goOn = TRUE; while (goOn && ReadNextLine (f, str, sizeof (str))) { if (str [0] == '&') { goOn = FALSE; } else if (str [0] == '!') { goOn = FALSE; } else if (str [0] == '>') { if (len > 0) { if (seqrp->lookForStop) { BSPutByte (seqrp->rawSeq, (Int2) '*'); len++; } BSWrite (seqrp->segLens, &len, sizeof (Int4)); total += len; len = 0; } chptr = StringChr (str, ' '); if (chptr != NULL) { *chptr = '\0'; } if (seqrp->ids != NULL) { last = seqrp->ids; while (last->next != NULL) { last = last->next; } this = MemNew (sizeof (IdRec)); if (this != NULL) { this->id.accn = StringSave (str + 1); } last->next = this; } else { last = MemNew (sizeof (IdRec)); if (last != NULL) { last->id.accn = StringSave (str + 1); } seqrp->ids = last; } } else if (str [0] != '\0') { chptr = str; while (*chptr != '\0') { ch = TO_UPPER (*chptr); if (ch >= 'A' && ch <= 'Z') { if (seqrp->nuc) { if (ch == 'U') { ch = 'T'; } if (StringChr ("BDEFHIJKLMOPQRSUVWXYZ", ch) == NULL) { BSPutByte (seqrp->rawSeq, (Int2) ch); len++; } } else { if (StringChr ("JOU", ch) == NULL) { BSPutByte (seqrp->rawSeq, (Int2) ch); len++; } } } chptr++; } } } if (seqrp->nuc) { BSPutByte (seqrp->rawSeq, (Int2) 'N'); BSPutByte (seqrp->rawSeq, (Int2) 'N'); BSPutByte (seqrp->rawSeq, (Int2) 'N'); len += 3; } if (len > 0) { if (seqrp->lookForStop) { BSPutByte (seqrp->rawSeq, (Int2) '*'); len++; } BSWrite (seqrp->segLens, &len, sizeof (Int4)); total += len; len = 0; } if (total > 0) { seqrp->sequence = BSMerge (seqrp->rawSeq, NULL); seqrp->length = total; } else { seqrp->sequence = NULL; seqrp->length = 0; } } }