PCSAN LIBCALL LoadCSAN(CharPtr pcFile) { FILE *f; Char fullpath [PATH_MAX]; CharPtr ptr; PCSAN pcsanHead = NULL; PCSAN pcsanTemp = NULL; Char pcBuf[250]; CharPtr ppcParse[125]; CharPtr pcTemp = NULL; CharPtr pcTest = NULL; CharPtr pcSeqPart = NULL; ValNodePtr pvn = NULL; long int val = 0; Int4 i = 0; Int4 iString = 0; Int4 iLen =0; Int4 iWC =0; Int4 iWL = 0; Int4 iGi = 0; if (!pcFile) return(NULL); ProgramPath (fullpath, sizeof (fullpath) - 1); ptr = StringRChr (fullpath, DIRDELIMCHR); if (ptr != NULL) { *ptr = '\0'; } /* printf("FULLPATH[%s]\n",IsNullStr(fullpath)); */ FileBuildPath (fullpath, NULL, pcFile); /* printf("FULLPATH[%s]\n",IsNullStr(fullpath)); */ if ((f = FileOpen (fullpath, "r")) == NULL) { if (FindPath ("NCBI", "NCBI", "DATA", fullpath, sizeof (fullpath) - 1)) { FileBuildPath (fullpath, NULL, pcFile); f = FileOpen (fullpath, "r"); if (f == NULL) { ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s] in LoadCSA", IsNullStr(fullpath)); return (NULL); } } else { ErrPost(CTX_NCBIOBJ, 1, "FindPath failed in LoadNeighbors"); return (NULL); } } do /* get each line, tokenize into ppcParse */ { pcBuf[0] = '\0'; pcTest = fgets(pcBuf, (size_t)250, f); /* printf("[%s]\n",IsNullStr(pcTest)); */ if (pcTest) { iLen = StringLen(pcTest); /* Break into words delimited by whitespace or "|" */ /* gi|123456| */ /* printf("LineLength %d\n",(int) iLen); */ for (i=0; i < 125; i++) ppcParse[i] = NULL; pcTemp = pcTest; ppcParse[0] = pcTest; iWC = 1; while ((*pcTemp != '\0') && (iWC < 125)) { if ((*pcTemp == '|') || (*pcTemp == ' ') || (*pcTemp == '\t') || (*pcTemp == '\n')) { *pcTemp = '\0'; /* terminate current word */ do { pcTemp++; /* skip whitespace to next word */ } while ((*pcTemp == '|') || (*pcTemp == ' ') || (*pcTemp == '\t') || (*pcTemp == '\n')); ppcParse[iWC] = pcTemp; /* start next word */ iWC++; } else pcTemp++; } /* DEBUG TEST */ /* for (i=0; i<125; i++) if (ppcParse[i] != NULL) { printf("%ld/%ld [%s]\n",i,iWC, IsNullStr(ppcParse[i])); } */ /* If ppcParse[0] is "gi" then this is a VALID sequence line and the last word parsed is the sequence */ if (ppcParse[0][0] != '\0') { iWL = StringLen(ppcParse[0]); if (iWL == 2) if (((ppcParse[0][0] == 'g') || (ppcParse[0][0] == 'G')) && ((ppcParse[0][1] == 'i') || (ppcParse[0][1] == 'I'))) { /* next word should be GI */ iGi = 0; if (StrToInt4 (ppcParse[1], &iGi)) { /* printf("GI is (%ld)\n",iGi); */ if (iGi == 0) goto parserr; /* find the 2nd last string = sequence */ /* last string is stripped off line terminator, by the way... */ iString=2; /* start after GI */ while (ppcParse[iString+1] != NULL) { /* iString is the LAST sting - line terminator */ iString++; } pcsanTemp = pcsanHead; while (pcsanTemp) { /* look for existing pcsan */ if (iGi == pcsanTemp->iGi) { break; } pcsanTemp = pcsanTemp->next; } if (!pcsanTemp) /* otherwise add a new one */ { pcsanTemp = NewCSAN(); pcsanTemp->next = pcsanHead; pcsanHead = pcsanTemp; /* put at head of list */ pcsanTemp->iGi = iGi; } /* Initialize fields */ pcSeqPart = NULL; pcSeqPart = StringSave(ppcParse[iString-1]); /* printf("SEQ [%ld]= [%s]\n",(long) iString-1, IsNullStr(pcSeqPart)); */ ValNodeAddStr(&pcsanTemp->pvnSeqAlnPart, 0, pcSeqPart); } /* if GI */ } /* if line starts with GI */ } /* if line starts with a word */ } /* if pcTest */ } while (pcTest); printf("REPORT\n"); pcsanTemp = pcsanHead; while (pcsanTemp) { printf("GI = [%ld]\n", (long) pcsanTemp->iGi); pvn = pcsanTemp->pvnSeqAlnPart; while (pvn) { printf(">%s<\n",(char *) IsNullStr(pvn->data.ptrvalue)); pvn = pvn->next; } pcsanTemp = pcsanTemp->next; } FileClose(f); return pcsanHead; parserr: FileClose(f); ErrPostEx(SEV_FATAL,0,0, "Error in input format \n"); FreeCSAN(pcsanHead); return NULL; }
BiostrucPtr LIBCALL MMDBBiostrucGet (DocUid uid, Int4 mdlLvl, Int4 maxModels) { AsnIoPtr aip = NULL; BiostrucPtr pbs = NULL; int index; Int4 acc; #ifdef MMDB_PUBSTRUCT extern WWWInfoPtr info; if(!file_db) { Int4 state = 0; char *dbserver = (database[0]?database:NULL); acc = uid; if(WWWFindName(info, "ps_acc") >=0) aip = PubStruct_readasn(dbserver, acc); else { index = WWWFindName(info, "ps_state"); if (index >= 0) { char * item; item = WWWGetValueByIndex(info,index); if (!StrToInt4(item,&state)) ErrPostEx(SEV_ERROR,0,0, "cant convert Pubstruct_state<%s> into integer",item); } if (state == 0 ) aip = PubStruct_viewasn(dbserver, uid); else { acc = PubStruct_lookup(dbserver,uid, state); /* fprintf(stderr,"%s:%d: acc=%d <<- %s(mmdb=%d,state=%d)\n", __FILE__,__LINE__,acc,dbserver,uid,state); */ if (acc>0) aip = PubStruct_readasn(dbserver, acc); } } } else #endif { Char path[PATH_MAX]; sprintf(path, "%s%ld.val", database, (long) uid); #ifdef MMDB_UNIXCOMPRESSED { FILE *pipe; Char compath[PATH_MAX]; sprintf(compath,"%s -c %s.gz ", gunzip, path); pipe=popen(compath,"rb"); if (pipe == 0) { ErrPostEx(SEV_FATAL,0,0, "MMDBBiostrucGet failed: Can't find gunzip in path.\n"); return NULL; } aip = AsnIoNew(ASNIO_BIN_IN, pipe , NULL, NULL, NULL); } #else if (FileLength(path) == 0) return NULL; aip = AsnIoOpen(path, "rb"); #endif } if (!aip) return NULL; pbs = BiostrucAsnGet(aip, NULL, mdlLvl, maxModels); #ifdef MMDB_PUBSTRUCT if(!file_db) PubStruct_closeasn (aip,1); else #endif AsnIoClose (aip); return pbs; }