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

Go to the SVN repository for this file.

1 /* $Id: pairwise_aln_app.cpp 33815 2007-05-04 17:18:18Z kazimird $
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
27 *
28 * File Description:
29 * Demo of extracting a pairwise alignment from a file with Seq-align(s).
30 *
31 * ===========================================================================
32 */
33 
34 #include <ncbi_pch.hpp>
35 #include <corelib/ncbistd.hpp>
36 #include <corelib/ncbiapp.hpp>
37 #include <corelib/ncbienv.hpp>
38 #include <corelib/ncbiargs.hpp>
40 
41 #include <common/test_assert.h>
42 
43 #include <serial/objistr.hpp>
44 #include <serial/iterator.hpp>
45 
46 /// Obj Manager
48 #include <objmgr/scope.hpp>
50 
51 /// Aln Manager
57 
58 
59 using namespace ncbi;
60 using namespace objects;
61 
62 
63 /// Types we use here:
64 // typedef CSeq_align::TDim TDim;
65 // typedef vector<const CSeq_align*> TAlnVector;
66 // typedef const CSeq_id* TSeqIdPtr;
67 // typedef vector<TSeqIdPtr> TSeqIdVector;
68 // typedef SCompareOrdered<TSeqIdPtr> TComp;
69 // typedef CAlnSeqIdVector<TAlnVector, TComp> TAlnSeqIdVector;
70 // typedef CSeqIdAlnBitmap<TAlnSeqIdVector> TSeqIdAlnBitmap;
71 // typedef CAlnStats<TAlnVector, TSeqIdVector, TAlnSeqIdVector> TAlnStats;
72 // typedef TAlnStats::TBaseWidths TBaseWidths;
73 // typedef TAlnStats::TAnchorRows TAnchorRows;
74 
75 
77 {
78 public:
79  virtual void Init (void);
80  virtual int Run (void);
81  CScope& GetScope (void) const;
82  void LoadInputAlns(void);
83  bool InsertAln (const CSeq_align* aln) {
84  aln->Validate(true);
85  m_AlnContainer.insert(*aln);
86  return true;
87  }
88 
89 private:
95 };
96 
97 
99 {
100  auto_ptr<CArgDescriptions> arg_desc(new CArgDescriptions);
101 
102  arg_desc->AddDefaultKey
103  ("in", "InputFileName",
104  "Name of file to read from (standard input by default)",
106 
107  arg_desc->AddDefaultKey
108  ("b", "bin_obj_type",
109  "This forces the input file to be read in binary ASN.1 mode\n"
110  "and specifies the type of the top-level ASN.1 object.\n",
112 
113  arg_desc->AddDefaultKey
114  ("q", "QueryRow",
115  "Query (anchor) row (zero-based)",
117 
118  arg_desc->AddDefaultKey
119  ("s", "SubjectRow",
120  "Subject row (zero-based)",
122 
123  // Program description
124  string prog_description = "Alignment build application.\n";
125  arg_desc->SetUsageContext(GetArguments().GetProgramBasename(),
126  prog_description, false);
127 
128  SetupArgDescriptions(arg_desc.release());
129 }
130 
131 
133 {
134  const CArgs& args = GetArgs();
135  string sname = args["in"].AsString();
136 
137  /// get the asn type of the top-level object
138  string asn_type = args["b"].AsString();
139  bool binary = !asn_type.empty();
140  auto_ptr<CObjectIStream> in
142 
143  CAlnAsnReader reader;
144  reader.Read(in.get(),
145  bind1st(mem_fun(&CPairwiseAlnApp::InsertAln), this),
146  asn_type);
147 }
148 
149 
151 {
152  if (!m_Scope) {
153  m_ObjMgr = CObjectManager::GetInstance();
155 
156  m_Scope = new CScope(*m_ObjMgr);
157  m_Scope->AddDefaults();
158  }
159  return *m_Scope;
160 }
161 
162 
164 {
165  // Setup application registry, error log, and MT-lock for CONNECT library
166  CONNECT_Init(&GetConfig());
167 
168  m_QueryRow = GetArgs()["q"].AsInteger();
169  m_SubjectRow = GetArgs()["s"].AsInteger();
170 
171  LoadInputAlns();
172 
173 // /// Create a vector of alignments
174 // TAlnVector aln_vector(m_AlnContainer.size());
175 // aln_vector.assign(m_AlnContainer.begin(), m_AlnContainer.end());
176 
177 
178 // /// Create a comparison functor
179 // TComp comp;
180 
181 
182 // /// Create a vector of seq-ids per seq-align
183 // TAlnSeqIdVector aln_seq_id_vector(aln_vector, comp);
184 
185 
186 // /// Create an alignment bitmap to obtain statistics.
187 // TSeqIdAlnBitmap id_aln_bitmap(aln_seq_id_vector, GetScope());
188 // id_aln_bitmap.Dump(cout);
189 
190 // /// Determine anchor row for each alignment
191 // TBaseWidths base_widths;
192 // bool translated = id_aln_bitmap.GetTranslatedAlnCount();
193 // if (translated) {
194 // base_widths.resize(id_aln_bitmap.GetAlnCount());
195 // for (size_t aln_idx = 0; aln_idx < aln_seq_id_vector.size(); ++aln_idx) {
196 // const TSeqIdVector& ids = aln_seq_id_vector[aln_idx];
197 // base_widths[aln_idx].resize(ids.size());
198 // for (size_t row = 0; row < ids.size(); ++row) {
199 // CBioseq_Handle bioseq_handle = m_Scope->GetBioseqHandle(*ids[row]);
200 // if (bioseq_handle.IsProtein()) {
201 // base_widths[aln_idx][row] = 3;
202 // } else if (bioseq_handle.IsNucleotide()) {
203 // base_widths[aln_idx][row] = 1;
204 // } else {
205 // string err_str =
206 // string("Cannot determine molecule type for seq-id: ")
207 // + ids[row]->AsFastaString();
208 // NCBI_THROW(CSeqalignException, eInvalidSeqId, err_str);
209 // }
210 // }
211 // }
212 // }
213 
214 
215 // /// Determine anchor rows;
216 // TAnchorRows anchor_rows;
217 // bool anchored = id_aln_bitmap.IsQueryAnchored();
218 // if (anchored) {
219 // TSeqIdPtr anchor_id = id_aln_bitmap.GetAnchorHandle().GetSeqId();
220 // anchor_rows.resize(id_aln_bitmap.GetAlnCount(), -1);
221 // for (size_t aln_idx = 0; aln_idx < anchor_rows.size(); ++aln_idx) {
222 // const TSeqIdVector& ids = aln_seq_id_vector[aln_idx];
223 // for (size_t row = 0; row < ids.size(); ++row) {
224 // if ( !(comp(ids[row], anchor_id) ||
225 // comp(anchor_id, ids[row])) ) {
226 // anchor_rows[aln_idx] = row;
227 // break;
228 // }
229 // }
230 // _ASSERT(anchor_rows[aln_idx] >= 0);
231 // }
232 // }
233 
234 
235 // /// Store all retrieved statistics in the aln hints
236 // TAlnStats aln_stats(aln_vector,
237 // aln_seq_id_vector,
238 // anchored ? &anchor_rows : 0,
239 // translated ? &base_widths : 0);
240 // aln_stats.Dump(cout);
241 
242 
243 // /// Construct pairwise alignmenst based on the aln hints
244 // for (size_t aln_idx = 0;
245 // aln_idx < aln_stats.GetAlnCount();
246 // ++aln_idx) {
247 
248 // CPairwiseAln
249 // pairwise_aln(*aln_stats.GetAlnVector()[aln_idx],
250 // m_QueryRow,
251 // m_SubjectRow,
252 // aln_stats.GetBaseWidthForAlnRow(aln_idx, m_QueryRow),
253 // aln_stats.GetBaseWidthForAlnRow(aln_idx, m_SubjectRow));
254 
255 // pairwise_aln.Dump(cout);
256 // }
257 // cout << endl;
258 
259 
260  return 0;
261 }
262 
263 
264 int main(int argc, const char* argv[])
265 {
266  return CPairwiseAlnApp().AppMain(argc, argv, 0, eDS_Default, 0);
267 }
void Run(void)
Enter the main loop.
void AddDefaultKey(const string &name, const string &synopsis, const string &comment, EType type, const string &default_value, TFlags flags=0, const string &env_var=kEmptyStr, const char *display_value=nullptr)
Add description for optional key with default value.
Definition: ncbiargs.cpp:2256
Defines command line argument related classes.
void LoadInputAlns(void)
Name of file (must exist and be readable)
Definition: ncbiargs.hpp:568
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:461
ASN.1 text.
Definition: serialdef.hpp:73
CScope & GetScope(void) const
Defines unified interface to application:
Helper class for reading seq-align objects from a CObjectIStream.
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:626
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
Convertible into an integer number (int or Int8)
Definition: ncbiargs.hpp:566
Types we use here:
CRef< CScope > m_Scope
int main(int argc, const char *argv[])
CScope & GetScope()
Definition: wgs_utils.cpp:48
virtual int Run(void)
Run the application.
Try standard log file (app.name + ".log") in /log/, use stderr on failure.
Definition: ncbidiag.hpp:1757
The Object manager core.
#define GetArgs
Avoid preprocessor name clash with the NCBI C Toolkit.
Definition: ncbiapp.hpp:59
CArgDescriptions –.
Definition: ncbiargs.hpp:514
Magic spell ;-) needed for some weird compilers... very empiric.
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" (ownerhsip for either or both can be deta...
An arbitrary string.
Definition: ncbiargs.hpp:563
CRef< CObjectManager > m_ObjMgr
CScope –.
Definition: scope.hpp:90
void Validate(bool full_test=false) const
Definition: Seq_align.cpp:649
CArgs –.
Definition: ncbiargs.hpp:356
void Read(CObjectIStream *obj_in_stream, TCallback callback, const string &top_level_asn_object=kEmptyStr)
Read all seq-align objects from the stream.
static CRef< CScope > m_Scope
static void Init(void)
Definition: cursor6.c:79
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
bool InsertAln(const CSeq_align *aln)
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
CNcbiApplication –.
Definition: ncbiapp.hpp:120
void SetUsageContext(const string &usage_name, const string &usage_description, bool usage_sort_args=false, SIZE_TYPE usage_width=78)
Set extra info to be used by PrintUsage().
Definition: ncbiargs.cpp:3110
CAlnContainer m_AlnContainer
std::istream & in(std::istream &in_, double &x_)
CSeq_align container.
virtual void Init(void)
Initialize the application.
ASN.1 binary.
Definition: serialdef.hpp:74
Modified on Tue Sep 19 16:26:14 2017 by modify_doxy.py rev. 546573