1 #ifndef SRA__READER__SRA__SRAREAD__HPP 2 #define SRA__READER__SRA__SRAREAD__HPP 3 /* $Id: sraread.hpp 519877 2016-11-18 20:51:27Z vasilche $ 4 * =========================================================================== 5 * 6 * PUBLIC DOMAIN NOTICE 7 * National Center for Biotechnology Information 8 * 9 * This software/database is a "United States Government Work" under the 10 * terms of the United States Copyright Act. It was written as part of 11 * the author's official duties as a United States Government employee and 12 * thus cannot be copyrighted. This software/database is freely available 13 * to the public for use. The National Library of Medicine and the U.S. 14 * Government have not placed any restriction on its use or reproduction. 15 * 16 * Although all reasonable efforts have been taken to ensure the accuracy 17 * and reliability of the software and data, the NLM and the U.S. 18 * Government do not and cannot warrant the performance or results that 19 * may be obtained by using this software or data. The NLM and the U.S. 20 * Government disclaim all warranties, express or implied, including 21 * warranties of performance, merchantability or fitness for any particular 22 * purpose. 23 * 24 * Please cite the author in any work or product based on this material. 25 * 26 * =========================================================================== 27 * 28 * Authors: Eugene Vasilchenko 29 * 30 * File Description: 31 * Access to SRA files 32 * 33 */ 34 35 #include <corelib/ncbistd.hpp> 36 #include <sra/readers/sra/exception.hpp> 37 #include <sra/readers/sra/sdk.hpp> 38 39 #include <objects/seqset/Seq_entry.hpp> 40 #include <objects/seq/Seq_inst.hpp> 41 42 //#include <sra/sradb.h> // for spotid_t, bitsz_t 43 typedef int64_t spotid_t; 44 typedef uint64_t bitsz_t; 45 46 // SRA SDK structures 47 struct SRAMgr; 48 struct SRAPath; 49 struct SRATable; 50 struct SRAColumn; 51 52 BEGIN_NCBI_SCOPE 53 BEGIN_SCOPE(objects) 54 55 class CSeq_entry; 56 57 58 template<> 59 struct CSraRefTraits<SRAPath> 60 { x_ReleaseCSraRefTraits61 static rc_t x_Release(const SRAPath* t) { return 0; } x_AddRefCSraRefTraits62 static rc_t x_AddRef (const SRAPath* t) { return 0; } 63 }; 64 65 DECLARE_SRA_REF_TRAITS(SRAMgr, const); 66 DECLARE_SRA_REF_TRAITS(SRAColumn, const); 67 DECLARE_SRA_REF_TRAITS(SRATable, const); 68 69 class CSraPath; 70 class CSraMgr; 71 class CSraRun; 72 class CSraColumn; 73 74 class NCBI_SRAREAD_EXPORT CSraPath 75 : public CSraRef<SRAPath> 76 { 77 public: CSraPath(ENull)78 explicit CSraPath(ENull /*null*/) 79 { 80 } 81 CSraPath(void); 82 NCBI_DEPRECATED_CTOR(CSraPath(const string& rep_path, 83 const string& vol_path)); 84 85 NCBI_DEPRECATED 86 static string GetDefaultRepPath(void); 87 NCBI_DEPRECATED 88 static string GetDefaultVolPath(void); 89 90 NCBI_DEPRECATED 91 void AddRepPath(const string& rep_path); 92 93 NCBI_DEPRECATED 94 void AddVolPath(const string& vol_path); 95 96 string FindAccPath(const string& acc) const; 97 }; 98 99 class NCBI_SRAREAD_EXPORT CSraMgr 100 : public CSraRef<const SRAMgr> 101 { 102 public: 103 enum ETrim { 104 eNoTrim, 105 eTrim 106 }; 107 108 CSraMgr(ETrim trim = eNoTrim); 109 110 NCBI_DEPRECATED 111 CSraMgr(const string& rep_path, const string& vol_path, 112 ETrim trim = eNoTrim); 113 114 spotid_t GetSpotInfo(const string& sra, CSraRun& run); 115 116 CRef<CSeq_entry> GetSpotEntry(const string& sra); 117 CRef<CSeq_entry> GetSpotEntry(const string& sra, CSraRun& run); 118 119 CSraPath& GetPath(void) const; 120 string FindAccPath(const string& acc) const; 121 GetTrim(void) const122 bool GetTrim(void) const 123 { 124 return m_Trim; 125 } 126 127 NCBI_DEPRECATED 128 static void RegisterFunctions(void); 129 130 protected: 131 void x_Init(void); 132 133 private: 134 mutable CSraPath m_Path; 135 bool m_Trim; 136 }; 137 138 class NCBI_SRAREAD_EXPORT CSraColumn 139 : public CSraRef<const SRAColumn> 140 { 141 public: CSraColumn(void)142 CSraColumn(void) 143 { 144 } CSraColumn(const CSraRun & run,const char * name,const char * type)145 CSraColumn(const CSraRun& run, const char* name, const char* type) 146 { 147 Init(run, name, type); 148 } 149 150 rc_t TryInitRc(const CSraRun& run, const char* name, const char* type); 151 void Init(const CSraRun& run, const char* name, const char* type); 152 }; 153 154 155 class NCBI_SRAREAD_EXPORT CSraRun 156 : public CSraRef<const SRATable> 157 { 158 public: CSraRun(void)159 CSraRun(void) 160 { 161 } CSraRun(CSraMgr & mgr,const string & acc)162 CSraRun(CSraMgr& mgr, const string& acc) 163 { 164 Init(mgr, acc); 165 } 166 167 void Init(CSraMgr& mgr, const string& acc); 168 GetAccession(void) const169 const string& GetAccession(void) const 170 { 171 return m_Acc; 172 } 173 174 CSeq_inst::TMol GetSequenceType(spotid_t spot_id, uint8_t read_id) const; 175 TSeqPos GetSequenceLength(spotid_t spot_id, uint8_t read_id) const; 176 CRef<CSeq_entry> GetSpotEntry(spotid_t spot_id) const; 177 178 protected: 179 void x_DoInit(CSraMgr& mgr, const string& acc); 180 181 private: 182 string m_Acc; 183 bool m_Trim; 184 CSraColumn m_Name; 185 CSraColumn m_Read; 186 CSraColumn m_Qual; 187 CSraColumn m_SDesc; 188 CSraColumn m_RDesc; 189 CSraColumn m_TrimStart; 190 }; 191 192 193 class NCBI_SRAREAD_EXPORT CSraValue 194 { 195 public: 196 enum ECheckRc { 197 eCheckRc, 198 eNoCheckRc 199 }; 200 CSraValue(const CSraColumn& col, spotid_t id, 201 ECheckRc check_rc = eCheckRc); 202 GetLength(void) const203 size_t GetLength(void) const 204 { 205 return m_Len; 206 } 207 GetRC(void) const208 rc_t GetRC(void) const 209 { 210 return m_Error; 211 } 212 213 DECLARE_OPERATOR_BOOL(!m_Error); 214 215 protected: 216 rc_t m_Error; 217 const void* m_Data; 218 bitsz_t m_Bitoffset; 219 bitsz_t m_Bitlen; 220 size_t m_Len; 221 }; 222 223 224 class CSraStringValue : public CSraValue 225 { 226 public: CSraStringValue(const CSraColumn & col,spotid_t id,ECheckRc check_rc=eCheckRc)227 CSraStringValue(const CSraColumn& col, spotid_t id, 228 ECheckRc check_rc = eCheckRc) 229 : CSraValue(col, id, check_rc) 230 { 231 } data(void) const232 const char* data(void) const 233 { 234 return static_cast<const char*>(m_Data); 235 } size(void) const236 size_t size(void) const 237 { 238 return GetLength(); 239 } operator string(void) const240 operator string(void) const 241 { 242 return string(data(), size()); 243 } Value(void) const244 string Value(void) const 245 { 246 return *this; 247 } 248 }; 249 250 template<class V> 251 class CSraValueFor : public CSraValue 252 { 253 public: 254 typedef V TValue; CSraValueFor(const CSraColumn & col,spotid_t id,CSraValue::ECheckRc check_rc=CSraValue::eCheckRc)255 CSraValueFor(const CSraColumn& col, spotid_t id, 256 CSraValue::ECheckRc check_rc = CSraValue::eCheckRc) 257 : CSraValue(col, id, check_rc) 258 { 259 } Value(void) const260 const TValue& Value(void) const 261 { 262 return *static_cast<const TValue*>(m_Data); 263 } operator ->(void) const264 const TValue* operator->(void) const 265 { 266 return &Value(); 267 } operator [](size_t i) const268 const TValue& operator[](size_t i) const 269 { 270 return static_cast<const TValue*>(m_Data)[i]; 271 } 272 }; 273 274 typedef CSraValueFor<uint16_t> CSraUInt16Value; 275 typedef CSraValueFor<char> CSraBytesValue; 276 277 278 END_SCOPE(objects) 279 END_NCBI_SCOPE 280 281 #endif // SRA__READER__SRA__SRAREAD__HPP 282