示例#1
0
AsnIoPtr CreateAsnConn(CONN               conn,
                       EAsnConn_Direction direction,
                       EAsnConn_Format    fmt)
{
    /* NB: Do not use ASNIO_{TEXT|BIN}_{IN|OUT} because they subsume FILE */
    AsnIoPtr aip;
    int type;

    switch (fmt) {
    case eAsnConn_Binary:
        type = ASNIO_BIN;
        break;
    case eAsnConn_Text:
        type = ASNIO_TEXT;
        break;
    default:
        return 0;
    }

    switch (direction) {
    case eAsnConn_Input:
        aip = AsnIoNew(type | ASNIO_IN,  0, (void*) conn, s_AsnRead, 0);
        break;
    case eAsnConn_Output:
        aip = AsnIoNew(type | ASNIO_OUT, 0, (void*) conn, 0, s_AsnWrite);
        break;
    default:
        return 0;
    }

    if (aip)
        s_SetAsnConn_CloseCb(conn, aip);
    return aip;
}
示例#2
0
NLM_EXTERN AsnIoConnPtr QUERY_AsnIoConnOpen (
  const char* mode,
  CONN conn
)
{
  Int1          type;
  AsnIoConnPtr  aicp;

  if (strcmp(mode, "r") == 0)
    type = (ASNIO_IN | ASNIO_TEXT);
  else if (strcmp(mode, "rb") == 0)
    type = (ASNIO_IN | ASNIO_BIN);
  else if (strcmp(mode, "w") == 0)
    type = (ASNIO_OUT | ASNIO_TEXT);
  else if (strcmp(mode, "wb") == 0)
    type = (ASNIO_OUT | ASNIO_BIN);
  else {
    AsnIoErrorMsg (NULL, 81, mode);
    return NULL;
  }

  aicp = (AsnIoConnPtr) MemNew (sizeof (AsnIoConn));
  aicp->aip = AsnIoNew (type, NULL, (Pointer) aicp, AsnIoConnRead, AsnIoConnWrite);
  aicp->conn = conn;
  return aicp;
}
示例#3
0
static void SeqEntryToFeat (SeqEntryPtr sep, FILE *fp)

