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

Go to the SVN repository for this file.

1 /* $Id: seqlocinfo.cpp 62982 2014-05-21 14:12:49Z fongah2 $
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: Christiam Camacho, Vahram Avagyan
27 *
28 */
29 
30 #include <ncbi_pch.hpp>
31 
34 
35 
38 
40 {
41  objects::ENa_strand retval;
42  switch (GetFrame()) {
43  case eFramePlus1:
44  case eFramePlus2:
45  case eFramePlus3:
46  retval = objects::eNa_strand_plus;
47  break;
48  case eFrameMinus1:
49  case eFrameMinus2:
50  case eFrameMinus3:
52  break;
53  case eFrameNotSet:
55  break;
56  default:
57  abort();
58  }
59  return retval;
60 }
61 
62 bool CSeqLocInfo::operator==(const CSeqLocInfo& rhs) const
63 {
64  if (this != &rhs) {
65  if (GetFrame() != rhs.GetFrame()) {
66  return false;
67  }
68 
69  if ( !GetSeqId().Match(rhs.GetSeqId()) ) {
70  return false;
71  }
72 
73  TSeqRange me = (TSeqRange)*this;
74  TSeqRange you = (TSeqRange) rhs;
75  if (me != you) {
76  return false;
77  }
78  }
79  return true;
80 }
81 
82 void CSeqLocInfo::SetFrame(int frame)
83 {
84  if (frame < -3 || frame > 3) {
85  string msg =
86  "CSeqLocInfo::SetFrame: input " + NStr::IntToString(frame) +
87  " out of range";
88  throw std::out_of_range(msg);
89  }
90  m_Frame = (ETranslationFrame) frame;
91 }
92 
93 //
94 // TMaskedQueryRegions
95 //
96 
98 TMaskedQueryRegions::RestrictToSeqInt(const objects::CSeq_interval& location) const
99 {
100  TMaskedQueryRegions retval;
101 
102  TSeqRange loc(location.GetFrom(), 0);
103  loc.SetToOpen(location.GetTo());
104 
105  ITERATE(TMaskedQueryRegions, maskinfo, *this) {
106  const CSeq_interval& intv = (*maskinfo)->GetInterval();
107  TSeqRange mask (intv.GetFrom(), intv.GetTo());
109  if (range.NotEmpty()) {
110  const ENa_strand kStrand = intv.CanGetStrand()
111  ? intv.GetStrand() : eNa_strand_unknown;
113  (new CSeq_interval(const_cast<CSeq_id&>(intv.GetId()),
114  range.GetFrom(),
115  range.GetToOpen(),
116  kStrand));
118  (*maskinfo)->GetFrame()));
119  retval.push_back(sli);
120  }
121  }
122 
123  return retval;
124 }
125 
128 {
130 
131  ITERATE(TMaskedQueryRegions, mask, *this) {
132  // this is done because the CSeqLocInfo doesn't guarantee that the
133  // strand and the frame are consistent, so we don't call
134  // CPacked_seqint::AddInterval(const CSeq_interval& itv);
135  retval->AddInterval((*mask)->GetSeqId(),
136  (*mask)->GetInterval().GetFrom(),
137  (*mask)->GetInterval().GetTo(),
138  (*mask)->GetStrand());
139  }
140  if (retval->CanGet() && !retval->Get().empty()) {
141  return retval;
142  }
143  retval.Reset();
144  return retval;
145 }
146 
147 bool
149 {
150  ITERATE(TMaskedQueryRegions, mask, *this) {
151  if ((*mask)->GetStrand() == eNa_strand_minus) {
152  return true;
153  }
154  }
155  return false;
156 }
157 
ncbi::TMaskedQueryRegions mask
structure for seqloc info
Definition: seqlocinfo.hpp:48
const objects::CSeq_id & GetSeqId() const
Definition: seqlocinfo.hpp:71
void SetFrame(int frame)
Definition: seqlocinfo.cpp:82
ETranslationFrame m_Frame
Definition: seqlocinfo.hpp:106
objects::ENa_strand GetStrand() const
Convert the frame to a strand.
Definition: seqlocinfo.cpp:39
bool operator==(const CSeqLocInfo &rhs) const
Definition: seqlocinfo.cpp:62
int GetFrame() const
Definition: seqlocinfo.hpp:79
Collection of masked regions for a single query sequence.
Definition: seqlocinfo.hpp:113
CRef< objects::CPacked_seqint > ConvertToCPacked_seqint() const
Converts this object to a CPacked_seqint (this is the convention used to encode masking locations in ...
Definition: seqlocinfo.cpp:127
bool HasNegativeStrandMasks() const
Returns true if there are masks on the negative strand.
Definition: seqlocinfo.cpp:148
TMaskedQueryRegions RestrictToSeqInt(const objects::CSeq_interval &location) const
Return a new instance of this object that is restricted to the location specified.
Definition: seqlocinfo.cpp:98
static const char location[]
Definition: config.c:97
static const char si[8][64]
Definition: des.c:146
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TThisType & SetToOpen(position_type toOpen)
Definition: range.hpp:175
TThisType IntersectionWith(const TThisType &r) const
Definition: range.hpp:312
CRange< TSeqPos > TSeqRange
typedefs for sequence ranges
Definition: range.hpp:419
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
ENa_strand
strand of nucleic acid
Definition: Na_strand_.hpp:64
bool CanGetStrand(void) const
Check if it is safe to call GetStrand method.
const TId & GetId(void) const
Get the Id member data.
TFrom GetFrom(void) const
Get the From member data.
TStrand GetStrand(void) const
Get the Strand member data.
TTo GetTo(void) const
Get the To member data.
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
@ eNa_strand_unknown
Definition: Na_strand_.hpp:65
const string kStrand
range(_Ty, _Ty) -> range< _Ty >
void abort()
USING_SCOPE(objects)
Modified on Wed Feb 28 07:15:00 2024 by modify_doxy.py rev. 669887