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 */ 26 27 #include <ngs/itf/ReadCollectionItf.hpp> 28 29 #include <ngs/itf/StringItf.hpp> 30 #include <ngs/itf/ReadItf.hpp> 31 #include <ngs/itf/ReadGroupItf.hpp> 32 #include <ngs/itf/ReferenceItf.hpp> 33 #include <ngs/itf/AlignmentItf.hpp> 34 #include <ngs/itf/StatisticsItf.hpp> 35 36 #include <ngs/itf/ErrBlock.hpp> 37 #include <ngs/itf/VTable.hpp> 38 39 #include <ngs/itf/ReadCollectionItf.h> 40 41 #include <ngs/Alignment.hpp> 42 #include <ngs/Read.hpp> 43 44 namespace ngs 45 { 46 /*---------------------------------------------------------------------- 47 * metadata 48 */ 49 extern ItfTok NGS_Refcount_v1_tok; 50 ItfTok NGS_ReadCollection_v1_tok ( "NGS_ReadCollection_v1", NGS_Refcount_v1_tok ); 51 52 /*---------------------------------------------------------------------- 53 * access vtable 54 */ 55 static inline Access(const NGS_VTable * vt)56 const NGS_ReadCollection_v1_vt * Access ( const NGS_VTable * vt ) 57 { 58 const NGS_ReadCollection_v1_vt * out = static_cast < const NGS_ReadCollection_v1_vt* > 59 ( Cast ( vt, NGS_ReadCollection_v1_tok ) ); 60 if ( out == 0 ) 61 throw ErrorMsg ( "object is not of type NGS_ReadCollection_v1" ); 62 return out; 63 } 64 65 /*---------------------------------------------------------------------- 66 * ReadCollectionItf 67 */ 68 getName() const69 StringItf * ReadCollectionItf :: getName () const 70 NGS_THROWS ( ErrorMsg ) 71 { 72 // the object is really from C 73 const NGS_ReadCollection_v1 * self = Test (); 74 75 // cast vtable to our level 76 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 77 78 // call through C vtable 79 ErrBlock err; 80 assert ( vt -> get_name != 0 ); 81 NGS_String_v1 * ret = ( * vt -> get_name ) ( self, & err ); 82 83 // check for errors 84 err . Check (); 85 86 return StringItf :: Cast ( ret ); 87 } 88 getReadGroups() const89 ReadGroupItf * ReadCollectionItf :: getReadGroups () const 90 NGS_THROWS ( ErrorMsg ) 91 { 92 // the object is really from C 93 const NGS_ReadCollection_v1 * self = Test (); 94 95 // cast vtable to our level 96 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 97 98 // call through C vtable 99 ErrBlock err; 100 assert ( vt -> get_read_groups != 0 ); 101 NGS_ReadGroup_v1 * ret = ( * vt -> get_read_groups ) ( self, & err ); 102 103 // check for errors 104 err . Check (); 105 106 return ReadGroupItf :: Cast ( ret ); 107 } 108 hasReadGroup(const char * spec) const109 bool ReadCollectionItf :: hasReadGroup ( const char * spec ) const 110 NGS_NOTHROW () 111 { 112 try 113 { 114 // the object is really from C 115 const NGS_ReadCollection_v1 * self = Test (); 116 117 // cast vtable to our level 118 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 119 120 // test for v1.1 121 if ( vt -> dad . minor_version < 1 ) 122 { 123 ReadGroupItf * itf = getReadGroup ( spec ); 124 if ( itf == 0 ) 125 return false; 126 127 itf -> Release (); 128 return true; 129 } 130 131 // call through C vtable 132 assert ( vt -> has_read_group != 0 ); 133 return ( * vt -> has_read_group ) ( self, spec ); 134 } 135 catch ( ... ) 136 { 137 } 138 139 return false; 140 } 141 getReadGroup(const char * spec) const142 ReadGroupItf * ReadCollectionItf :: getReadGroup ( const char * spec ) const 143 NGS_THROWS ( ErrorMsg ) 144 { 145 // the object is really from C 146 const NGS_ReadCollection_v1 * self = Test (); 147 148 // cast vtable to our level 149 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 150 151 // call through C vtable 152 ErrBlock err; 153 assert ( vt -> get_read_group != 0 ); 154 NGS_ReadGroup_v1 * ret = ( * vt -> get_read_group ) ( self, & err, spec ); 155 156 // check for errors 157 err . Check (); 158 159 return ReadGroupItf :: Cast ( ret ); 160 } 161 getReferences() const162 ReferenceItf * ReadCollectionItf :: getReferences () const 163 NGS_THROWS ( ErrorMsg ) 164 { 165 // the object is really from C 166 const NGS_ReadCollection_v1 * self = Test (); 167 168 // cast vtable to our level 169 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 170 171 // call through C vtable 172 ErrBlock err; 173 assert ( vt -> get_references != 0 ); 174 NGS_Reference_v1 * ret = ( * vt -> get_references ) ( self, & err ); 175 176 // check for errors 177 err . Check (); 178 179 return ReferenceItf :: Cast ( ret ); 180 } 181 hasReference(const char * spec) const182 bool ReadCollectionItf :: hasReference ( const char * spec ) const 183 NGS_NOTHROW () 184 { 185 try 186 { 187 // the object is really from C 188 const NGS_ReadCollection_v1 * self = Test (); 189 190 // cast vtable to our level 191 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 192 193 // test for v1.1 194 if ( vt -> dad . minor_version < 1 ) 195 { 196 ReferenceItf * itf = getReference ( spec ); 197 if ( itf == 0 ) 198 return false; 199 200 itf -> Release (); 201 return true; 202 } 203 204 // call through C vtable 205 assert ( vt -> has_reference != 0 ); 206 return ( * vt -> has_reference ) ( self, spec ); 207 } 208 catch ( ... ) 209 { 210 } 211 212 return false; 213 } 214 getReference(const char * spec) const215 ReferenceItf * ReadCollectionItf :: getReference ( const char * spec ) const 216 NGS_THROWS ( ErrorMsg ) 217 { 218 // the object is really from C 219 const NGS_ReadCollection_v1 * self = Test (); 220 221 // cast vtable to our level 222 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 223 224 // call through C vtable 225 ErrBlock err; 226 assert ( vt -> get_reference != 0 ); 227 NGS_Reference_v1 * ret = ( * vt -> get_reference ) ( self, & err, spec ); 228 229 // check for errors 230 err . Check (); 231 232 return ReferenceItf :: Cast ( ret ); 233 } 234 getAlignment(const char * alignmentId) const235 AlignmentItf * ReadCollectionItf :: getAlignment ( const char * alignmentId ) const 236 NGS_THROWS ( ErrorMsg ) 237 { 238 // the object is really from C 239 const NGS_ReadCollection_v1 * self = Test (); 240 241 // cast vtable to our level 242 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 243 244 // call through C vtable 245 ErrBlock err; 246 assert ( vt -> get_alignment != 0 ); 247 NGS_Alignment_v1 * ret = ( * vt -> get_alignment ) ( self, & err, alignmentId ); 248 249 // check for errors 250 err . Check (); 251 252 return AlignmentItf :: Cast ( ret ); 253 } 254 getAlignments(uint32_t categories) const255 AlignmentItf * ReadCollectionItf :: getAlignments ( uint32_t categories ) const 256 NGS_THROWS ( ErrorMsg ) 257 { 258 // the object is really from C 259 const NGS_ReadCollection_v1 * self = Test (); 260 261 // cast vtable to our level 262 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 263 264 // call through C vtable 265 ErrBlock err; 266 assert ( vt -> get_alignments != 0 ); 267 bool wants_primary = ( categories & Alignment :: primaryAlignment ); 268 bool wants_secondary 269 = ( categories & Alignment :: secondaryAlignment ) != 0; 270 NGS_Alignment_v1 * ret = ( * vt -> get_alignments ) ( self, & err, wants_primary, wants_secondary ); 271 272 // check for errors 273 err . Check (); 274 275 return AlignmentItf :: Cast ( ret ); 276 } 277 getAlignmentCount(uint32_t categories) const278 uint64_t ReadCollectionItf :: getAlignmentCount ( uint32_t categories ) const 279 NGS_THROWS ( ErrorMsg ) 280 { 281 // the object is really from C 282 const NGS_ReadCollection_v1 * self = Test (); 283 284 // cast vtable to our level 285 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 286 287 // call through C vtable 288 ErrBlock err; 289 assert ( vt -> get_align_count != 0 ); 290 bool wants_primary = ( categories & Alignment :: primaryAlignment ); 291 bool wants_secondary 292 = ( categories & Alignment :: secondaryAlignment ) != 0; 293 uint64_t ret = ( * vt -> get_align_count ) ( self, & err, wants_primary, wants_secondary ); 294 295 // check for errors 296 err . Check (); 297 298 return ret; 299 } 300 getAlignmentRange(uint64_t first,uint64_t count,uint32_t categories) const301 AlignmentItf * ReadCollectionItf :: getAlignmentRange ( uint64_t first, uint64_t count, uint32_t categories ) const 302 NGS_THROWS ( ErrorMsg ) 303 { 304 // the object is really from C 305 const NGS_ReadCollection_v1 * self = Test (); 306 307 // cast vtable to our level 308 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 309 310 // call through C vtable 311 ErrBlock err; 312 assert ( vt -> get_align_range != 0 ); 313 bool wants_primary = ( categories & Alignment :: primaryAlignment ); 314 bool wants_secondary 315 = ( categories & Alignment :: secondaryAlignment ) != 0; 316 NGS_Alignment_v1 * ret = ( * vt -> get_align_range ) ( self, & err, first, count, wants_primary, wants_secondary ); 317 318 // check for errors 319 err . Check (); 320 321 return AlignmentItf :: Cast ( ret ); 322 } 323 getRead(const char * readId) const324 ReadItf * ReadCollectionItf :: getRead ( const char * readId ) const 325 NGS_THROWS ( ErrorMsg ) 326 { 327 // the object is really from C 328 const NGS_ReadCollection_v1 * self = Test (); 329 330 // cast vtable to our level 331 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 332 333 // call through C vtable 334 ErrBlock err; 335 assert ( vt -> get_read != 0 ); 336 NGS_Read_v1 * ret = ( * vt -> get_read ) ( self, & err, readId ); 337 338 // check for errors 339 err . Check (); 340 341 return ReadItf :: Cast ( ret ); 342 } 343 getReads(uint32_t categories) const344 ReadItf * ReadCollectionItf :: getReads ( uint32_t categories ) const 345 NGS_THROWS ( ErrorMsg ) 346 { 347 // the object is really from C 348 const NGS_ReadCollection_v1 * self = Test (); 349 350 // cast vtable to our level 351 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 352 353 // call through C vtable 354 ErrBlock err; 355 assert ( vt -> get_reads != 0 ); 356 bool wants_full = ( categories & Read :: fullyAligned ) != 0; 357 bool wants_partial = ( categories & Read :: partiallyAligned ) != 0; 358 bool wants_unaligned = ( categories & Read :: unaligned ) != 0; 359 NGS_Read_v1 * ret = ( * vt -> get_reads ) ( self, & err, wants_full, wants_partial, wants_unaligned ); 360 361 // check for errors 362 err . Check (); 363 364 return ReadItf :: Cast ( ret ); 365 } 366 getReadCount(uint32_t categories) const367 uint64_t ReadCollectionItf :: getReadCount ( uint32_t categories ) const 368 NGS_THROWS ( ErrorMsg ) 369 { 370 // the object is really from C 371 const NGS_ReadCollection_v1 * self = Test (); 372 373 // cast vtable to our level 374 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 375 376 // call through C vtable 377 ErrBlock err; 378 assert ( vt -> get_read_count != 0 ); 379 bool wants_full = ( categories & Read :: fullyAligned ) != 0; 380 bool wants_partial = ( categories & Read :: partiallyAligned ) != 0; 381 bool wants_unaligned = ( categories & Read :: unaligned ) != 0; 382 uint64_t ret = ( * vt -> get_read_count ) ( self, & err, wants_full, wants_partial, wants_unaligned ); 383 384 // check for errors 385 err . Check (); 386 387 return ret; 388 } 389 getReadRange(uint64_t first,uint64_t count) const390 ReadItf * ReadCollectionItf :: getReadRange ( uint64_t first, uint64_t count ) const 391 NGS_THROWS ( ErrorMsg ) 392 { 393 // the object is really from C 394 const NGS_ReadCollection_v1 * self = Test (); 395 396 // cast vtable to our level 397 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 398 399 // call through C vtable 400 ErrBlock err; 401 assert ( vt -> get_reads != 0 ); 402 NGS_Read_v1 * ret = ( * vt -> get_read_range ) ( self, & err, first, count, true, true, true ); 403 404 // check for errors 405 err . Check (); 406 407 return ReadItf :: Cast ( ret ); 408 } 409 getReadRange(uint64_t first,uint64_t count,uint32_t categories) const410 ReadItf * ReadCollectionItf :: getReadRange ( uint64_t first, uint64_t count, uint32_t categories ) const 411 NGS_THROWS ( ErrorMsg ) 412 { 413 // the object is really from C 414 const NGS_ReadCollection_v1 * self = Test (); 415 416 // cast vtable to our level 417 const NGS_ReadCollection_v1_vt * vt = Access ( self -> vt ); 418 419 // call through C vtable 420 ErrBlock err; 421 assert ( vt -> get_reads != 0 ); 422 bool wants_full = ( categories & Read :: fullyAligned ) != 0; 423 bool wants_partial = ( categories & Read :: partiallyAligned ) != 0; 424 bool wants_unaligned = ( categories & Read :: unaligned ) != 0; 425 NGS_Read_v1 * ret = ( * vt -> get_read_range ) ( self, & err, first, count, wants_full, wants_partial, wants_unaligned ); 426 427 // check for errors 428 err . Check (); 429 430 return ReadItf :: Cast ( ret ); 431 } 432 433 434 } // namespace ngs 435