{
  AsnExpOptPtr  aeop;
  AsnIoPtr      aip;
  ExpStructPtr  esp;

  if (sep != NULL && fp != NULL) {
    esp = MemNew (sizeof (ExpStruct));
    if (esp != NULL) {
      aip = AsnIoNullOpen ();
      if (aip != NULL) {
        esp->fp = fp;
        esp->aip = AsnIoNew (ASNIO_TEXT_OUT, fp, NULL, NULL, NULL);
        esp->is_na = is_na;
        esp->feat = 3;  /* look for CdRegion SeqFeat */
        aeop = AsnExpOptNew (aip, "Seq-feat", (Pointer) esp, GetSeqFeat);
        if (aeop != NULL) {
          SeqEntryAsnWrite (sep, aip, NULL);
          fflush (fp);
          AsnExpOptFree (aip, aeop);
        }
        AsnIoClose (aip);
      }
      MemFree (esp);
    }
  }
}
示例#4
0
BiostrucAnnotSetPtr LIBCALL VASTBsAnnotSetGet (Int4 uid)
{
   AsnIoPtr aip = NULL;
   AsnTypePtr atp = NULL;
   Char path[PATH_MAX];
   Char compath[PATH_MAX];
   Char tempfile[PATH_MAX];
   Char pcId[20];    
   Int2 iFileExists = 0;
   BiostrucAnnotSetPtr pbsa = NULL;
   int iAvail = 1;
   FILE *pipe;

   sprintf(pcId, "%ld", (long) uid);
   path[0] = '\0';
   StringCpy(path, database);
   StringCat(path, pcId);
   StringCat(path, ".bas");

#ifdef MMDB_UNIXCOMPRESSED
   compath[0] = '\0';
   sprintf(compath, "%s -d -c %s.gz ", gunzip, path);
   pipe = popen(compath, "rb");

   if (pipe == NULL) {
       ErrPostEx(SEV_FATAL,0,0, "VASTBsAnnotSetGet failed: Can't find gunzip in path.\n");
       return NULL;
   }

   aip = AsnIoNew(ASNIO_BIN_IN, pipe, NULL, NULL, NULL);
#else
   iFileExists = FileLength(path);
   if (iFileExists == 0)
      {
        return NULL;
      }
      
    aip = AsnIoOpen(path, "rb");
#endif

    if (aip) 
     {
       pbsa = BiostrucAnnotSetAsnRead(aip, NULL);
       AsnIoClose (aip);
     }

#ifdef MMDB_UNIXCOMPRESSED 
    pclose(pipe);
#endif

    if (!pbsa) return NULL;  
    return pbsa;
} 
示例#5
0
static
int	mfmt_init_output( void *handle, char *file_name, FILE *fd )
{
    /* Open the file using the AsnIoOpen routine */

    asn_hand->ioptr = AsnIoNew( (asn_hand->mode == binary) ?
	ASNIO_BIN_OUT : ASNIO_TEXT_OUT, fd, NULL, NULL, NULL );
    if( asn_hand->ioptr == NULL ) {
	asn_hand->have_error = ErrFetch( &asn_hand->error );
    } else {
	asn_hand->have_error = FALSE;
	asn_hand->open_state = init_output;
	asn_hand->count = 0;
    }
    return( asn_hand->ioptr != NULL );
}
static void s_TestIdFormatting(const char* s)
{
    size_t            len = strlen(s);
    CObjectIStreamAsn ois(s, len);
    CSeq_id           cxx_id;
    AsnIoMemPtr       aimp = AsnIoMemOpen
        (const_cast<char*>("r"),
         reinterpret_cast<BytePtr>(const_cast<char*>(s)), len);
    AsnIoPtr          aip = AsnIoNew((ASNIO_IN | ASNIO_TEXT), NULL, aimp,
                                     AsnIoMemRead, AsnIoMemWrite);
    TAutoSeqId        c_id;

    ois.Read(&cxx_id, CSeq_id::GetTypeInfo(), CObjectIStream::eNoFileHeader);
    aip->read_id = TRUE;
    c_id = SeqIdAsnRead(aip, s_SeqIdATP);

    BOOST_CHECK_EQUAL(s_IdLabel(c_id,   eFastaShort),
                      s_IdLabel(cxx_id, eFastaShort));
    BOOST_CHECK_EQUAL(s_IdLabel(c_id,   eTextAccVer),
                      s_IdLabel(cxx_id, eTextAccVer));
    BOOST_CHECK_EQUAL(s_IdLabel(c_id,   eTextAccOnly),
                      s_IdLabel(cxx_id, eTextAccOnly));
    BOOST_CHECK_EQUAL(s_IdLabel(c_id, eReport), s_IdLabel(cxx_id, eReport));
}
示例#7
0
void BEPrintIds(BEDataPtr pBdata, Uint4 *ids, int count)
{
    Int4 i;
    SeqEntryPtr sep, sep_all;
    Boolean retvalue = TRUE;
    SeqIdPtr sip = NULL;
    BioseqPtr bsp;
    BGenBankPtr bgbp;
    AsnIoPtr aip;
    Boolean is_na = FALSE;
    
    if(pBdata->format == F_GILIST) {
        for(i = 0; i < count; i++)
            fprintf(stdout, "%d\n", (int) ids[i]);
        return;
    }
    
    if(pBdata->database == 0)
        is_na = TRUE;

    if(pBdata->format == F_ASN1_GENB)
        bgbp = BGenBankInit();
    
    for(i = 0; i < count; i++) {
        
        sep_all = BESeqEntryGet(ids[i]);
        
        if(sep_all == NULL) {
            ErrPostEx(SEV_ERROR, 88, 67, "Retrieving of blob for the "
                      "gi=%d failed", (int)ids[i]);
            continue;
        }
        
        if(!pBdata->allset) {
            ObjMgrRegister(OBJ_SEQENTRY, sep_all);
            sip = ValNodeNew(NULL);
            sip->choice = SEQID_GI;
            sip->data.intvalue = ids[i];
            
            if((bsp = BioseqFind(sip)) == NULL) {
                ErrPostEx(SEV_ERROR, 88, 67, 
                          "Error finding bioseq for gi=%d\n", (int)ids[i]);
                continue;
            }

            sep = SeqEntryNew();
            sep->choice = 1; /* Bioseq */
            sep->data.ptrvalue = bsp;
        } else {
            sep = sep_all;
        }
        
        switch(pBdata->format) {        
        case F_FASTA:               /* 1 */

            if(!SeqEntryToFasta(sep, stdout, is_na)) {
                if(!SeqEntryToFasta(sep, stdout, !is_na)) {
                    ErrPostEx(SEV_ERROR, 88, 67, "Printing of FASTA format "
                              "(gi=%d) failed\r\n", (int)ids[i]);
                }
            }

            break;
        case F_ASN1:                /* 2 */

            aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);
            SeqEntryAsnWrite(sep, aip, NULL);
            AsnIoClose(aip);

            break;
        case F_GILIST:              /* 3 */
            for(i = 0; i < count; i++)
                fprintf(stdout, "%d\n", (int) ids[i]);
            break;
        case F_DLIST:               /* 4 */
            if (IS_Bioseq(sep))
                retvalue = SeqEntrysToDefline(sep, stdout, is_na, 3);
            else
                retvalue = SeqEntrysToDefline(sep, stdout, is_na, 0);
            
            if(retvalue == FALSE) {
                if (IS_Bioseq(sep))
                    retvalue = SeqEntrysToDefline(sep, stdout, !is_na, 3);
                else
                    retvalue = SeqEntrysToDefline(sep, stdout, !is_na, 0);
            }
            break;
        case F_ASN1_GENB:           /* 5 */
            retvalue = SeqEntryAsnWrite(sep, bgbp->aip, bgbp->atp);
            break;
        default:
        case F_GEN:                 /* 0 */
            if(!SeqEntryToFlatEx(sep_all, stdout, 
                                 is_na ? GENBANK_FMT : GENPEPT_FMT, 
                                 RELEASE_MODE, sip, FF_REGULAR)) {
                
                if(!SeqEntryToFlatEx(sep_all, stdout, 
                                     is_na ? GENPEPT_FMT : GENBANK_FMT, 
                                     RELEASE_MODE, sip, FF_REGULAR)) {
                }
            }
            break;
        }
        
        SeqEntryFree(sep_all);
        ValNodeFree(sip);
    }

    if(pBdata->format == F_ASN1_GENB)
        BGenBankClose(bgbp);
    
    return;
}
示例#8
0
BGenBankPtr BGenBankInit(void)
{
    BGenBankPtr bgbp;
    AsnModulePtr amp;

    AsnTypePtr       atp_bioseq_set;
    AsnTypePtr       atp_bioseq_set_level;
    AsnTypePtr       atp_bioseq_set_class;
    AsnTypePtr       atp_bioseq_set_release;
    AsnTypePtr       atp_bioseq_set_date;
    AsnTypePtr       atp_bioseq_set_seq_set;
    AsnTypePtr       atp_bioseq_set_seq_set_E;

    Char  release[] = "Q-server Production";
    Char  date_time[128];
    NCBI_Date       date;
    DataVal dv;

    DateClean(&date);

    bgbp = (BGenBankPtr)MemNew(sizeof(BGenBank));
    bgbp->aip = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);
    
    amp = AsnAllModPtr();

    MACRO_atp_find(atp_bioseq_set,Bioseq-set);
    MACRO_atp_find(atp_bioseq_set_level,Bioseq-set.level);
    MACRO_atp_find(atp_bioseq_set_class,Bioseq-set.class);
    MACRO_atp_find(atp_bioseq_set_release,Bioseq-set.release);
    MACRO_atp_find(atp_bioseq_set_date,Bioseq-set.date);
    MACRO_atp_find(atp_bioseq_set_seq_set,Bioseq-set.seq-set);
    MACRO_atp_find(atp_bioseq_set_seq_set_E,Bioseq-set.seq-set.E);

    if(!AsnOpenStruct(bgbp->aip,atp_bioseq_set,NULL))     
        return NULL;
    dv.intvalue = 0;

    if(!AsnWrite(bgbp->aip,atp_bioseq_set_level,&dv))     
        return NULL;
    dv.intvalue = 7;

    if(!AsnWrite(bgbp->aip,atp_bioseq_set_class,&dv))     
        return NULL;
    dv.ptrvalue = &release;

    if(!AsnWrite(bgbp->aip,atp_bioseq_set_release,&dv))     
        return NULL;

    Nlm_DayTimeStr(date_time,TRUE,TRUE);
    date.str=date_time;

    if(!DateAsnWrite(&date,bgbp->aip,atp_bioseq_set_date))        
        return NULL;
    
    if(!AsnOpenStruct(bgbp->aip,atp_bioseq_set_seq_set,NULL))     
        return NULL;
    AsnIoFlush(bgbp->aip);
    
    bgbp->atp =atp_bioseq_set_seq_set_E;
    bgbp->atp_bioseq_set_seq_set = atp_bioseq_set_seq_set;
    bgbp->atp_bioseq_set = atp_bioseq_set;
    
    return bgbp;
}
示例#9
0
static NI_HandPtr s_GenericGetService
(NI_DispatcherPtr disp, CharPtr configFile, CharPtr configSection,
 CharPtr defService, Boolean hasResource)
{
  NI_HandPtr result;
  SOCK       sock;
  Char       srv_host[64];
  Uint2      srv_port;
  Uint4      conn_try;

  /* get the server host name */
  NI_GetEnvParam(configFile, configSection, ENV_DEBUG_HOST,
                 srv_host, sizeof(srv_host), "");
  if ( !srv_host[0] ) {
    ErrPostEx(SEV_ERROR, 0, 0, ENV_DEBUG_HOST ": undefined");
    return 0;
  }

  {{ /* get the server port */
    Char str[32];
    int  val;
    NI_GetEnvParam(configFile, configSection, ENV_DEBUG_PORT,
                   str, sizeof(str), "");
    val = atoi(str);
    if (val <= 0) {
      ErrPostEx(SEV_ERROR, 0, 0, ENV_DEBUG_PORT ": bad(%d) or undefined", val);
      return 0;
    }
    srv_port = (Uint2)val;
  }}

  {{ /* alternate the max. number of attemts to establish a connection */
    Char str[32];
    int  val;
    NI_GetEnvParam(configFile, configSection, ENV_DEBUG_TRY,
                   str, sizeof(str), "");
    val = atoi(str);
    conn_try = (Uint4)((val > 0) ? val : DEF_DEBUG_TRY);
  }}

  /* establish connection to the server */
  for (sock = 0;  !sock  &&  conn_try;  conn_try--) {
    if (SOCK_Create(srv_host, srv_port, 0, &sock) != eIO_Success) {
      ErrPostEx(SEV_WARNING, 0, 1,
                "[Debug NI Client]  Cannot connect to host \"%s\", port %d;",
                srv_host, (int)srv_port);
    }
  }
  if ( !sock ) {
    ErrPostEx(SEV_ERROR, 0, 1,
              "[Debug NI Client]  Failed to connect to host \"%s\", port %d;",
              srv_host, (int)srv_port);
    return 0;
  }

  /* open ASN i/o, etc. */
  result = (NI_HandPtr)MemNew(sizeof(NI_Handle));
  result->extra_proc_info = sock;
  result->raip = AsnIoNew((ASNIO_BIN | ASNIO_IN),  (FILE *)0,
                          (void *)sock, s_AsnRead,  (IoFuncType)0);
  result->waip = AsnIoNew((ASNIO_BIN | ASNIO_OUT), (FILE *)0,
                          (void *)sock, (IoFuncType)0, s_AsnWrite);

  AsnIoSetErrorMsg(result->raip, s_AsnErrorFunc);
  AsnIoSetErrorMsg(result->waip, s_AsnErrorFunc);
  result->hostname = StringSave("");
  result->disp = disp;
  disp->referenceCount++;

  return result;
}
示例#10
0
static void ProcessMultipleRecord (
  CharPtr filename,
  CSpeedFlagPtr cfp
)

