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

Go to the SVN repository for this file.

1 /* $Id: blast_seqinfosrc_aux.cpp 88157 2019-11-14 14:41:14Z boratyng $
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: Vahram Avagyan
27 *
28 */
29 
30 /// @file blast_seqinfosrc_aux.cpp
31 /// Implementation of auxiliary functions using IBlastSeqInfoSrc to
32 /// retrieve ids and related sequence information.
33 
34 #include <ncbi_pch.hpp>
37 #include <serial/typeinfo.hpp>
38 #include <corelib/ncbiutil.hpp>
39 
40 #include <algorithm>
41 
42 /** @addtogroup AlgoBlast
43  *
44  * @{
45  */
46 
49 BEGIN_SCOPE(blast)
50 
51 void GetSequenceLengthAndId(const blast::IBlastSeqInfoSrc * seqinfo_src,
52  int oid,
53  CRef<CSeq_id> & seqid,
54  TSeqPos * length)
55 {
56  _ASSERT(length);
57  list<CRef<CSeq_id> > seqid_list = seqinfo_src->GetId(oid);
58 
60  if (id.NotEmpty()) {
61  seqid.Reset(new CSeq_id);
62  if (id->IsGi())
63  SerialAssign(*seqid, *id);
64  else
65  SerialAssign(*seqid, *(seqid_list.front()));
66  }
67  *length = seqinfo_src->GetLength(oid);
68 
69  return;
70 }
71 
72 void GetSequenceLengthAndId(const blast::IBlastSeqInfoSrc * seqinfo_src,
73  int oid,
74  int (*rank_func)(const CRef<CSeq_id>&),
75  CRef<CSeq_id> & seqid,
76  TSeqPos * length)
77 {
78  _ASSERT(length);
79  list<CRef<CSeq_id> > seqid_list = seqinfo_src->GetId(oid);
80 
81  CRef<CSeq_id> id = FindBestChoice(seqid_list, rank_func);
82  if (id.NotEmpty()) {
83  seqid.Reset(new CSeq_id);
84  SerialAssign(*seqid, *id);
85  }
86  *length = seqinfo_src->GetLength(oid);
87 
88  return;
89 }
90 
91 void GetFilteredRedundantGis(const IBlastSeqInfoSrc & seqinfo_src,
92  int oid,
93  vector<TGi> & gis)
94 {
95  gis.resize(0);
96 
97  if (! seqinfo_src.HasGiList()) {
98  return;
99  }
100 
101  list< CRef<CSeq_id> > seqid_list = seqinfo_src.GetId(oid);
102  gis.reserve(seqid_list.size());
103 
104  ITERATE(list< CRef<CSeq_id> >, id, seqid_list) {
105  if ((**id).IsGi()) {
106  gis.push_back((**id).GetGi());
107  }
108  }
109 
110  sort(gis.begin(), gis.end());
111 }
112 
114  int oid,
115  vector<string> & seqids,
116  bool use_gi)
117 {
118  seqids.resize(0);
119 
120  if (! seqinfo_src.HasGiList()) {
121  return;
122  }
123 
124  list< CRef<CSeq_id> > seqid_list = seqinfo_src.GetId(oid);
125 
126  ITERATE(list< CRef<CSeq_id> >, id, seqid_list) {
127  if (use_gi)
128  {
129  if ((**id).IsGi())
130  {
131  string sid_string = "gi:" + (*id)->GetSeqIdString(true);
132  seqids.push_back(sid_string);
133  }
134  }
135  else
136  {
137  const CTextseq_id* tsid = (*id)->GetTextseq_Id();
138  if (tsid && tsid->IsSetAccession())
139  {
140  string sid_string = "seqid:" + (*id)->GetSeqIdString(true);
141  seqids.push_back(sid_string);
142  }
143  else if ((*id)->IsPdb())
144  {
145  string sid_string = "seqid:" + (*id)->GetSeqIdString(true);
146  seqids.push_back(sid_string);
147  }
148  }
149  }
150 }
151 
152 END_SCOPE(blast)
154 
155 /* @} */
Declarations of auxiliary functions using IBlastSeqInfoSrc to retrieve ids and related sequence infor...
CRef –.
Definition: ncbiobj.hpp:618
Abstract base class to encapsulate retrieval of sequence identifiers.
virtual list< CRef< objects::CSeq_id > > GetId(Uint4 index) const =0
Method to retrieve a sequence identifier given its ordinal number.
void GetSequenceLengthAndId(const blast::IBlastSeqInfoSrc *seqinfo_src, int oid, CRef< CSeq_id > &seqid, TSeqPos *length)
void GetFilteredRedundantSeqids(const IBlastSeqInfoSrc &sisrc, int oid, vector< string > &seqids, bool use_gis=true)
Get Seqids for a sequence in a redundant database.
void GetFilteredRedundantGis(const IBlastSeqInfoSrc &sisrc, int oid, vector< TGi > &gis)
Get GIs for a sequence in a redundant database.
virtual bool HasGiList() const =0
Returns true if the subject is restricted by a GI list.
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
C & SerialAssign(C &dest, const C &src, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
Definition: serialbase.hpp:482
static int BestRank(const CRef< CSeq_id > &id)
Definition: Seq_id.hpp:774
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#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
C::value_type FindBestChoice(const C &container, F score_func)
Find the best choice (lowest score) for values in a container.
Definition: ncbiutil.hpp:250
bool IsSetAccession(void) const
Check if a value has been assigned to Accession data member.
bool IsGi(void) const
Check if variant Gi is selected.
Definition: Seq_id_.hpp:883
constexpr auto sort(_Init &&init)
Useful/utility classes and methods.
#define _ASSERT
#define const
Definition: zconf.h:232
Modified on Wed Sep 04 15:04:58 2024 by modify_doxy.py rev. 669887