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

Go to the SVN repository for this file.

1 /* $Id: seq_text_demo_ui.cpp 15281 2007-11-01 16:22:10Z bollin $
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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include "seq_text_demo_ui.hpp"
34 
36 #include <serial/objistr.hpp>
38 #include <serial/serial.hpp>
39 
42 
43 #include "seq_text_demo_ui_.cpp"
44 
45 
46 CSeqTextDemoUI::CSeqTextDemoUI()
47 {
48  m_Window.reset(x_CreateWindow());
49 
50  m_MenuBar->SetCmdTarget(m_MatrixWidget);
51 }
52 
53 
54 CSeqTextDemoUI::~CSeqTextDemoUI()
55 {
56  // these must be deleted in proper order
57  m_DataSource.Reset();
58  m_Window.reset();
59  m_Scope.Reset();
60  m_ObjMgr.Reset();
61 }
62 
63 
64 void CSeqTextDemoUI::Show(int argc, char** argv)
65 {
66  m_Accession->value("gi|78214425");
67  m_Accession->redraw();
68 
69  m_InputFile->value("E:\\Projects\\c++\\compilers\\msvc_prj\\gbench\\blastres.asn");
70  m_InputFile->redraw();
71 
72  m_Window->show(argc, argv);
73  while (m_Window->shown()) {
74  Fl::wait();
75  }
76 }
77 
78 void CSeqTextDemoUI::x_OnLoadAccession()
79 {
80  CSeq_id id;
81  try {
82  id.Set(m_Accession->value());
83  }
84  catch (CSeqIdException&) {
85  string msg("Accession '");
86  msg += m_Accession->value();
87  msg += "' not recognized as a valid accession";
89  "Unhandled Accession");
90  return;
91  }
92 
93  if ( !m_ObjMgr ) {
94  m_ObjMgr = CObjectManager::GetInstance();
96 
97  m_Scope.Reset(new CScope(*m_ObjMgr));
99  }
100 
101  // retrieve our sequence
102  CBioseq_Handle handle = m_Scope->GetBioseqHandle(id);
103  if ( !handle ) {
104  string msg("Can't find sequence for accession '");
105  msg += m_Accession->value();
106  msg += "'";
108  "Sequence Not Found");
109  return;
110  }
111 
112  m_DataSource.Reset(new CSeqTextDataSource(handle, *m_Scope));
113 
114  m_MatrixWidget->SetDataSource (*m_DataSource);
115 }
116 
117 void CSeqTextDemoUI::x_OnLoadFile()
118 {
119  string filename(m_InputFile->value());
120  auto_ptr<CObjectIStream> is(CObjectIStream::Open(eSerial_AsnText, filename));
121 
122  CRef<CSeq_entry> sep(new CSeq_entry());
123  *is >> *sep;
124 
125  if ( !m_ObjMgr ) {
126  m_ObjMgr = CObjectManager::GetInstance();
128 
129  m_Scope.Reset(new CScope(*m_ObjMgr));
130  m_Scope->AddDefaults();
131  }
132 
133  m_DataSource.Reset(new CSeqTextDataSource(*sep, *m_Scope));
134 
135 }
136 
CBioseq_Handle –.
static const unsigned char msg[]
Definition: ccm.c:378
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:463
ASN.1 text.
Definition: serialdef.hpp:73
USING_SCOPE(objects)
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:185
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:243
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
CSeqTextDataSource implements Adapter design pattern.
EDialogReturnValue NcbiMessageBox(const string &message, TDialogType type=eDialog_Ok, EDialogIcon icon=eIcon_Exclamation, const string &title="Error", EDialogTextMode text_mode=eRaw)
Definition: message_box.cpp:48
CScope –.
Definition: scope.hpp:90
Definition: Seq_entry.hpp:55
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
static CRef< CScope > m_Scope
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CSeqIdException –.
Definition: Seq_id.hpp:721
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:756
CSeq_id & Set(const CTempString &the_id, TParseFlags flags=fParse_AnyRaw)
Reassign based on flat specifications; arguments interpreted as with constructors.
Definition: Seq_id.cpp:1905
Modified on Sun Nov 19 16:40:35 2017 by modify_doxy.py rev. 546573