Beispiel #1
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);
 
}
Beispiel #2
0
Int2 Main (void)

{
  AsnIoPtr     aip;
  Boolean      convertgis;
  Boolean      extractmrnas;
  CharPtr      infile, outfile;
  SeqEntryPtr  sep;

  /* standard setup */

  ErrSetFatalLevel (SEV_MAX);
  ErrClearOptFlags (EO_SHOW_USERSTR);
  UseLocalAsnloadDataAndErrMsg ();
  ErrPathReset ();

  /* finish resolving internal connections in ASN.1 parse tables */

  if (! AllObjLoad ()) {
    Message (MSG_FATAL, "AllObjLoad failed");
    return 1;
  }
  if (! SubmitAsnLoad ()) {
    Message (MSG_FATAL, "SubmitAsnLoad failed");
    return 1;
  }
  if (! FeatDefSetLoad ()) {
    Message (MSG_FATAL, "FeatDefSetLoad failed");
    return 1;
  }
  if (! SeqCodeSetLoad ()) {
    Message (MSG_FATAL, "SeqCodeSetLoad failed");
    return 1;
  }
  if (! GeneticCodeTableLoad ()) {
    Message (MSG_FATAL, "GeneticCodeTableLoad failed");
    return 1;
  }

  /* process command line arguments */

  if (! GetArgs ("gi2accn", sizeof (myargs) / sizeof (Args), myargs)) {
    return 0;
  }

  infile = (CharPtr) myargs [i_argInputFile].strvalue;
  outfile = (CharPtr) myargs [o_argOutputFile].strvalue;
  convertgis = (Boolean) myargs [c_argConvertGIs].intvalue;
  extractmrnas = (Boolean) myargs [x_argExtractMrnas].intvalue;

  aip = AsnIoOpen (infile, "r");
  if (aip == NULL) {
    Message (MSG_FATAL, "AsnIoOpen input file failed");
    return 1;
  }

  sep = SeqEntryAsnRead (aip, NULL);
  AsnIoClose (aip);
  if (sep == NULL) {
    Message (MSG_FATAL, "SeqEntryAsnRead failed");
    return 1;
  }

  PubSeqFetchEnable ();

  LookupFarSeqIDs (sep, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE);

  /* Extract mRNA hits from BLAST against nr */

  if (extractmrnas) {
    VisitAnnotsInSep (sep, NULL, FindBlastNR);
    DeleteMarkedObjects (0, OBJ_SEQENTRY, (Pointer) sep);
  }

  /* convert gi numbers to accession.version */

  if (convertgis) {
    VisitAlignmentsInSep (sep, NULL, UpdateAligns);
  }

  PubSeqFetchDisable ();

  BasicSeqEntryCleanup (sep);

  aip = AsnIoOpen (outfile, "w");
  if (aip == NULL) {
    Message (MSG_FATAL, "AsnIoOpen output file failed");
    return 1;
  }

  SeqEntryAsnWrite (sep, aip, NULL);
  AsnIoClose (aip);

  return 0;
}
Beispiel #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;  
}
Beispiel #4
0
static void DoProcess (
  SeqEntryPtr sep,
  Uint2 entityID,
  CSpeedFlagPtr cfp
)

