Esempio n. 1
0
static void PromoteToSeqEntry (Uint2 entityID, Uint2 datatype, Pointer dataptr)

{
    BioseqPtr     bsp;
    BioseqSetPtr  bssp;
    SeqEntryPtr   sep;

    sep = GetTopSeqEntryForEntityID (entityID);
    if (sep != NULL) return;
    sep = SeqEntryNew ();
    if (sep == NULL) return;
    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);
    }
}
Esempio n. 2
0
extern void ExportSeqAnnotFeatureTable (FILE *fp, SeqAnnotPtr sap) 
{
  FeatureTableData ftd;
  BioseqPtr fake_bsp;
  SeqFeatPtr first_feat;
  SeqEntryPtr sep;
  
  if (fp == NULL || sap == NULL) return;

  /* create fake bioseq to hold annotation */
  fake_bsp = BioseqNew();
  fake_bsp->annot = sap;
  
  /* create SeqEntry for temporary bioseq to live in */
  sep = SeqEntryNew ();
  sep->choice = 1;
  sep->data.ptrvalue = fake_bsp;
  SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) fake_bsp, sep);  

  ftd.export_only_selected = FALSE;
  ftd.fp = fp;
  ftd.show_nucs = TRUE;
  ftd.show_prots = TRUE;
  ftd.suppress_protein_ids = FALSE;

  /* show sources if there are any */
  first_feat = (SeqFeatPtr) sap->data;
  while (first_feat != NULL && first_feat->data.choice != SEQFEAT_BIOSRC) {
    first_feat = first_feat->next;
  }
  if (first_feat != NULL) {
    ftd.hide_sources = FALSE;
  } else {
    ftd.hide_sources = TRUE;
  }
      
  first_feat = (SeqFeatPtr) sap->data;
  fake_bsp->id = SeqIdDup (SeqLocId (first_feat->location));
  if (first_feat->data.choice == SEQFEAT_PROT) {
    fake_bsp->mol = Seq_mol_aa;
  } else {
    fake_bsp->mol = Seq_mol_dna;
  }
  fake_bsp->repr = Seq_repr_raw;
  fake_bsp->length = FindNecessaryBioseqLength (first_feat);
  
  VisitBioseqsInSep (sep, &ftd, VSMExportFeatureTableBioseqCallback);

  fake_bsp->annot = NULL;
  fake_bsp->idx.deleteme = TRUE;
  DeleteMarkedObjects (fake_bsp->idx.entityID, 0, NULL);
 
}
Esempio n. 3
0
static Int2 
VSMExportFeatureTable 
(OMProcControlPtr ompcp, 
 Boolean show_nucs, 
 Boolean show_prots,
 Boolean hide_sources,
 Boolean suppress_protein_ids,
 Boolean export_only_selected)

{
    Char filename[255];
    ValNode vn;
    SeqEntryPtr sep = NULL;
    FeatureTableData ftd;
    SeqAnnotPtr sap = NULL;
    BioseqPtr fake_bsp = NULL;
    SeqFeatPtr first_feat = NULL;
    
    switch(ompcp->input_itemtype)
    {
        case OBJ_SEQENTRY:
        case OBJ_BIOSEQ:
        case OBJ_BIOSEQSET:
      case OBJ_SEQFEAT:
            break;
        case OBJ_SEQANNOT:
            sap = (SeqAnnotPtr) ompcp->input_data;
            if (sap== NULL) {
              ErrPostEx(SEV_ERROR, 0,0,"ToFasta: Can't write NULL Seq-annot");
              return OM_MSG_RET_ERROR;
            } else if (sap->type != 1) {
                ErrPostEx(SEV_ERROR, 0,0,"ToFasta: Can only write Feature Table Seq-annot");
              return OM_MSG_RET_ERROR;
            } else if (sap->data == NULL) {
                ErrPostEx(SEV_ERROR, 0,0,"ToFasta: Can't write empty Feature Table Seq-annot");
              return OM_MSG_RET_ERROR;
            }
            break;
        default:
            ErrPostEx(SEV_ERROR, 0,0,"ToFasta: Can only write Seq-entry, Feature Table Seq-annot, Bioseq, or Bioseq-set");
            return OM_MSG_RET_ERROR;
    }
    
    ftd.show_nucs = show_nucs;
    ftd.show_prots = show_prots;
    ftd.hide_sources = hide_sources;
    ftd.suppress_protein_ids = suppress_protein_ids;
    ftd.export_only_selected = export_only_selected;
    
  if (ompcp->input_itemtype == OBJ_SEQFEAT)
  {
    sep = GetTopSeqEntryForEntityID (ompcp->input_entityID);
  }
  else if (ompcp->input_choicetype == OBJ_SEQENTRY)
  {
        sep = (SeqEntryPtr)(ompcp->input_choice);
  }
  else if (ompcp->input_itemtype == OBJ_SEQANNOT) {
    sep = GetTopSeqEntryForEntityID (ompcp->input_entityID);
    if (sep == NULL) {
      if (sap != NULL) {
        fake_bsp = BioseqNew();
        first_feat = (SeqFeatPtr) sap->data;
        fake_bsp->id = SeqIdDup (SeqLocId (first_feat->location));
        fake_bsp->annot = sap;
        if (first_feat->data.choice == SEQFEAT_PROT) {
          fake_bsp->mol = Seq_mol_aa;
        } else {
          fake_bsp->mol = Seq_mol_dna;
        }
        fake_bsp->repr = Seq_repr_raw;
        fake_bsp->length = FindNecessaryBioseqLength (first_feat);

        /* create SeqEntry for temporary bioseq to live in */
        sep = SeqEntryNew ();
        sep->choice = 1;
        sep->data.ptrvalue = fake_bsp;
        SeqMgrSeqEntry (SM_BIOSEQ, (Pointer) fake_bsp, sep);
      }
    }
  }
    else
    {
        vn.next = NULL;
        vn.data.ptrvalue = ompcp->input_data;
        if (ompcp->input_itemtype == OBJ_BIOSEQ)
            vn.choice = 1;
        else
            vn.choice = 2;
        sep = &vn;
    }
        
    filename[0] = '\0';
    if (GetOutputFileName(filename, (size_t)254, NULL))
    {
        WatchCursor();
#ifdef WIN_MAC
        ftd.fp = FileOpen (filename, "r");
        if (ftd.fp != NULL) {
            FileClose (ftd.fp);
        } else {
            FileCreate (filename, "TEXT", "ttxt");
        }
#endif
        ftd.fp = FileOpen(filename, "w");
        VisitBioseqsInSep (sep, &ftd, VSMExportFeatureTableBioseqCallback);
        FileClose(ftd.fp);
        ArrowCursor();
    }
    
    if (fake_bsp != NULL) {
      fake_bsp->annot = NULL;
      fake_bsp->idx.deleteme = TRUE;
      DeleteMarkedObjects (fake_bsp->idx.entityID, 0, NULL);
    }
    
    return OM_MSG_RET_DONE;  
}
Esempio n. 4
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);
  }
}