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

Go to the SVN repository for this file.

1 /* $Id: macro_fn_seq_constr.cpp 46800 2021-10-18 18:02:34Z asztalos $
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: Andrea Asztalos
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 #include <objmgr/bioseq_ci.hpp>
34 /** @addtogroup GUI_MACRO_SCRIPTS_UTIL
35  *
36  * @{
37  */
38 
40 BEGIN_SCOPE(macro)
42 
43 
44 //////////////////////////////////////////////////////////////////////////////
45 /// class CMacroFunction_FeatStrandednessConstraint
46 /// Checks for the strandedness of all features
47 /// ISSTRAND_OF_FEATURES(strandedness) - accepts one parameter, a string corresponding to Feature-strandedness-constraint, except "any"
48 ///
51 {
52  EFeature_strandedness_constraint strandedness = x_GetStrandednessFromName(m_Args[0]->GetString());
53 
54  // make sure that the iterator is a sequence iterator
55  CObjectInfo oi = m_DataIter->GetEditedObject();
57  CRef<CScope> scope = m_DataIter->GetScopedObject().scope;
58  if (!bseq || !scope)
59  return;
60 
61  bool match = x_Match(scope->GetBioseqHandle(*bseq), strandedness);
62  m_Result->SetDataType(CMQueryNodeValue::eBool);
63  m_Result->SetBool(match);
64 }
65 
68 {
70  if (NStr::EqualNocase(strand_name, "minus-only")) {
72  } else if (NStr::EqualNocase(strand_name, "plus-only")) {
74  } else if (NStr::EqualNocase(strand_name, "at-least-one-minus")) {
76  } else if (NStr::EqualNocase(strand_name, "at-least-one-plus")) {
78  } else if (NStr::EqualNocase(strand_name, "no-minus")) {
80  } else if (NStr::EqualNocase(strand_name, "no-plus")) {
82  }
83  return strand;
84 }
85 
87 {
88  if (strandedness == eFeature_strandedness_constraint_any)
89  return false; // different
90 
91  unsigned num_minus = 0, num_plus = 0;
93  for ( ; feat; ++feat) {
94  if (feat->GetLocation().GetStrand() == eNa_strand_minus) {
95  num_minus++;
97  || strandedness == eFeature_strandedness_constraint_no_minus) {
98  return false;
99  } else if (strandedness == eFeature_strandedness_constraint_at_least_one_minus) {
100  return true;
101  }
102  } else {
103  num_plus++;
105  || strandedness == eFeature_strandedness_constraint_no_plus) {
106  return false;
107  } else if (strandedness == eFeature_strandedness_constraint_at_least_one_plus) {
108  return true;
109  }
110  }
111  }
112 
113  switch (strandedness) {
115  if (num_minus > 0 && num_plus == 0) return true;
117  if (num_plus > 0 && num_minus == 0) return true;
119  if (num_minus > 0) return true;
121  if (num_plus > 0) return true;
123  if (num_minus == 0) return true;
125  if (num_plus == 0) return true;
126  default: return false;
127  }
128  return false;
129 }
130 
132 {
133  return (m_Args.size() == 1
134  && m_Args[0]->GetDataType() == CMQueryNodeValue::eString
135  && !m_Args[0]->GetString().empty());
136 }
137 
138 
139 //////////////////////////////////////////////////////////////////////////////
140 /// class CMacroFunction_NumberOfFeatures
141 /// FEATS_ON_SEQ(feature_type | "all") - returns the number of features of type "feature_type" present on the sequence
142 /// When the argument is "any" or "all", it returns the total number of features (all kind)
143 ///
146 {
147  CConstRef<CObject> obj = m_DataIter->GetScopedObject().object;
148  CRef<CScope> scope = m_DataIter->GetScopedObject().scope;
149  if (!obj || !scope)
150  return;
151 
152  CBioseq_Handle bsh = m_DataIter->GetBioseqHandle();
153  _ASSERT(bsh);
154  if (bsh) {
155  int count = s_GetFeatTypeCount(bsh, m_Args[0]->GetString());
156  m_Result->SetInt(count);
157  }
158 }
159 
161 {
162  // count all features on the sequence
163  int count = 0;
165  if (subtype != CSeqFeatData::eSubtype_bad) {
167  for (CFeat_CI it(bsh, SAnnotSelector(subtype)); it; ++it) {
168  count++;
169  }
170  }
171  else {
172  CScope& scope = bsh.GetScope();
173  for (CFeat_CI feat_it(bsh, SAnnotSelector(CSeqFeatData::e_Cdregion)); feat_it; ++feat_it) {
174  if (feat_it->IsSetProduct()) {
175  CBioseq_Handle product = scope.GetBioseqHandle(feat_it->GetProduct());
176  for (CFeat_CI prot_it(product, SAnnotSelector(subtype)); prot_it; ++prot_it) {
177  count++;
178  }
179  }
180  }
181  }
182  }
183 
184  return count;
185 }
186 
188 {
189  return (m_Args.size() == 1 && m_Args[0]->GetDataType() == CMQueryNodeValue::eString);
190 }
191 
192 END_SCOPE(macro)
194 
195 /* @} */
CBioseq_Handle –.
CFeat_CI –.
Definition: feat_ci.hpp:64
CObjectInfo –.
Definition: objectinfo.hpp:597
CScope –.
Definition: scope.hpp:92
static E_Choice GetTypeFromSubtype(ESubtype subtype)
@ eSubtype_bad
These no longer need to match the FEATDEF values in the C toolkit's objfdef.h.
objects::CSeqFeatData::ESubtype GetFeatSubtype(const string &feat_type)
Definition: macro_util.cpp:350
objects::EFeature_strandedness_constraint x_GetStrandednessFromName(const string &strand_name)
static int s_GetFeatTypeCount(const objects::CBioseq_Handle &bsh, const string &feat_type)
returns the number of features of type feat_type present on the bioseq
virtual void TheFunction()
Function implementation.
CRef< CMQueryNodeValue > m_Result
void SetInt(Int8 data)
Definition: macro_exec.hpp:128
bool x_Match(const objects::CBioseq_Handle &bsh, objects::EFeature_strandedness_constraint strandedness)
CIRef< IMacroBioDataIter > m_DataIter
virtual bool x_ValidArguments() const
Tests the number and the type of function arguments.
DEFINE_MACRO_FUNCNAME(CMacroFunction_NumberOfFeatures, "FEATS_ON_SEQ")
class CMacroFunction_NumberOfFeatures FEATS_ON_SEQ(feature_type | "all") - returns the number of feat...
virtual bool x_ValidArguments() const
Tests the number and the type of function arguments.
static const TObjectType * SafeCast(TTypeInfo type)
Definition: serialutil.hpp:76
ENa_strand GetStrand(void) const
Get the location's strand.
Definition: Seq_loc.cpp:882
TObjectPtr GetObjectPtr(void) const
Get pointer to object.
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
CScope & GetScope(void) const
Get scope this handle belongs to.
const CSeq_loc & GetLocation(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define USING_SCOPE(ns)
Use the specified namespace.
Definition: ncbistl.hpp:78
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
EFeature_strandedness_constraint
Access to EFeature_strandedness_constraint's attributes (values, names) as defined in spec.
@ eFeature_strandedness_constraint_no_plus
@ eFeature_strandedness_constraint_at_least_one_minus
@ eFeature_strandedness_constraint_at_least_one_plus
@ eFeature_strandedness_constraint_minus_only
@ eFeature_strandedness_constraint_any
@ eFeature_strandedness_constraint_no_minus
@ eFeature_strandedness_constraint_plus_only
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)
Definition: pcre_exec.c:513
SAnnotSelector –.
#define _ASSERT
Modified on Wed Mar 27 11:22:01 2024 by modify_doxy.py rev. 669887