NCBI C++ ToolKit
table_annot_data_source.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_CORE___TABLE_ANNOT_DATA_SOURCE__HPP
2 #define GUI_CORE___TABLE_ANNOT_DATA_SOURCE__HPP
3 
4 /* $Id: table_annot_data_source.hpp 30332 2014-04-30 19:22:24Z falkrb $
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  * Authors: Bob Falk
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbistl.hpp>
36 #include <corelib/ncbiobj.hpp>
37 
38 #include <util/icanceled.hpp>
39 
43 
44 #include <gui/gui_export.h>
45 
46 
49 
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 /// CAnnotDataSource -
53 ///
54 /// This class wraps a CSeq_annot that contains a CSeq_table. The class
55 /// has features for finding fields in the table that respresent locations
56 /// and then either adding those as location columns or converting the fields
57 /// as needed to create region fetures.
59 {
60 public:
63  : m_IdCol(-1)
64  , m_StartPosCol(-1)
65  , m_StopPosCol(-1)
66  , m_StrandCol(-1)
67  , m_LengthCol(-1)
68  , m_DataRegionCol(-1)
69  , m_GenotypeCol(-1)
70  , m_IsRsid(false) {}
71 
72  /// Some of these may be -1 (e.g. stop OR length, and data region)
73  STableLocation(int col, int start, int stop, int length, int strand, int dr, int gt, bool rsid)
74  : m_IdCol(col)
75  , m_StartPosCol(start)
76  , m_StopPosCol(stop)
77  , m_StrandCol(strand)
78  , m_LengthCol(length)
79  , m_DataRegionCol(dr)
80  , m_GenotypeCol(gt)
81  , m_IsRsid(rsid) {}
82 
83  /// Return informational string as to which columns are selected
84  string GetColumnInfo() const;
85 
86  int m_IdCol;
91  // data region is needed for creating seq-features from table rows
93  // genotype column needed for creating snp features
95  // Snip/variation ids imply a specific location so will not need start/stop fields
96  bool m_IsRsid;
97  };
98 
99 public:
100  /// ctor
102 
103  /// clears all columns rows and delimiters
104  void Clear();
105 
106  void Init() {}
107 
108 
109 
110  /// return total number of rows read
111  size_t GetNumRows() const { return 0; }
112 
113  /// return a specific field from a specific row, based on current table type
114  /// and delimiter
115  string GetField(size_t row, size_t col) const;
116 
117  /// Find colums that can be combined to form locations based on column info
118  /// If no locations are found, missing info is given in msg.
119  vector<STableLocation> FindLocations(string& msg, bool strand_required);
120 
121  /// Add a location to the table based on the specified columns
122  bool AddSeqLoc(const STableLocation& fc, int loc_number, ICanceled* cancel=NULL);
123 
124  /// Add a location to the table using the rsid (snp/variation) ids location from the snp db
125  bool AddSnpSeqLoc(const STableLocation& fc, int loc_number, ICanceled* cancel=NULL);
126 
127  /// Create a feature using specified columns
128  bool CreateFeature(const STableLocation& fc, ICanceled* cancel=NULL);
129 
130  /// Create a region feature for each snp using specified snp (rsid) column
131  bool CreateSnpFeature(const STableLocation& fc, ICanceled* cancel=NULL);
132 
133  /// Create snips (features that show variations) for each row
134  bool CreateSnps(const STableLocation& fc, ICanceled* cancel=NULL);
135 
136  /// Remove any seqloc columns (can be used to undo the AddSeqLoc actions)
137  void RemoveSeqLocs();
138 
139  CRef<CSeq_annot> GetContainer() { return m_AnnotContainer; }
140 
141  /// Write seqtable to file 'fname'. If write_extended_form is not
142  /// true a seq-table will be written, otherwise a seq-annot with meta-
143  /// information will be written with an embedded seq-table.
144  void WriteAsn(const string& fname);
145 
146 protected:
147 
148  /// Get meta information stored in User_Data in m_AnnotContainer
149  CAnnotdesc::TUser* x_GetColumnMetaInfo();
150 
151  /// Return enumerated strand type based on string
152  ENa_strand x_GetStrand(string strand);
153 
154  /// Log an error (but stop logging if error count gets high
155  void x_LogErr(const string& logstr, string& errstr, int& err_count, int row);
156 
157  /// Search string 'meta_string' for the value assigned to 'tag_name', e.g.
158  /// GetMetaInfoTag("&genome_assembly=GRCh37.p5 &one_based=true",
159  /// "genome_assembly") == "GRCh37.p5"
160  string x_GetMetaInfoTag(const string& meta_string, const string& tag_name);
161 
162  /// Change the value for 'tag_name' in 'meta_string' to 'new_value'.
163  /// returns true on change, false on not-found.
164  bool x_UpdateMetaInfoTag(string& meta_string,
165  const string& tag_name,
166  const string& new_value);
167 
169 };
170 
172 
173 
174 #endif // GUI_CORE___TABLE_ANNOT_DATA_SOURCE__HPP
175 
User-defined methods of the data storage class.
Data storage class.
Int2 LIBCALLBACK WriteAsn(Pointer object, CharPtr data, Uint2 length)
Definition: asntypes.cpp:638
#define false
Definition: bool.h:36
CObject –.
Definition: ncbiobj.hpp:180
CRef< CSeq_annot > GetContainer()
size_t GetNumRows() const
return total number of rows read
CRef< CSeq_annot > m_AnnotContainer
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
#define NULL
Definition: ncbistd.hpp:225
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_LOADERS_EXPORT
Definition: gui_export.h:525
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
Defines to provide correct exporting from DLLs in Windows.
sat & gt
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
The NCBI C++/STL use hints.
#define fc
STableLocation(int col, int start, int stop, int length, int strand, int dr, int gt, bool rsid)
Some of these may be -1 (e.g. stop OR length, and data region)
USING_SCOPE(objects)
Modified on Sun Mar 03 03:13:00 2024 by modify_doxy.py rev. 669887