00001 /* $Id: gb_release_file.cpp 103491 2007-05-04 17:18:18Z kazimird $ 00002 * =========================================================================== 00003 * 00004 * PUBLIC DOMAIN NOTICE 00005 * National Center for Biotechnology Information 00006 * 00007 * This software/database is a "United States Government Work" under the 00008 * terms of the United States Copyright Act. It was written as part of 00009 * the author's official duties as a United States Government employee and 00010 * thus cannot be copyrighted. This software/database is freely available 00011 * to the public for use. The National Library of Medicine and the U.S. 00012 * Government have not placed any restriction on its use or reproduction. 00013 * 00014 * Although all reasonable efforts have been taken to ensure the accuracy 00015 * and reliability of the software and data, the NLM and the U.S. 00016 * Government do not and cannot warrant the performance or results that 00017 * may be obtained by using this software or data. The NLM and the U.S. 00018 * Government disclaim all warranties, express or implied, including 00019 * warranties of performance, merchantability or fitness for any particular 00020 * purpose. 00021 * 00022 * Please cite the author in any work or product based on this material. 00023 * 00024 * =========================================================================== 00025 * 00026 * Author: Mati Shomrat 00027 * File Description: 00028 * Utility class for processing Genbank release files. 00029 * 00030 */ 00031 #include <ncbi_pch.hpp> 00032 #include <corelib/ncbistd.hpp> 00033 #include <serial/objhook.hpp> 00034 #include <serial/objistr.hpp> 00035 #include <serial/objectiter.hpp> 00036 #include <serial/objectio.hpp> 00037 #include <objects/seqset/Seq_entry.hpp> 00038 #include <objects/seqset/Bioseq_set.hpp> 00039 #include <vector> 00040 #include <algorithm> 00041 #include <objects/seqset/gb_release_file.hpp> 00042 00043 00044 BEGIN_NCBI_SCOPE 00045 USING_SCOPE(objects); 00046 00047 00048 //////////////////////////////////////////////////////////////////////////// 00049 // 00050 // CGBReleaseFileImpl 00051 00052 00053 class CGBReleaseFileImpl : public CReadClassMemberHook 00054 { 00055 public: 00056 typedef CGBReleaseFile::ISeqEntryHandler* THandler; 00057 00058 CGBReleaseFileImpl(const string& file_name); 00059 CGBReleaseFileImpl(CObjectIStream& in); 00060 00061 void Read(void); 00062 void RegisterHandler(THandler handler); 00063 00064 virtual void ReadClassMember(CObjectIStream& in, const CObjectInfoMI& member); 00065 00066 private: 00067 THandler m_Handler; 00068 auto_ptr<CObjectIStream> m_In; 00069 CBioseq_set m_Seqset; 00070 bool m_Stopped; 00071 }; 00072 00073 00074 CGBReleaseFileImpl::CGBReleaseFileImpl(const string& file_name) : 00075 m_In(CObjectIStream::Open(file_name, eSerial_AsnBinary)), 00076 m_Stopped(false) 00077 { 00078 _ASSERT(m_In.get() != 0 && m_In->InGoodState()); 00079 } 00080 00081 00082 CGBReleaseFileImpl::CGBReleaseFileImpl(CObjectIStream& in) : 00083 m_In(&in), m_Stopped(false) 00084 { 00085 _ASSERT(m_In.get() != 0 && m_In->InGoodState()); 00086 } 00087 00088 00089 void CGBReleaseFileImpl::RegisterHandler(THandler handler) 00090 { 00091 m_Handler = handler; 00092 } 00093 00094 00095 void CGBReleaseFileImpl::Read(void) 00096 { 00097 // install the read hook on the top level Bioseq-set's sequence of entries 00098 CObjectTypeInfo info(CBioseq_set::GetTypeInfo()); 00099 info.FindMember("seq-set").SetLocalReadHook(*m_In, this); 00100 00101 try { 00102 // read in the file, this will execute the handler's code for each 00103 // Seq-entry read. 00104 m_In->Read(&m_Seqset, CBioseq_set::GetTypeInfo()); 00105 } catch (const CException&) { 00106 if ( !m_Stopped ) { 00107 throw; 00108 } 00109 } 00110 } 00111 00112 00113 void CGBReleaseFileImpl::ReadClassMember 00114 (CObjectIStream& in, 00115 const CObjectInfoMI& member) 00116 { 00117 // remove the read hook 00118 member.ResetLocalReadHook(in); 00119 00120 // iterate over the sequence of entries 00121 for ( CIStreamContainerIterator it(in, member); it; ++it ) { 00122 CRef<CSeq_entry> se(new CSeq_entry); 00123 it >> *se; 00124 if ( se ) { 00125 if ( !m_Handler->HandleSeqEntry(se) ) { 00126 m_Stopped = true; 00127 break; 00128 } 00129 } 00130 } 00131 } 00132 00133 00134 ///////////////////////////////////////////////////////////////////////////// 00135 // 00136 // CGBReleaseFile 00137 00138 00139 CGBReleaseFile::CGBReleaseFile(const string& file_name) : 00140 m_Impl(new CGBReleaseFileImpl(file_name)) 00141 { 00142 _ASSERT(m_Impl); 00143 } 00144 00145 00146 CGBReleaseFile::CGBReleaseFile(CObjectIStream& in) : 00147 m_Impl(new CGBReleaseFileImpl(in)) 00148 { 00149 _ASSERT(m_Impl); 00150 } 00151 00152 00153 CGBReleaseFile::~CGBReleaseFile(void) 00154 { 00155 } 00156 00157 00158 void CGBReleaseFile::Read(void) 00159 { 00160 x_GetImpl().Read(); 00161 } 00162 00163 00164 void CGBReleaseFile::RegisterHandler(ISeqEntryHandler* handler) 00165 { 00166 x_GetImpl().RegisterHandler(handler); 00167 } 00168 00169 00170 CGBReleaseFileImpl& CGBReleaseFile::x_GetImpl(void) 00171 { 00172 return reinterpret_cast<CGBReleaseFileImpl&>(*m_Impl); 00173 } 00174 00175 00176 END_NCBI_SCOPE 00177 00178
1.4.6
Modified on Mon Dec 07 16:21:09 2009 by modify_doxy.py rev. 173732