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

Go to the SVN repository for this file.

1 /* $Id: asn_cache_util.cpp 72616 2016-05-18 15:58:33Z gouriano $
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: Mike DiCuccio Cheinan Marks
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <string>
35 #include <fstream>
36 
39 
42 
45 
46 
47 void GetNormalizedSeqId(const CSeq_id& id,
48  string& id_str, Uint4& version)
49 {
50  id.GetLabel(&id_str, CSeq_id::eType);
51  id_str += '|';
52  if (id.IsGeneral()) {
53  id_str += id.GetGeneral().GetDb();
54  id_str += "|";
55  }
56  id.GetLabel(&id_str,
59 
60  NStr::ToLower(id_str);
61 
62  version = 0;
63  const CTextseq_id* text_id = id.GetTextseq_Id();
64  if (text_id && text_id->IsSetVersion()) {
65  version = text_id->GetVersion();
66  }
67 }
68 
69 
70 
71 void GetNormalizedSeqId(const objects::CSeq_id_Handle& id,
72  string& id_str, Uint4& version)
73 {
74  GetNormalizedSeqId(*id.GetSeqId(), id_str, version);
75 }
76 
77 
78 
79 void ReadThroughFile( const std::string & file_path )
80 {
81  /// Read through a file and throw away the data. This optimizes
82  /// random access performance when using panfs.
83  CNcbiIfstream dump_index_stream( file_path.c_str(), std::ios::binary );
84  const size_t kBufferSize = 64 * 1024 * 1024;
85  std::vector<char> buffer( kBufferSize );
86  while ( dump_index_stream ) {
87  dump_index_stream.read( &buffer[0], kBufferSize );
88  }
89 }
90 
91 ///
92 /// Extract bioseq with given id from entry
93 ///
95  const CSeq_id_Handle & id)
96 {
97  CConstRef<CBioseq> bioseq;
98  if (entry) {
99  if(entry->IsSet()){
101  if((bioseq = ExtractBioseq(*it, id)).NotNull())
102  break;
103  } else {
104  ITERATE(CBioseq::TId, it, entry->GetSeq().GetId())
105  if(id.GetSeqId()->Match(**it)){
106  bioseq = &entry->GetSeq();
107  break;
108  }
109  }
110  }
111  return bioseq;
112 }
113 
114 
115 
116 
117 
119 
USING_SCOPE(objects)
void ReadThroughFile(const std::string &file_path)
void GetNormalizedSeqId(const CSeq_id &id, string &id_str, Uint4 &version)
CConstRef< CBioseq > ExtractBioseq(CConstRef< CSeq_entry > entry, const CSeq_id_Handle &id)
Extract bioseq with given id from entry.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
string
Definition: cgiapp.hpp:687
@ fLabel_GeneralDbIsContent
For type general, use the database name as the tag and the (text or numeric) key as the content.
Definition: Seq_id.hpp:618
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:605
@ eType
FASTA-style type, or database in GeneralDbIsContent mode.
Definition: Seq_id.hpp:604
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
static string & ToLower(string &str)
Convert string to lower case – string& version.
Definition: ncbistr.cpp:405
X * NotNull(X *object)
Check for not null value (after C malloc, strdup etc.).
Definition: ncbiutil.hpp:85
TVersion GetVersion(void) const
Get the Version member data.
bool IsSetVersion(void) const
Check if a value has been assigned to Version data member.
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
const TSeq_set & GetSeq_set(void) const
Get the Seq_set member data.
list< CRef< CSeq_entry > > TSeq_set
const TId & GetId(void) const
Get the Id member data.
Definition: Bioseq_.hpp:290
list< CRef< CSeq_id > > TId
Definition: Bioseq_.hpp:94
static int version
Definition: mdb_load.c:29
const SIZE_TYPE kBufferSize
Definition: page.cpp:44
static pcre_uint8 * buffer
Definition: pcretest.c:1051
static bool GetSeqId(const T &d, set< string > &labels, const string name="", bool detect=false, bool found=false)
Modified on Wed Apr 17 13:08:38 2024 by modify_doxy.py rev. 669887