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

Go to the SVN repository for this file.

1 /* $Id: alnmgr_sample.cpp 90014 2020-05-04 17:30:22Z ivanov $
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 * Author: Kamen Todorov, NCBI
27 *
28 * File Description:
29 * Sample alignment manager application
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbiapp.hpp>
36 #include <corelib/ncbiargs.hpp>
37 #include <corelib/ncbienv.hpp>
38 
40 
41 #include <serial/iterator.hpp>
42 #include <serial/objistr.hpp>
43 #include <serial/objostr.hpp>
44 #include <serial/serial.hpp>
45 
46 #include <objects/seq/Bioseq.hpp>
50 
53 
56 #include <objmgr/scope.hpp>
57 #include <objmgr/seq_vector.hpp>
58 
61 
64 
65 
67 {
68  virtual void Init(void);
69  virtual int Run(void);
70 };
71 
72 
74 {
75  // Create command-line argument descriptions class
76  unique_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
77 
78  // Specify USAGE context
79  arg_desc->SetUsageContext
80  (GetArguments().GetProgramBasename(),
81  "Alignment manager demo program: Seq-align extractor/viewer");
82 
83  // Describe the expected command-line arguments
84  arg_desc->AddDefaultKey
85  ("in", "InputFile",
86  "name of file to read from (standard input by default)",
88 
89  arg_desc->AddDefaultKey
90  ("out", "OutputFile",
91  "name of file to write to (standard output by default)",
93 
94  arg_desc->AddDefaultKey
95  ("asnout", "OutputFile",
96  "name of asn file to write to (standard output by default)",
98 
99  // Setup arg.descriptions for this application
100  SetupArgDescriptions(arg_desc.release());
101 }
102 
103 
105 {
106  // Setup application registry, error log, and MT-lock for CONNECT library
108 
109  // Get arguments
110  const CArgs& args = GetArgs();
111  CSeq_align in_sa;
112  CSeq_entry in_se;
113 
114  // Read the file
115  {{
116  unique_ptr<CObjectIStream> in(CObjectIStream::Open(eSerial_AsnText, args["in"].AsInputFile()));
117  *in >> in_se;
118  }}
119 
120  unique_ptr<CObjectOStream> asn_out(CObjectOStream::Open(eSerial_AsnText, args["asnout"].AsOutputFile()));
121  asn_out->SetSeparator("\n");
122 
123  CNcbiOstream& out = args["out"].AsOutputFile();
124 
127  CScope scope(*objmgr);
128  scope.AddDefaults();
129 
130  CAlnMix mix(scope);
131  for (CTypeIterator<CDense_seg> sa_it = Begin(in_se); sa_it; ++sa_it) {
132  mix.Add(*sa_it);
133  }
135  *asn_out << mix.GetDenseg();
136  *asn_out << Separator;
137  asn_out->Flush();
138 
139  CAlnVec av(mix.GetDenseg(), scope);
140  av.SetAnchor(0);
141 
144 
145  for (int i = 0; i < chunk_vec->size(); i++) {
146  CConstRef<CAlnMap::CAlnChunk> chunk = (*chunk_vec)[i];
147  if (!chunk->IsGap()) {
148  out << chunk->GetRange().GetFrom() << "-" << chunk->GetRange().GetTo();
149  } else {
150  out << "gap";
151  }
152  if (chunk->GetType() & CAlnMap::fSeq) {
153  cout << "(Seq)";
154  }
155  if (chunk->GetType() & CAlnMap::fNotAlignedToSeqOnAnchor) {
156  cout << "(NotAlignedToSeqOnAnchor)";
157  }
158  if (chunk->GetType() & CAlnMap::fUnalignedOnRight) {
159  cout << "(UnalignedOnRight)";
160  }
161  if (chunk->GetType() & CAlnMap::fUnalignedOnLeft) {
162  cout << "(UnalignedOnLeft)";
163  }
164  if (chunk->GetType() & CAlnMap::fNoSeqOnRight) {
165  cout << "(NoSeqOnRight)";
166  }
167  if (chunk->GetType() & CAlnMap::fNoSeqOnLeft) {
168  cout << "(NoSeqOnLeft)";
169  }
170  if (chunk->GetType() & CAlnMap::fEndOnRight) {
171  cout << "(EndOnRight)";
172  }
173  if (chunk->GetType() & CAlnMap::fEndOnLeft) {
174  cout << "(EndOnLeft)";
175  }
176  cout << endl;
177  }
178  return 0;
179 }
180 
181 
182 /////////////////////////////////////////////////////////////////////////////
183 // MAIN
184 
185 int NcbiSys_main(int argc, TXChar* argv[])
186 {
187  // Execute main application function
188  return CSampleAlnmgrApplication().AppMain(argc, argv);
189 }
int NcbiSys_main(int argc, TXChar *argv[])
USING_SCOPE(ncbi)
@ fUnalignedOnRight
Definition: alnmap.hpp:55
@ fEndOnRight
Definition: alnmap.hpp:59
@ fNoSeqOnRight
Definition: alnmap.hpp:57
@ fNoSeqOnLeft
Definition: alnmap.hpp:58
@ fNotAlignedToSeqOnAnchor
Definition: alnmap.hpp:53
@ fSeq
Definition: alnmap.hpp:52
@ fUnalignedOnLeft
Definition: alnmap.hpp:56
@ fEndOnLeft
Definition: alnmap.hpp:60
void SetAnchor(TNumrow anchor)
Definition: alnmap.cpp:79
CRef< CAlnChunkVec > GetAlnChunks(TNumrow row, const TSignedRange &range, TGetChunkFlags flags=fAlnSegsOnly) const
Definition: alnmap.cpp:1002
void Add(const CDense_seg &ds, TAddFlags flags=0)
Definition: alnmix.cpp:120
@ fNegativeStrand
Definition: alnmix.hpp:102
@ fTruncateOverlaps
Definition: alnmix.hpp:101
void Merge(TMergeFlags flags=0)
Definition: alnmix.cpp:273
const CDense_seg & GetDenseg(void) const
Definition: alnmix.cpp:295
CArgDescriptions –.
Definition: ncbiargs.hpp:541
CArgs –.
Definition: ncbiargs.hpp:379
CConstRef –.
Definition: ncbiobj.hpp:1266
static TRegisterLoaderInfo RegisterInObjectManager(CObjectManager &om, CReader *reader=0, CObjectManager::EIsDefault is_default=CObjectManager::eDefault, CObjectManager::TPriority priority=CObjectManager::kPriority_NotSet)
Definition: gbloader.cpp:366
virtual int Run(void)
Run the application.
virtual void Init(void)
Initialize the application.
CScope –.
Definition: scope.hpp:92
Definition: Seq_entry.hpp:56
Template class for iteration on objects of class C.
Definition: iterator.hpp:673
std::ofstream out("events_result.xml")
main entry point for tests
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
Definition: ncbiapp.cpp:285
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
Definition: ncbiapp.cpp:799
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
Definition: ncbiapp.cpp:1175
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ fPreOpen
Open file right away; for eInputFile, eOutputFile, eIOFile.
Definition: ncbiargs.hpp:618
@ eInputFile
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:595
@ eOutputFile
Name of file (must be writable)
Definition: ncbiargs.hpp:596
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
CBeginInfo Begin(C &obj)
Get starting point of object hierarchy.
Definition: iterator.hpp:1004
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
char TXChar
Definition: ncbistr.hpp:172
void CONNECT_Init(const IRWRegistry *reg=0, CRWLock *lock=0, TConnectInitFlags flag=eConnectInit_OwnNothing, FSSLSetup ssl=0)
Init [X]CONNECT library with the specified "reg" and "lock" (ownership for either or both can be deta...
int i
range(_Ty, _Ty) -> range< _Ty >
Magic spell ;-) needed for some weird compilers... very empiric.
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
Defines unified interface to application:
std::istream & in(std::istream &in_, double &x_)
The Object manager core.
Modified on Sat Dec 02 09:19:42 2023 by modify_doxy.py rev. 669887