{
  Char            id [64];
  ErrSev          oldErrSev;
  ValidStructPtr  vsp;

  if (sep == NULL || cfp == NULL) return;

  if (StringChr (cfp->clean, 't') != NULL) {
    VisitDescriptorsInSep (sep, NULL, MarkTitles);
    DeleteMarkedObjects (entityID, 0, NULL);
  }
  if (StringChr (cfp->clean, 'a') != NULL) {
    AssignIDsInEntity (entityID, 0, NULL);
  }
  if (StringChr (cfp->clean, 'b') != NULL) {
    BasicSeqEntryCleanup (sep);
  }
  if (StringChr (cfp->clean, 's') != NULL) {
    SeriousSeqEntryCleanup (sep, NULL, NULL);
  }

  if (StringChr (cfp->index, 'f') != NULL) {
    SeqMgrIndexFeatures (entityID, 0);
  }

  if (StringChr (cfp->seq, 'c') != NULL) {
    VisitBioseqsInSep (sep, (Pointer) cfp, DoFastaExist);
  }
  if (StringChr (cfp->seq, 'C') != NULL) {
    VisitBioseqsInSep (sep, (Pointer) cfp, DoFastaRegen);
  }
  if (StringChr (cfp->seq, 's') != NULL) {
    VisitBioseqsInSep (sep, (Pointer) cfp, DoFastaSeq);
  }
  if (StringChr (cfp->seq, 'S') != NULL) {
    if (SeqMgrFeaturesAreIndexed (entityID) == 0) {
      SeqMgrIndexFeatures (entityID, 0);
    }
    VisitBioseqsInSep (sep, (Pointer) cfp, DoFastaSeq);
  }
  if (StringChr (cfp->seq, 'r') != NULL) {
    VisitBioseqsInSep (sep, (Pointer) cfp, DoFastaRaw);
  }
  if (StringChr (cfp->seq, 'd') != NULL) {
    VisitBioseqsInSep (sep, (Pointer) cfp, DoFastaDefline);
  }
  if (StringChr (cfp->seq, 'D') != NULL) {
    if (SeqMgrFeaturesAreIndexed (entityID) == 0) {
      SeqMgrIndexFeatures (entityID, 0);
    }
    VisitBioseqsInSep (sep, (Pointer) cfp, DoFastaDefline);
  }
  if (StringChr (cfp->seq, 'T') != NULL) {
    VisitDescriptorsInSep (sep, NULL, MarkTitles);
    DeleteMarkedObjects (entityID, 0, NULL);
    SeqMgrIndexFeatures (entityID, 0);
    VisitBioseqsInSep (sep, (Pointer) cfp, DoFastaDefline);
  }
  if (StringChr (cfp->seq, 'x') != NULL) {
    VisitBioseqsInSep (sep, (Pointer) cfp, DoNewFastaDefline);
  }
  if (StringChr (cfp->seq, 'X') != NULL) {
    VisitDescriptorsInSep (sep, NULL, MarkTitles);
    DeleteMarkedObjects (entityID, 0, NULL);
    SeqMgrIndexFeatures (entityID, 0);
    VisitBioseqsInSep (sep, (Pointer) cfp, DoNewFastaDefline);
  }
  
  if (StringChr (cfp->seq, 'f') != NULL) {
    VisitFeaturesInSep (sep, (Pointer) cfp, DoFastaFeat);
  }
  if (StringChr (cfp->seq, 't') != NULL) {
    VisitFeaturesInSep (sep, (Pointer) cfp, DoFastaTrans);
  }

  if (StringChr (cfp->feat, 'v') != NULL) {
    VisitFeaturesInSep (sep, NULL, DoVisitFeaturesTest);
  }
  if (StringChr (cfp->feat, 'g') != NULL) {
    if (SeqMgrFeaturesAreIndexed (entityID) == 0) {
      SeqMgrIndexFeatures (entityID, 0);
    }
    VisitFeaturesInSep (sep, (Pointer) cfp, DoGeneOverlapPrintTest);
  }
  if (StringChr (cfp->feat, 'h') != NULL) {
    if (SeqMgrFeaturesAreIndexed (entityID) == 0) {
      SeqMgrIndexFeatures (entityID, 0);
    }
    VisitFeaturesInSep (sep, (Pointer) cfp, DoGeneOverlapSpeedTest);
  }
  if (StringChr (cfp->feat, 'x') != NULL) {
  }
  if (StringChr (cfp->feat, 'o') != NULL) {
  }
  if (StringChr (cfp->feat, 'd') != NULL) {
  }
  if (StringChr (cfp->feat, 't') != NULL) {
    SeqEntryToGnbk (sep, NULL, FTABLE_FMT, SEQUIN_MODE, NORMAL_STYLE,
                    0, 0, SHOW_PROT_FTABLE, NULL, cfp->ofp);
  }
  if (StringChr (cfp->feat, 's') != NULL) {
    if (SeqMgrFeaturesAreIndexed (entityID) == 0) {
      SeqMgrIndexFeatures (entityID, 0);
    }
    cfp->nucbsp = FindNucBioseq (sep);
    if (cfp->nucbsp != NULL) {
      BioseqToGeneticCode (cfp->nucbsp, &(cfp->genCode), NULL, NULL, NULL, 0, NULL);
      SeqIdWrite (cfp->nucbsp->id, id, PRINTID_FASTA_LONG, sizeof (id) - 1);
      fprintf (cfp->ofp, "%s\n", id);
      VisitBioseqsInSep (sep, (Pointer) cfp, DoSuggestIntervals);
      cfp->nucbsp = NULL;
      cfp->genCode = 0;
    }
  }
  if (StringChr (cfp->feat, 'S') != NULL) {
    if (SeqMgrFeaturesAreIndexed (entityID) == 0) {
      SeqMgrIndexFeatures (entityID, 0);
    }
    cfp->nucbsp = FindNucBioseq (sep);
    if (cfp->nucbsp != NULL) {
      BioseqToGeneticCode (cfp->nucbsp, &(cfp->genCode), NULL, NULL, NULL, 0, NULL);
      SetBatchSuggestNucleotide (cfp->nucbsp, cfp->genCode);
      SeqIdWrite (cfp->nucbsp->id, id, PRINTID_FASTA_LONG, sizeof (id) - 1);
      fprintf (cfp->ofp, "%s\n", id);
      VisitBioseqsInSep (sep, (Pointer) cfp, DoSuggestIntervals);
      ClearBatchSuggestNucleotide ();
      cfp->nucbsp = NULL;
      cfp->genCode = 0;
    }
  }
  if (StringChr (cfp->feat, 'c') != NULL) {
    VisitFeaturesInSep (sep, (Pointer) cfp, DoVisitCodingRegions);
  }

  if (StringChr (cfp->desc, 'b') != NULL) {
  }
  if (StringChr (cfp->desc, 't') != NULL) {
  }

  if (StringChr (cfp->verify, 'v') != NULL) {
    if (SeqMgrFeaturesAreIndexed (entityID) == 0) {
      SeqMgrIndexFeatures (entityID, 0);
    }
    vsp = ValidStructNew ();
    if (vsp != NULL) {
      vsp->useSeqMgrIndexes = TRUE;
      vsp->suppressContext = TRUE;
      vsp->seqSubmitParent = TRUE;
      vsp->testLatLonSubregion = TRUE;
      oldErrSev = ErrSetMessageLevel (SEV_NONE);
      vsp->errfunc = ValidCallback;
      vsp->userdata = (Pointer) cfp->ofp;
      /* vsp->convertGiToAccn = FALSE; */
      ValidateSeqEntry (sep, vsp);
      ValidStructFree (vsp);
      ErrSetMessageLevel (oldErrSev);
    }
  }
  if (StringChr (cfp->verify, 'b') != NULL) {
    if (SeqMgrFeaturesAreIndexed (entityID) == 0) {
      SeqMgrIndexFeatures (entityID, 0);
    }
    SeqEntryToGnbk (sep, NULL, GENBANK_FMT, SEQUIN_MODE, NORMAL_STYLE,
                    0, 0, 0, NULL, cfp->ofp);
  }

  if (cfp->ofp != NULL) {
    fflush (cfp->ofp);
  }
}