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

Go to the SVN repository for this file.

1 /* ===========================================================================
2  *
3  * PUBLIC DOMAIN NOTICE
4  * National Center for Biotechnology Information
5  *
6  * This software/database is a "United States Government Work" under the
7  * terms of the United States Copyright Act. It was written as part of
8  * the author's official duties as a United States Government employee and
9  * thus cannot be copyrighted. This software/database is freely available
10  * to the public for use. The National Library of Medicine and the U.S.
11  * Government have not placed any restriction on its use or reproduction.
12  *
13  * Although all reasonable efforts have been taken to ensure the accuracy
14  * and reliability of the software and data, the NLM and the U.S.
15  * Government do not and cannot warrant the performance or results that
16  * may be obtained by using this software or data. The NLM and the U.S.
17  * Government disclaim all warranties, express or implied, including
18  * warranties of performance, merchantability or fitness for any particular
19  * purpose.
20  *
21  * Please cite the author in any work or product based on this material.
22  *
23  * ===========================================================================
24  *
25  * Author: Ilya Dondoshansky
26  *
27  */
28 
29 /** @file seqinfosrc_seqvec.cpp
30  * Implementation of the concrete strategy for an IBlastSeqInfoSrc interface to
31  * retrieve sequence identifiers and lengths from a vector of Seq-locs.
32  */
33 
34 #include <ncbi_pch.hpp>
35 #include <objmgr/util/sequence.hpp>
38 
39 /** @addtogroup AlgoBlast
40  *
41  * @{
42  */
43 
46 BEGIN_SCOPE(blast)
47 
49  : m_SeqVec(seqv)
50 {
51  if (seqv.size() == 0) {
52  NCBI_THROW(CBlastException, eInvalidArgument,
53  "Empty sequence vector for id and length retrieval");
54  }
55 }
56 
58 {
59 }
60 
61 list< CRef<CSeq_id> > CSeqVecSeqInfoSrc::GetId(Uint4 index) const
62 {
63  if (index >= m_SeqVec.size()) {
64  NCBI_THROW(CBlastException, eInvalidArgument,
65  "Index out of range for id retrieval");
66  }
67 
68  list < CRef<CSeq_id> > seqid_list;
69  CRef<CSeq_id> seqid_ref;
70 
71  seqid_ref.Reset(const_cast<CSeq_id*>(
72  &sequence::GetId(*m_SeqVec[index].seqloc,
73  m_SeqVec[index].scope)));
74 
75  seqid_list.push_back(seqid_ref);
76  return seqid_list;
77 }
78 
80 {
81  if (index >= m_SeqVec.size()) {
82  NCBI_THROW(CBlastException, eInvalidArgument,
83  "Index out of range for Seq-loc retrieval");
84  }
85  return m_SeqVec[index].seqloc;
86 }
87 
89 {
90  if (index >= m_SeqVec.size()) {
91  NCBI_THROW(CBlastException, eInvalidArgument,
92  "Index out of range for length retrieval");
93  }
94 
95  return sequence::GetLength(*m_SeqVec[index].seqloc,
96  m_SeqVec[index].scope);
97 }
98 
100 {
101  return m_SeqVec.size();
102 }
103 
105 {
106  return false;
107 }
108 
109 static void
111  const vector <TSeqRange>& target_ranges,
112  const CSeqLocInfo::ETranslationFrame frame,
113  TMaskedSubjRegions& retval)
114 {
115  TSeqRange loc(interval->GetFrom(), interval->GetTo());
116 
117  for (size_t ir=0; ir< target_ranges.size(); ir++) {
118  if (target_ranges[ir] != TSeqRange::GetEmpty() &&
119  loc.IntersectingWith(target_ranges[ir])) {
120  CRef<CSeqLocInfo> sli(new CSeqLocInfo(interval, frame));
121  retval.push_back(sli);
122  return;
123  }
124  }
125 }
126 
128  const TSeqRange& target_range,
129  TMaskedSubjRegions& retval) const
130 {
131  if (target_range == TSeqRange::GetEmpty()) {
132  return false;
133  }
134  vector<TSeqRange> ranges;
135  ranges.push_back(target_range);
136  return GetMasks(index, ranges, retval);
137 }
138 
140  const vector<TSeqRange>& target_ranges,
141  TMaskedSubjRegions& retval) const
142 {
144 
145  CRef<CSeq_loc> mask = m_SeqVec[index].mask;
146  if (mask.Empty() || target_ranges.empty()) {
147  return false;
148  }
149 
150  if (mask->IsInt()) {
152  target_ranges, kFrame, retval);
153  } else if (mask->IsPacked_int()) {
154  ITERATE(CPacked_seqint::Tdata, itr, mask->GetPacked_int().Get()) {
155  s_SeqIntervalToSeqLocInfo(*itr, target_ranges, kFrame, retval);
156  }
157  } else {
158  NCBI_THROW(CBlastException, eInvalidArgument,
159  "Type of mask not supported");
160  }
161 
162  return (retval.empty() ? false : true);
163 }
164 
165 END_SCOPE(blast)
167 
168 /* @} */
Declares the BLAST exception class.
ncbi::TMaskedQueryRegions mask
Defines BLAST error codes (user errors included)
structure for seqloc info
Definition: seqlocinfo.hpp:48
Implementation of the IBlastSeqInfoSrc interface to encapsulate retrieval of sequence identifiers and...
Collection of masked regions for a single query sequence.
Definition: seqlocinfo.hpp:113
TSeqLocVector m_SeqVec
Vector of subject sequence locations to get information from.
virtual bool GetMasks(Uint4 index, const TSeqRange &target_range, TMaskedSubjRegions &retval) const
Retrieves the subject masks for the corresponding index.
virtual Uint4 GetLength(Uint4 index) const
Retrieve sequence length given its index in the vector.
static void s_SeqIntervalToSeqLocInfo(CRef< CSeq_interval > interval, const vector< TSeqRange > &target_ranges, const CSeqLocInfo::ETranslationFrame frame, TMaskedSubjRegions &retval)
virtual size_t Size() const
Returns the size of the underlying container of sequences.
virtual ~CSeqVecSeqInfoSrc()
Destructor.
virtual list< CRef< objects::CSeq_id > > GetId(Uint4 index) const
Retrieve a sequence identifier given its index in the vector.
virtual bool HasGiList() const
Is the subject restricted by a GI list? (Always returns false).
virtual CConstRef< objects::CSeq_loc > GetSeqLoc(Uint4 index) const
Method to retrieve the sequence location given its ordinal number.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
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,...
TSeqPos GetLength(const CSeq_id &id, CScope *scope)
Get sequence length if scope not null, else return max possible TSeqPos.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
bool IntersectingWith(const TThisType &r) const
Definition: range.hpp:331
static TThisType GetEmpty(void)
Definition: range.hpp:306
#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
list< CRef< CSeq_interval > > Tdata
TFrom GetFrom(void) const
Get the From member data.
TTo GetTo(void) const
Get the To member data.
Defines a concrete strategy for the IBlastSeqInfoSrc interface for sequence identifiers retrieval fro...
vector< SSeqLoc > TSeqLocVector
Vector of sequence locations.
Definition: sseqloc.hpp:129
#define const
Definition: zconf.h:232
Modified on Fri Sep 20 14:57:13 2024 by modify_doxy.py rev. 669887