{
  AsnIoPtr     aip;
  AsnTypePtr   atp;
  BioseqPtr    bsp;
  Char         buf [41];
  Uint2        entityID;
  FILE         *fp;
  SeqEntryPtr  fsep;
  Char         longest [41];
  Int4         numrecords, x;
  SeqEntryPtr  sep;
  time_t       starttime, stoptime, worsttime;
#ifdef OS_UNIX
  Char         cmmd [256];
  CharPtr      gzcatprog;
  int          ret;
  Boolean      usedPopen = FALSE;
#endif

  if (cfp == NULL) return;

  if (StringHasNoText (filename)) return;

#ifndef OS_UNIX
  if (cfp->compressed) {
    Message (MSG_POSTERR, "Can only decompress on-the-fly on UNIX machines");
    return;
  }
#endif

#ifdef OS_UNIX
  if (cfp->compressed) {
    gzcatprog = getenv ("NCBI_UNCOMPRESS_BINARY");
    if (gzcatprog != NULL) {
      sprintf (cmmd, "%s %s", gzcatprog, filename);
    } else {
      ret = system ("gzcat -h >/dev/null 2>&1");
      if (ret == 0) {
        sprintf (cmmd, "gzcat %s", filename);
      } else if (ret == -1) {
        Message (MSG_POSTERR, "Unable to fork or exec gzcat in ScanBioseqSetRelease");
        return;
      } else {
        ret = system ("zcat -h >/dev/null 2>&1");
        if (ret == 0) {
          sprintf (cmmd, "zcat %s", filename);
        } else if (ret == -1) {
          Message (MSG_POSTERR, "Unable to fork or exec zcat in ScanBioseqSetRelease");
          return;
        } else {
          Message (MSG_POSTERR, "Unable to find zcat or gzcat in ScanBioseqSetRelease - please edit your PATH environment variable");
          return;
        }
      }
    }
    fp = popen (cmmd, /* cfp->binary? "rb" : */ "r");
    usedPopen = TRUE;
  } else {
    fp = FileOpen (filename, cfp->binary? "rb" : "r");
  }
#else
  fp = FileOpen (filename, cfp->binary? "rb" : "r");
#endif
  if (fp == NULL) {
    Message (MSG_POSTERR, "FileOpen failed for input file '%s'", filename);
    return;
  }

  aip = AsnIoNew (cfp->binary? ASNIO_BIN_IN : ASNIO_TEXT_IN, fp, NULL, NULL, NULL);
  if (aip == NULL) {
    Message (MSG_ERROR, "AsnIoNew failed for input file '%s'", filename);
    return;
  }

  if (cfp->logfp != NULL) {
    fprintf (cfp->logfp, "%s\n\n", filename);
    fflush (cfp->logfp);
  }

  longest [0] = '\0';
  worsttime = 0;
  numrecords = 0;

  atp = cfp->atp_bss;

  while ((atp = AsnReadId (aip, cfp->amp, atp)) != NULL) {
    if (atp == cfp->atp_se) {

      sep = SeqEntryAsnRead (aip, atp);
      if (sep != NULL) {

        entityID = ObjMgrGetEntityIDForChoice (sep);

        fsep = FindNthBioseq (sep, 1);
        if (fsep != NULL && fsep->choice == 1) {
          bsp = (BioseqPtr) fsep->data.ptrvalue;
          if (bsp != NULL) {
            SeqIdWrite (bsp->id, buf, PRINTID_FASTA_LONG, sizeof (buf));
            if (cfp->logfp != NULL) {
              fprintf (cfp->logfp, "%s\n", buf);
              fflush (cfp->logfp);
            }
          }
        }

        starttime = GetSecs ();

        for (x = 0; x < cfp->maxcount; x++) {
          DoProcess (sep, entityID, cfp);
        }
        stoptime = GetSecs ();

        if (stoptime - starttime > worsttime) {
          worsttime = stoptime - starttime;
          StringCpy (longest, buf);
        }
        numrecords++;

        ObjMgrFreeByEntityID (entityID);
      }

    } else {

      AsnReadVal (aip, atp, NULL);
    }
  }

  AsnIoFree (aip, FALSE);

#ifdef OS_UNIX
  if (usedPopen) {
    pclose (fp);
  } else {
    FileClose (fp);
  }
#else
  FileClose (fp);
#endif
  if (cfp->logfp != NULL && (! StringHasNoText (longest))) {
    fprintf (cfp->logfp, "Longest processing time %ld seconds on %s\n",
             (long) worsttime, longest);
    fprintf (cfp->logfp, "Total number of records %ld\n", (long) numrecords);
    fflush (cfp->logfp);
  }
}
示例#11
0
static void ProcessSingleRecord (
  CharPtr filename,
  CSpeedFlagPtr cfp
)

