1 #ifndef ALGO_ALIGN_NW_DEMO_HFILTER_HITFILTER_APP__HPP
2 #define ALGO_ALIGN_NW_DEMO_HFILTER_HITFILTER_APP__HPP
3 
4 /* $Id: hitfilter_app.hpp 179209 2009-12-22 16:44:40Z kapustin $
5 * ===========================================================================
6 *
7 *                            PUBLIC DOMAIN NOTICE
8 *               National Center for Biotechnology Information
9 *
10 *  This software/database is a "United States Government Work" under the
11 *  terms of the United States Copyright Act.  It was written as part of
12 *  the author's official duties as a United States Government employee and
13 *  thus cannot be copyrighted.  This software/database is freely available
14 *  to the public for use. The National Library of Medicine and the U.S.
15 *  Government have not placed any restriction on its use or reproduction.
16 *
17 *  Although all reasonable efforts have been taken to ensure the accuracy
18 *  and reliability of the software and data, the NLM and the U.S.
19 *  Government do not and cannot warrant the performance or results that
20 *  may be obtained by using this software or data. The NLM and the U.S.
21 *  Government disclaim all warranties, express or implied, including
22 *  warranties of performance, merchantability or fitness for any particular
23 *  purpose.
24 *
25 *  Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================
28 *
29 * Author:  Yuri Kapustin
30 *
31 * File Description:  HitFilter application class definition
32 *
33 * ===========================================================================
34 */
35 
36 #include <corelib/ncbiapp.hpp>
37 #include <corelib/ncbienv.hpp>
38 #include <corelib/ncbiargs.hpp>
39 
40 #include <algo/align/util/blast_tabular.hpp>
41 
42 
43 BEGIN_NCBI_SCOPE
44 
45 
46 class CAppHitFilterException : public CException
47 {
48 public:
49     enum EErrCode {
50         eInternal,
51         eGeneral
52     };
GetErrCodeString(void) const53     virtual const char* GetErrCodeString(void) const {
54         switch ( GetErrCode() ) {
55         case eInternal:
56             return "eInternal";
57         case eGeneral:
58             return "eGeneral";
59         default:
60             return CException::GetErrCodeString();
61         }
62     }
63     NCBI_EXCEPTION_DEFAULT(CAppHitFilterException, CException);
64 };
65 
66 
67 BEGIN_SCOPE(objects)
68     class CSeq_align;
69 END_SCOPE(objects)
70 
71 class CAppHitFilter : public CNcbiApplication
72 {
73 public:
74 
75     virtual void Init();
76     virtual int  Run();
77     virtual void Exit();
78 
79     typedef CBlastTabular          THit;
80     typedef CRef<THit>             THitRef;
81     typedef vector<THitRef>        THitRefs;
82 
83     enum EReciprocity {
84         e_Other,
85         e_SubjectDuplication,
86         e_QueryDuplication,
87         e_ReciprocalBest
88     };
89 
90 private:
91 
92     typedef list<CRef<objects::CSeq_align> > TSeqAlignList;
93 
94     void x_ReadInputHits(THitRefs* phitrefs, bool one_pair = false);
95     void x_IterateSeqAlignList(const TSeqAlignList& sa_list,
96                                THitRefs* phitrefs,
97                                bool parse_aln,
98                                const THit::TCoord& min_len,
99                                const double& min_idty) const;
100     void x_DumpOutput(const THitRefs& hitrefs);
101     void x_LoadConstraints(CNcbiIstream& istr, THitRefs& all);
102     void x_LoadIDs(CNcbiIstream& istr);
103 
104     void x_DoPairwise(THitRefs* pall);
105     void x_DoMultiple(THitRefs* pall);
106 
107     typedef map<string,string> TMapIds;
108     TMapIds m_IDs;
109 
110     struct SBuildIDs {
111         string m_id [2];
112     };
113     typedef map<string,SBuildIDs> TMapIdPairs;
114     TMapIdPairs m_IDRevs;
115 };
116 
117 
118 END_NCBI_SCOPE
119 
120 
121 #endif /* ALGO_ALIGN_NW_DEMO_HFILTER_HITFILTER_APP__HPP */
122