alignment_dbg.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * nvbio
  3. * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the NVIDIA CORPORATION nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #include <nvbio-aln-diff/alignment.h>
  28. #include <zlib/zlib.h>
  29. namespace nvbio {
  30. namespace alndiff {
  31. struct DebugAlignmentStream : public AlignmentStream
  32. {
  33. struct Info
  34. {
  35. uint32 flag;
  36. uint32 ref_id;
  37. // 8-bytes
  38. uint8 mate;
  39. uint8 mapQ;
  40. uint8 ed;
  41. uint8 pad;
  42. // 12-bytes
  43. uint16 subs:16;
  44. uint8 ins;
  45. uint8 dels;
  46. // 16-bytes
  47. uint8 mms;
  48. uint8 gapo;
  49. uint8 gape;
  50. uint8 has_second;
  51. // 20-bytes
  52. int32 score;
  53. int32 sec_score;
  54. // 24-bytes
  55. };
  56. DebugAlignmentStream(const char* file_name)
  57. {
  58. m_file = gzopen( file_name, "rb" );
  59. }
  60. // return if the stream is ok
  61. //
  62. bool is_ok() { return m_file != NULL; }
  63. // get the next batch
  64. //
  65. uint32 next_batch(
  66. const uint32 count,
  67. Alignment* batch)
  68. {
  69. uint32 n_read = 0;
  70. Info info;
  71. while (n_read < count)
  72. {
  73. Alignment* aln = batch + n_read;
  74. // clean the alignment
  75. *aln = Alignment();
  76. // read id
  77. if (gzread( m_file, &aln->read_id, sizeof(uint32) ) == 0)
  78. break;
  79. // read length
  80. gzread( m_file, &aln->read_len, sizeof(uint32) );
  81. // alignment position
  82. gzread( m_file, &aln->pos, sizeof(uint32) );
  83. if (aln->pos != uint32(0))
  84. {
  85. gzread( m_file, &info, sizeof(Info) );
  86. aln->flag = info.flag;
  87. aln->ref_id = info.ref_id;
  88. aln->mate = info.mate;
  89. aln->score = info.score;
  90. aln->mapQ = info.mapQ;
  91. aln->ed = info.ed;
  92. aln->subs = info.subs;
  93. aln->ins = info.ins;
  94. aln->dels = info.dels;
  95. aln->n_mm = info.mms;
  96. aln->n_gapo = info.gapo;
  97. aln->n_gape = info.gape;
  98. aln->has_second = info.has_second;
  99. aln->sec_score = info.sec_score;
  100. }
  101. ++n_read;
  102. }
  103. return n_read;
  104. }
  105. gzFile m_file;
  106. };
  107. AlignmentStream* open_dbg_file(const char* file_name)
  108. {
  109. return new DebugAlignmentStream( file_name );
  110. }
  111. } // alndiff namespace
  112. } // nvbio namespace