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

Go to the SVN repository for this file.

1 /* $Id: seqgraphic_utils.cpp 42838 2019-04-19 17:24:56Z shkeda $
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: Liangshou Wu
27  *
28  * File Description:
29  *
30  */
31 
32 
33 #include <ncbi_pch.hpp>
34 
36 
38 #include <objmgr/util/sequence.hpp>
39 #include <objmgr/seqdesc_ci.hpp>
42 #include <objects/seq/MolInfo.hpp>
46 
47 
50 
51 
52 bool CSGUtils::IsChromosome(const CBioseq_Handle& handle, CScope& scope)
53 {
54  CConstRef<CSeq_id> seq_id = handle.GetSeqId();
55 
57  scope, sequence::eGetId_Best);
58  if (idh) {
59  seq_id = idh.GetSeqId();
60  }
61 
64  return true;
65  }
66 
67  CSeqdesc_CI desc_it(handle, CSeqdesc::e_Source);
68  while (desc_it) {
70  return true;
71  }
72  ++desc_it;
73  }
74 
75  return false;
76 }
77 
78 
79 bool CSGUtils::IsSegSet(const CBioseq_Handle& handle, CScope& scope)
80 {
81  // try to resolve the given seq-id
82  CSeq_id_Handle idh = handle.GetSeq_id_Handle();
83  idh = sequence::GetId(*idh.GetSeqId(), scope, sequence::eGetId_Best);
84 
85  if (handle.IsSetInst_Repr() &&
86  handle.GetInst_Repr() == CSeq_inst::eRepr_seg) {
87  return true;
88  }
89 
90  return false;
91 }
92 
93 
94 bool CSGUtils::IsmRNA(const CBioseq_Handle& handle, CScope& scope)
95 {
96  const CMolInfo* info = sequence::GetMolInfo(handle);
97  if (info) {
98  if (info->GetBiomol() == CMolInfo::eBiomol_mRNA ||
99  info->GetBiomol() == CMolInfo::eBiomol_pre_RNA ||
100  info->GetBiomol() == CMolInfo::eBiomol_tRNA ||
101  info->GetBiomol() == CMolInfo::eBiomol_snRNA ||
102  info->GetBiomol() == CMolInfo::eBiomol_scRNA ||
103  info->GetBiomol() == CMolInfo::eBiomol_cRNA ||
104  info->GetBiomol() == CMolInfo::eBiomol_snoRNA ||
105  info->GetBiomol() == CMolInfo::eBiomol_ncRNA ||
106  info->GetBiomol() == CMolInfo::eBiomol_tmRNA) {
107  return true;
108  }
109  }
110 
111  CConstRef<CSeq_id> seq_id = handle.GetSeqId();
112  CSeq_id_Handle idh = sequence::GetId(handle.GetSeq_id_Handle(), scope,
114  if (idh) {
115  seq_id = idh.GetSeqId();
116  }
117 
118  CSeq_id::EAccessionInfo id_info = seq_id->IdentifyAccession();
119 
120  if ((id_info & CSeq_id::eAcc_division_mask) == CSeq_id::eAcc_est ||
121  id_info == CSeq_id::eAcc_refseq_mrna ||
123  id_info == CSeq_id::eAcc_gpipe_mrna) {
124  return true;
125  }
126 
127  return false;
128 }
129 
130 bool CSGUtils::IsRefSeq(const objects::CBioseq_Handle& handle)
131 {
132  CConstRef<CSeq_id> seq_id = handle.GetSeqId();
133  // this is needed for cases when handle was originally created with a GI so IdentifyAccession() does not return an e_Gi based on
134  // the look of the original ID, so we need to get the "best" representation that will return the real meaning of the thing
136  if (idh) {
137  seq_id = idh.GetSeqId();
138  }
139  return IsRefSeq(*seq_id);
140 }
141 
142 bool CSGUtils::IsRefSeq(const string& seqid)
143 {
144  return IsRefSeq(CSeq_id(seqid));
145 }
146 
147 bool CSGUtils::IsRefSeq(const objects::CSeq_id& seqid)
148 {
149  CSeq_id::EAccessionInfo info = seqid.IdentifyAccession();
164 }
165 
166 
167 bool CSGUtils::IsMitochondrion(const objects::CBioseq_Handle& handle)
168 {
169  CSeqdesc_CI desc_it(handle, CSeqdesc::e_Source);
170  while (desc_it) {
172  return true;
173  }
174  ++desc_it;
175  }
176 
177  return false;
178 }
179 
180 
181 bool CSGUtils::IsPlastid(const objects::CBioseq_Handle& handle)
182 {
183  CSeqdesc_CI desc_it(handle, CSeqdesc::e_Source);
184  while (desc_it) {
185  if (desc_it->GetSource().GetGenome() == CBioSource::eGenome_plastid) {
186  return true;
187  }
188  ++desc_it;
189  }
190 
191  return false;
192 }
193 
194 
195 /* Obsolete, use gui/objutils/na_utils:CDataTrackUtils::IsGeneModelFeature
196 bool CSGUtils::IsMainFeature(int type, int subtype)
197 {
198  return (subtype == CSeqFeatData::eSubtype_exon ||
199  subtype == CSeqFeatData::eSubtype_misc_RNA ||
200  subtype == CSeqFeatData::eSubtype_C_region ||
201  subtype == CSeqFeatData::eSubtype_V_segment ||
202  subtype == CSeqFeatData::eSubtype_D_segment ||
203  subtype == CSeqFeatData::eSubtype_J_segment ||
204  type == CSeqFeatData::e_Gene ||
205  type == CSeqFeatData::e_Cdregion ||
206  type == CSeqFeatData::e_Rna);
207 }
208 */
209 
210 
211 bool CSGUtils::GetFeatFetchDepth(const objects::CBioseq_Handle& handle,
212  objects::CScope& scope, int& depth)
213 {
214  if (handle.IsSetDescr()) {
215  CSeqdesc_CI desc_it(handle, CSeqdesc::e_User);
216  while (desc_it) {
217  const CSeqdesc& desc = *desc_it;
218  if (desc.IsUser()) {
219  const CUser_object& user = desc.GetUser();
220  const CObject_id& id = user.GetType();
221  if (id.IsStr() && id.GetStr() == "FeatureFetchPolicy") {
222  ITERATE ( CUser_object::TData, fit, user.GetData() ) {
223  const CUser_field& field = **fit;
224  const CObject_id& fid = field.GetLabel();
225  if ( !fid.IsStr() || fid.GetStr() != "Depth" ) {
226  continue;
227  }
228  if ( !field.GetData().IsInt() ) {
229  continue;
230  }
231  depth = field.GetData().GetInt();
232  return true;
233  }
234  }
235  }
236  ++desc_it;
237  }
238  }
239  return false;
240 }
241 
CBioseq_Handle –.
static bool IsRefSeq(const objects::CBioseq_Handle &handle)
static bool GetFeatFetchDepth(const objects::CBioseq_Handle &handle, objects::CScope &scope, int &depth)
static bool IsChromosome(const objects::CBioseq_Handle &handle, objects::CScope &scope)
static bool IsMitochondrion(const objects::CBioseq_Handle &handle)
static bool IsmRNA(const objects::CBioseq_Handle &handle, objects::CScope &scope)
static bool IsSegSet(const objects::CBioseq_Handle &handle, objects::CScope &scope)
static bool IsPlastid(const objects::CBioseq_Handle &handle)
CScope –.
Definition: scope.hpp:92
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
static unsigned char depth[2 *(256+1+29)+1]
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
static EAccessionInfo IdentifyAccession(const CTempString &accession, TParseFlags flags=fParse_AnyRaw)
Deduces information from a bare accession a la WHICH_db_accession; may report false negatives on prop...
Definition: Seq_id.cpp:1634
CConstRef< CSeq_id > GetSeqId(void) const
EAccessionInfo
For IdentifyAccession (below)
Definition: Seq_id.hpp:220
@ eAcc_refseq_contig
Definition: Seq_id.hpp:420
@ eAcc_refseq_mrna_predicted
Definition: Seq_id.hpp:439
@ eAcc_chromosome
Definition: Seq_id.hpp:292
@ eAcc_refseq_unreserved
Definition: Seq_id.hpp:418
@ eAcc_refseq_mrna
Definition: Seq_id.hpp:415
@ eAcc_gpipe_mrna
Definition: Seq_id.hpp:551
@ eAcc_refseq_prot
Definition: Seq_id.hpp:414
@ eAcc_refseq_wgs_nuc
Definition: Seq_id.hpp:421
@ eAcc_refseq_wgs_prot
Definition: Seq_id.hpp:422
@ eAcc_refseq_ncrna
Definition: Seq_id.hpp:416
@ eAcc_refseq_chromosome
Definition: Seq_id.hpp:429
@ eAcc_refseq_genomic
Definition: Seq_id.hpp:430
@ eAcc_refseq_prot_predicted
Definition: Seq_id.hpp:438
@ eAcc_est
Definition: Seq_id.hpp:265
@ eAcc_refseq_ncrna_predicted
Definition: Seq_id.hpp:440
@ eAcc_division_mask
Definition: Seq_id.hpp:299
@ eAcc_refseq_wgs_intermed
Definition: Seq_id.hpp:431
@ eAcc_refseq_genome
Definition: Seq_id.hpp:419
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
const CMolInfo * GetMolInfo(const CBioseq &bioseq)
Retrieve the MolInfo object for a given bioseq handle.
Definition: sequence.cpp:284
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
const CSeq_id_Handle & GetSeq_id_Handle(void) const
Get handle of id used to obtain this bioseq handle.
CConstRef< CSeq_id > GetSeqId(void) const
Get id which can be used to access this bioseq handle Throws an exception if none is available.
bool IsSetInst_Repr(void) const
TInst_Repr GetInst_Repr(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TGenome GetGenome(void) const
Get the Genome member data.
Definition: BioSource_.hpp:422
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
const TData & GetData(void) const
Get the Data member data.
bool IsInt(void) const
Check if variant Int is selected.
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
TInt GetInt(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
const TLabel & GetLabel(void) const
Get the Label member data.
const TType & GetType(void) const
Get the Type member data.
vector< CRef< CUser_field > > TData
const TUser & GetUser(void) const
Get the variant data.
Definition: Seqdesc_.cpp:384
const TSource & GetSource(void) const
Get the variant data.
Definition: Seqdesc_.cpp:566
bool IsUser(void) const
Check if variant User is selected.
Definition: Seqdesc_.hpp:1122
@ eRepr_seg
segmented sequence
Definition: Seq_inst_.hpp:95
@ eBiomol_pre_RNA
precursor RNA of any sort really
Definition: MolInfo_.hpp:102
@ eBiomol_cRNA
viral RNA genome copy intermediate
Definition: MolInfo_.hpp:111
@ eBiomol_snoRNA
small nucleolar RNA
Definition: MolInfo_.hpp:112
@ e_User
user defined object
Definition: Seqdesc_.hpp:124
@ e_Source
source of materials, includes Org-ref
Definition: Seqdesc_.hpp:133
static MDB_envinfo info
Definition: mdb_load.c:37
USING_SCOPE(objects)
Modified on Wed Sep 04 15:02:34 2024 by modify_doxy.py rev. 669887