NCBI C++ ToolKit
asn_export_job.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: asn_export_job.cpp 26539 2012-10-03 16:40:50Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <corelib/ncbifile.hpp>
33 
36 
38 
41 
43 : CAppJob("ASN Export"), m_Params(params)
44 {
45 }
46 
48 {
49  string err_msg;
50 
51  wxString fileName = m_Params.GetFileName();
52 
53  try {
54  ios::openmode mode = ios::out;
55  if (m_Params.GetAsnType())
56  mode |= ios::binary;
57 
58  CNcbiOfstream os(fileName.fn_str(), mode);
59 
60  if (m_Params.GetAsnType())
61  os << MSerial_AsnBinary;
62  else
63  os << MSerial_AsnText;
64 
66  const CSerialObject* so = dynamic_cast<const CSerialObject*>(it->object.GetPointer());
67  CScope* scope = it->scope.GetPointer();
68 
69  const CSeq_id* seq_id = dynamic_cast<const CSeq_id*>(so);
70  const CSeq_loc* seq_loc = dynamic_cast<const CSeq_loc*>(so);
71  CConstRef<CSeq_entry> seq_entry;
72 
73  if (seq_id || seq_loc) {
74  CBioseq_Handle handle;
75  if (seq_id)
76  handle = scope->GetBioseqHandle(*seq_id);
77  else if (seq_loc)
78  handle = scope->GetBioseqHandle(*seq_loc);
79 
80  if (handle) {
81  CSeq_entry_Handle seh = handle.GetTopLevelEntry();
82  if (seh) {
83  seq_entry = seh.GetSeq_entryCore();
84  }
85  }
86  }
87 
88  if (seq_entry)
89  so = seq_entry.GetPointer();
90 
91  if (so) {
92  os << *so;
93  }
94  }
95  }
96  catch (CException& e) {
97  err_msg = "Failed to save file:\n";
98  err_msg += e.GetMsg();
99  }
100 
101  if (err_msg.empty()) {
102  LOG_POST(Info << "CAsnExportJob::Run() Finished " << m_Descr);
103  return eCompleted;
104  } else {
105  m_Error.Reset(new CAppJobError(err_msg));
106  return eFailed;
107  }
108 }
109 
CBioseq_Handle –.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:900
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:641
string m_Descr
mutex to sync our internals
TConstScopedObjects m_Objects
std::ofstream out("events_result.xml")
main entry point for tests
#define MSerial_AsnBinary
Definition: serialbase.hpp:642
CAsnExportJob(const CAsnExportParams &params)
CSeq_entry_Handle GetTopLevelEntry(void) const
Get top level Seq-entry handle.
CConstRef< CSeq_entry > GetSeq_entryCore(void) const
Get const reference to the seq-entry.
virtual EJobState Run()
implement Run() in derived classes, make sure that exceptions are handled and m_StopRequested flag is...
CRef< CAppJobError > m_Error
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
CAppJobError Default implementation for IAppJobError - encapsulates a text error message.
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:198
CSeq_entry_Handle –.
USING_SCOPE(objects)
wxString GetFileName() const
CException –.
Definition: ncbiexpt.hpp:709
vector< SConstScopedObject > TConstScopedObjects
Definition: objects.hpp:103
CScope –.
Definition: scope.hpp:90
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock, CFileIO, CFileReader, CFileWriter, CFileReaderWriter, CFileException.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
CAppJob - default implementation of IAppJob that could be used as a base class.
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1002
Base class for all serializable objects.
Definition: serialbase.hpp:148
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1564
CAsnExportParams m_Params
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:326
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:443
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:756
int GetAsnType() const
Modified on Tue Aug 23 18:28:35 2016 by modify_doxy.py rev. 506947