{
  AsnIoPtr      aip;
  BioseqPtr     bsp;
  ValNodePtr    bsplist = NULL;
  BioseqSetPtr  bssp;
  Pointer       dataptr = NULL;
  Uint2         datatype, entityID = 0;
  FileCache     fc;
  FILE          *fp;
  Int1          iotype;
  Char          line [512];
  Int4          maxio = 1;
  SeqEntryPtr   sep;
  time_t        starttime, stoptime, worsttime;
  CharPtr       str;
  Int4          x;

  if (cfp == NULL) return;

  if (StringHasNoText (filename)) return;

  if (StringChr (cfp->io, 'r') != NULL) {
    maxio = cfp->maxcount;
  }

  starttime = GetSecs ();

  for (x = 0; x < maxio; x++) {
    if (entityID != 0) {
      ObjMgrFreeByEntityID (entityID);
      entityID = 0;
      dataptr = NULL;
    }

    if (cfp->type == 1) {

      fp = FileOpen (filename, "r");
      if (fp == NULL) {
        Message (MSG_POSTERR, "Failed to open '%s'", filename);
        return;
      }

      dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, FALSE, FALSE, FALSE, FALSE);

      FileClose (fp);

      entityID = ObjMgrRegister (datatype, dataptr);

    } else if (cfp->type >= 2 && cfp->type <= 5) {

      aip = AsnIoOpen (filename, cfp->binary? "rb" : "r");
      if (aip == NULL) {
        Message (MSG_POSTERR, "AsnIoOpen failed for input file '%s'", filename);
        return;
      }

      switch (cfp->type) {
        case 2 :
          dataptr = (Pointer) SeqEntryAsnRead (aip, NULL);
          datatype = OBJ_SEQENTRY;
          break;
        case 3 :
          dataptr = (Pointer) BioseqAsnRead (aip, NULL);
          datatype = OBJ_BIOSEQ;
          break;
        case 4 :
          dataptr = (Pointer) BioseqSetAsnRead (aip, NULL);
          datatype = OBJ_BIOSEQSET;
          break;
        case 5 :
          dataptr = (Pointer) SeqSubmitAsnRead (aip, NULL);
          datatype = OBJ_SEQSUB;
          break;
        default :
          break;
      }

      AsnIoClose (aip);

      entityID = ObjMgrRegister (datatype, dataptr);

    } else if (cfp->type == 6) {

      fp = FileOpen (filename, "r");
      if (fp == NULL) {
        Message (MSG_POSTERR, "Failed to open '%s'", filename);
        return;
      }

      dataptr = ReadAsnFastaOrFlatFile (fp, &datatype, NULL, FALSE, FALSE, FALSE, FALSE);

      FileClose (fp);

      entityID = ObjMgrRegister (datatype, dataptr);

    } else if (cfp->type == 7) {

      fp = FileOpen (filename, "r");
      if (fp == NULL) {
        Message (MSG_POSTERR, "Failed to open '%s'", filename);
        return;
      }

      FileCacheSetup (&fc, fp);

      str = FileCacheReadLine (&fc, line, sizeof (line), NULL);
      while (str != NULL) {
        str = FileCacheReadLine (&fc, line, sizeof (line), NULL);
      }

      FileClose (fp);

      return;

    } else {
      Message (MSG_POSTERR, "Input format type '%d' unrecognized", (int) cfp->type);
      return;
    }
  }

  if (entityID < 1 || dataptr == NULL) {
    Message (MSG_POSTERR, "Data read failed for input file '%s'", filename);
    return;
  }

  if (datatype == OBJ_SEQSUB || datatype == OBJ_SEQENTRY ||
        datatype == OBJ_BIOSEQ || datatype == OBJ_BIOSEQSET) {

    stoptime = GetSecs ();
    worsttime = stoptime - starttime;
    if (cfp->logfp != NULL) {
      fprintf (cfp->logfp, "ASN reading time %ld seconds\n", (long) worsttime);
      fflush (cfp->logfp);
    }

    sep = GetTopSeqEntryForEntityID (entityID);

    if (sep == NULL) {
      sep = SeqEntryNew ();
      if (sep != NULL) {
        if (datatype == OBJ_BIOSEQ) {
          bsp = (BioseqPtr) dataptr;
          sep->choice = 1;
          sep->data.ptrvalue = bsp;
          SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) bsp, sep);
        } else if (datatype == OBJ_BIOSEQSET) {
          bssp = (BioseqSetPtr) dataptr;
          sep->choice = 2;
          sep->data.ptrvalue = bssp;
          SeqMgrSeqEntry (SM_BIOSEQSET, (Pointer) bssp, sep);
        } else {
          sep = SeqEntryFree (sep);
        }
      }
      sep = GetTopSeqEntryForEntityID (entityID);
    }

    if (sep != NULL) {

      if (cfp->lock) {
        starttime = GetSecs ();

        bsplist = LockFarComponents (sep);

        stoptime = GetSecs ();
        worsttime = stoptime - starttime;
        if (cfp->logfp != NULL) {
          fprintf (cfp->logfp, "Far component locking time %ld seconds\n", (long) worsttime);
          fflush (cfp->logfp);
        }
      }

      if (StringChr (cfp->io, 'w') != NULL) {
        starttime = GetSecs ();

        iotype = ASNIO_TEXT_OUT;
        if (StringChr (cfp->io, 'b') != NULL) {
          iotype = ASNIO_BIN_OUT;
        }

        for (x = 0; x < cfp->maxcount; x++) {
          aip = AsnIoNew (iotype, cfp->ofp, NULL, NULL, NULL);
          if (aip != NULL) {
            SeqEntryAsnWrite (sep, aip, NULL);
            AsnIoFree (aip, FALSE);
          }
        }

        stoptime = GetSecs ();
        worsttime = stoptime - starttime;
        if (cfp->logfp != NULL) {
          fprintf (cfp->logfp, "ASN writing time %ld seconds\n", (long) worsttime);
          fflush (cfp->logfp);
        }
      }

      starttime = GetSecs ();

      for (x = 0; x < cfp->maxcount; x++) {
        DoProcess (sep, entityID, cfp);
      }

      stoptime = GetSecs ();
      worsttime = stoptime - starttime;
      if (cfp->logfp != NULL) {
        fprintf (cfp->logfp, "Internal processing time %ld seconds\n", (long) worsttime);
        fflush (cfp->logfp);
      }

      ObjMgrFreeByEntityID (entityID);

      bsplist = UnlockFarComponents (bsplist);
    }

  } else {

    Message (MSG_POSTERR, "Datatype %d not recognized", (int) datatype);
  }
}
示例#12
0
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;
}
示例#13
0
Boolean LIBCALL VastToCn3D(WWWInfoPtr www_info)
{
	FILE *pFile = NULL;
	FILE *pIn = NULL;
	Char pcBuf[100], pcLine[256], giBuf[20], URL[200];
	CharPtr pcTest, pcL1 = NULL, Name, www_arg;
	Int4 GetGi, Fid, Fsid, iFileExists = 0, indx;
	BiostrucAnnotSetPtr pbsa = NULL; 
	BiostrucAnnotSetPtr pbsaShort = NULL;
        BiostrucFeatureSetPtr pbsfs = NULL;
        BiostrucFeaturePtr pbsf = NULL;
        BiostrucResidueGraphSetPtr stdDictionary;
        ValNodePtr pvnFids = NULL, pvnFid = NULL;
        Int2 iTest = 0, iPDB = 0, iColor;
	AsnIoPtr aip = NULL; 
	Byte bRender;
	Char *IPAddress = getenv("REMOTE_HOST");
        Int4 NumLabels, iMMDBId;
	ValNode * pbsidThis;
	BiostrucPtr pbsMaster, pbsSlave, pbsSlaveHead = NULL, pbsSlaveTail, pbsTemp;
	Char szName[5], chain[2];
	Char * szTemp;
  SeqAnnotPtr psaAlignHead = NULL, psaAlignTail;
  SeqAlignPtr salpHead, salpTail;
  SeqIdPtr      sip;   
  DenseSegPtr   dsp; 
  BioseqPtr bsp;
  SeqEntryPtr sep;
    char  str [52];
    NcbiMimeAsn1Ptr pvnNcbi;
    BiostrucAlignPtr pbsaStruct;
    AsnIoPtr paiFile, aipr;
    Boolean is_network;
    Int4 uid, uidmaster = 0;
 Int2 retcode = 3;
 CharPtr JobID = NULL, pcPass;
 Char AsnPath[PATH_MAX];
 Char AsnName[10];
 Int2 ret, complexity;
 Int4 iFidCount = 0;
 Boolean Chain;

 /*    SeqAsnLoad();
    
    
    objmmdb1AsnLoad();
    objmmdb2AsnLoad();
    objmmdb3AsnLoad();
    SeqAlignAsnLoad();
    objmimeAsnLoad();
    */


	if ((indx = WWWFindName(www_info, "uid")) < 0) {
		printf("Content-type: text/html\n\n");
		printf("<h3>No accession (PDB ID) was input - nothing to report.</h3>\n"); 
		return 0;
	}

	www_arg =  WWWGetValueByIndex(www_info, indx);

	if (isdigit(www_arg[0]))
		GetGi = (Int4) atoi(www_arg);
	else {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		printf("<h3>Non-numeric MMDB-id input - no results.</h3>\n"); 
		return 0;
	}

	/* vsid and pass are to look at alignments from VAST Search */
	if ((indx = WWWFindName(www_info, "vsid")) >= 0) {
		www_arg = WWWGetValueByIndex(www_info, indx);
		JobID = StringSave(www_arg);

		if ((indx = WWWFindName(www_info, "pass")) < 0) {
			printf("Content-type: text/html\n\n");
			printf("<body bgcolor = \"#f0f0f0\">\n");
			printf("<h2>VAST SEARCH</h2>\n");
			printf("<h3>Password required.</h3>\n");
			return 0;
		}
		else {
			www_arg = WWWGetValueByIndex(www_info, indx);
			pcPass = StringSave(www_arg);

			if ((ret = Check_VastSearch_Password(pcPass, JobID)) != 1) {
				if (ret == 2) return 0;
				printf("Content-type: text/html\n\n");
				printf("<body bgcolor = \"#f0f0f0\">\n");
				printf("<h2>VAST SEARCH</h2>\n");
				printf("<h3>Incorrect password.</h3>\n"); 
				return 0;
			}
		}
	}

	if ((indx = WWWFindName(www_info, "hit")) < 0) {
		printf("Content-type: text/html\n\n");
		printf("<body bgcolor = \"#f0f0f0\">\n");
		printf("<br>\n<h2>No alignment was selected!</h2>\n");
		printf("<h3>Please click on up to 5 boxes in the leftmost column of the table.</h3>\n"); 
		return 0;
	}
        
	/* loop over all the "hit" values in the list */
	NumLabels = WWWGetNumEntries(www_info);

	for (indx = 0; indx < NumLabels; indx++) {
		Name = WWWGetNameByIndex(www_info, indx);

		if (StrICmp(Name, "hit") == 0) {
			www_arg = WWWGetValueByIndex(www_info, indx);

			if (isdigit(www_arg[0]))
				Fid = (Int4) atol(www_arg);
			else {
				printf("Content-type: text/html\n\n");
				printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
				printf("<h3>Non-numeric slave alignment code - no results.</h3>\n");
				return 0;
			}

			if (++iFidCount > 5) break;
			pvnFid = ValNodeAddInt(&pvnFids, 0, Fid);
		}
 	}

	if ((indx = WWWFindName(www_info, "chaindom")) < 0) {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		printf("<h3>No feature set ID (master alignment code) - nothing to report.</h3>\n");
		return 0;
	}

	www_arg = WWWGetValueByIndex(www_info, indx);

	if (isdigit(www_arg[0]))
		Fsid = (Int4) atoi(www_arg);
	else {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		printf("<h3>Non-numeric master alignment code - no results.</h3>\n");
		return 0;
	}
        
        if ((indx = WWWFindName(www_info, "chn_complexity")) < 0)
            Chain = TRUE;
        else
        {
          www_arg = WWWGetValueByIndex(www_info, indx);
          complexity =(Int2)atoi(www_arg);

          if (complexity) Chain = TRUE;
          else Chain = FALSE;
        }
  
	if ((indx = WWWFindName(www_info, "atm_complexity")) < 0)
		/* select alpha Carbons only by default */
		complexity = ONECOORDRES;
	else {
		www_arg = WWWGetValueByIndex(www_info, indx);

		if (isdigit(www_arg[0]))
			complexity = (Int2) atoi(www_arg);
		else
			complexity = ONECOORDRES;
	}

	if ((complexity != ONECOORDRES) && (complexity != ONECOORDATOM))
		/* bizarre value, but default to alpha-Carbons only */
		complexity = ONECOORDRES;

	/* action == 0 indicates MIME; action == 1 is text; action == 2 is save */
	if ((indx = WWWFindName(www_info, "action")) < 0)
		iPDB = 0;
	else {
		www_arg = WWWGetValueByIndex(www_info, indx);

		if (isdigit(www_arg[0]))
			iPDB = (Int4) atoi(www_arg);
		else
			iPDB = 0;
	}

	if (VASTInit() != TRUE) {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		printf("<h3>Can't find VAST data on server.\n");
		printf("Contact [email protected]</h3>\n"); 
		return 0;
	}

	OpenMMDBAPI((POWER_VIEW /* ^ FETCH_ENTREZ */), NULL);
	pbsa = LocalGetFeatureSet(GetGi, Fsid, JobID);
	
        if (pbsa == NULL) {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		printf("<h3>No master alignment record exists for %ld.</h3>\n", (long) GetGi);
		return 0; 
	}
        
	if (iFidCount == 1)
          pbsaShort = BiostrucAnnotSetGetByFid(pbsa, Fid, Fsid);
        else
          pbsaShort = PruneBiostrucAnnotHits(pbsa, Fsid, pvnFids);
	
        if (pbsaShort == NULL) {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		printf("<h3>Can't find alignment record.</h3>\n");
		return 0; 
	}
  
	if (MMDBInit() == FALSE) {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		printf("<h3>MMDBInit failed.</h3>\n");
		return 0;
	}

        pbsfs = pbsaShort->features;
        
        pbsaStruct = BiostrucAlignNew();
         
        if (pbsfs)
        {
          pbsf = pbsfs->features;
          szTemp = pbsf->name;
	  szName[0] = szTemp[0];
	  szName[1] = szTemp[1];
	  szName[2] = szTemp[2];
	  szName[3] = szTemp[3];
	  szName[4] = '\0';
        }
        
        if (JobID == NULL)
        pbsMaster = FetchBiostrucPDB(szName, complexity, 1);
        else
        {
          AsnName[0]='\0';
          StringCpy(AsnName, "/b");
          StringCat(AsnName, szName);
	
          AsnPath[0]='\0';
          StringCpy(AsnPath, VSPATH);
          StringCat(AsnPath, JobID);
          StringCat(AsnPath, AsnName);
   
          pbsMaster = FetchBS(AsnPath, 0, complexity, 1, POWER_VIEW);
        }

        if (pbsMaster == NULL)
        {
	  printf("Content-type: text/html\n\n");
	  printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
	  printf("<h3> Unable to load master structure.</h3>\n");
	  return 0;
	}
       
        /* Load in Standard Dictionary to make sequences - Ken */
        aipr = NULL;
        aipr = AsnIoOpen("bstdt", "rb");
        
        if (aipr == NULL) 
        {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		printf("<h3>Can't find standard dictionary.</h3>\n");
		return 0; 
	}
        
        stdDictionary = BiostrucResidueGraphSetAsnRead(aipr, NULL);
        AsnIoFlush(aipr);
        aipr = AsnIoClose(aipr);
       
       /* retrieve the bioseq for master and put in ValNode */
       sep = (SeqEntryPtr) MakeBioseqs(pbsMaster, stdDictionary);
       if ( sep == NULL ) 
       {
         printf("Content-type: text/html\n\n");
         printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n");
         printf("<h3>Unable to get SeqEntry.</h3>\n");
         return 0;
       } 
       ValNodeLink(&(pbsaStruct->sequences), sep);
       /* PruneBiostruc if Aligned Chain Options has been chosen */
       if (Chain)
       {
         if (szTemp[4] != ' ')
         {
           chain[0] = szTemp[4];
           chain[1] = '\0';
           pbsTemp = (BiostrucPtr)PruneBiostruc(pbsMaster, chain);
           pbsMaster = NULL;
           pbsMaster = pbsTemp;
         }
       }
    
        /* Make a linked list of Biostrucs of the slave structures*/   
         while (pbsf)
         {
            szTemp = pbsf->name;
            szName[0] = szTemp[7];
	    szName[1] = szTemp[8];
	    szName[2] = szTemp[9];
	    szName[3] = szTemp[10];
	    szName[4] = '\0';

	    if (!pbsSlaveHead) 
            {
                pbsSlaveHead =  FetchBiostrucPDB(szName, complexity, 1); 
		if (!pbsSlaveHead)
                {
                  printf("Content-type: text/html\n\n");
		  printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		  printf("<h3> Unable to load slave structure.</h3>\n");
		  return 0;
                }
                /* Make Bioseq for Slaves */
                sep = (SeqEntryPtr) MakeBioseqs(pbsSlaveHead, stdDictionary);
                if ( sep == NULL ) 
                {
		  printf("Content-type: text/html\n\n");
		  printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n");
		  printf("<h3>Unable to get SeqEntry.</h3>\n");
		  return 0;
	        } 
                ValNodeLink(&(pbsaStruct->sequences), sep);
                /* PruneBiostruc if Aligned Chain Options has been chosen */
                if (Chain)
                {
                  if (szTemp[11] != ' ')
                  {
                    chain[0] = szTemp[11];
                    chain[1] = '\0';
                    pbsTemp = (BiostrucPtr)PruneBiostruc(pbsSlaveHead, chain);
                    pbsSlaveHead = NULL;
                    pbsSlaveHead = pbsTemp;
                  }
                }   
                pbsSlaveTail = pbsSlaveHead;
	    }
            else
            { 
		pbsSlave = FetchBiostrucPDB(szName, complexity, 1);
		if (!pbsSlave) 
                {
                  printf("Content-type: text/html\n\n");
		  printf("<h2>VASTSERV Error (VastToCn3D)</h2>\n");
		  printf("<h3> Unable to load slave structure.</h3>\n");
		  return 0;
                }
		/* Make Bioseq for Slaves */
                sep = (SeqEntryPtr) MakeBioseqs(pbsSlave, stdDictionary);
                if ( sep == NULL ) 
                {
		  printf("Content-type: text/html\n\n");
		  printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n");
		  printf("<h3>Unable to get SeqEntry.</h3>\n");
		  return 0;
	        } 
                ValNodeLink(&(pbsaStruct->sequences), sep);
                /* PruneBiostruc if Aligned Chain Options has been chosen */
                if (Chain)
                {
                  if (szTemp[11] != ' ')
                  {
                    chain[0] = szTemp[11];
                    chain[1] = '\0';
                    pbsTemp = (BiostrucPtr)PruneBiostruc(pbsSlave, chain);
                    pbsSlave = NULL;
                    pbsSlave = pbsTemp;
                  }
                }
                pbsSlaveTail->next = pbsSlave;
                pbsSlaveTail = pbsSlaveTail->next;
                pbsSlaveTail->next = NULL;
            }
          
            pbsf = pbsf->next;
         }
        /* Make a linked list of sequence alignments of master and slaves */
        pbsf=pbsfs->features;
        while (pbsf) {
          if (!psaAlignHead) {
            psaAlignHead = fnPBSFtoPSA (pbsf);  /* get the sequence alignments */
            if (psaAlignHead == NULL || psaAlignHead->data == NULL) {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n");
		printf("<h3>Unable to create SeqAnnot.</h3>\n");
		return 0;
	    }
            salpHead = (SeqAlignPtr)(psaAlignHead->data);
            salpTail = salpHead;
          }
          else {
             psaAlignTail = fnPBSFtoPSA (pbsf);
             salpTail->next = (SeqAlignPtr)(psaAlignTail->data);
             if (psaAlignTail == NULL || psaAlignTail->data == NULL) {
		printf("Content-type: text/html\n\n");
		printf("<h2>VASTSERV Error (VastToCn3d)</h2>\n");
		printf("<h3>Unable to create SeqAnnot.</h3>\n");
		return 0;
	     }
             salpTail = salpTail->next;
             salpTail->next = NULL;
          }
          pbsf = pbsf->next;
        }
        
  pbsaStruct->master = pbsMaster;
  pbsaStruct->slaves = pbsSlaveHead;
  pbsaStruct->alignments = pbsaShort;
  pbsaStruct->seqalign = psaAlignHead;

  pvnNcbi = ValNodeNew(NULL);
  pvnNcbi->choice =  NcbiMimeAsn1_alignstruc;
  pvnNcbi->data.ptrvalue = pbsaStruct;
  pvnNcbi = (NcbiMimeAsn1Ptr) CheckId(pvnNcbi, JobID);      /* to check identity, yanli  */

  OutputFile = stdout;

  if (iPDB == 0)		/* cn3d MIME */
    printf ("Content-type: chemical/ncbi-asn1-binary\n\n");

  else if (iPDB == 1) {		/* "See File" */
    printf ("Content-type: text/html\n\n");
    printf ("<HTML><body><pre>\n");
  }

  else				/* "Save File" */
    printf ("Content-type: application/octet-stream\n\n");

  if (iPDB != 1)
    paiFile = AsnIoNew(ASNIO_BIN_OUT, stdout, NULL, NULL, NULL);

  else
    paiFile = AsnIoNew(ASNIO_TEXT_OUT, stdout, NULL, NULL, NULL);

  NcbiMimeAsn1AsnWrite(pvnNcbi, paiFile, NULL);
  AsnIoFlush(paiFile);
  AsnIoClose(paiFile);

  CloseMMDBAPI();
  MMDBFini();
  VASTFini();
  return 0;

} /* end of VastToCn3D */
示例#14
0
AsnMemoryWrite::AsnMemoryWrite(Uint2 mode)
    : m_Data(new char[512]), m_Size(512), m_Ptr(0)
{
    m_Out = AsnIoNew(mode | ASNIO_OUT, 0, this,
		     0, reinterpret_cast<IoFuncType>(WriteAsn));
}
示例#15
0
void AsnMemoryRead::Init(void)
{
    m_Ptr = 0;
    m_In = AsnIoNew(m_mode | ASNIO_IN, 0, this,
		    reinterpret_cast<IoFuncType>(ReadAsn), 0);
}