sample_kmers.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. // sample_kmers.h
  28. //
  29. #pragma once
  30. #include "utils.h"
  31. #include <nvbio/basic/pipeline_context.h>
  32. #include <nvbio/basic/numbers.h>
  33. #include <nvbio/basic/console.h>
  34. #include <nvbio/basic/timer.h>
  35. #include <nvbio/basic/primitives.h>
  36. #include <nvbio/io/sequence/sequence.h>
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. ///@addtogroup nvLighterModule
  40. ///@{
  41. ///
  42. /// A small class implementing an nvbio::Pipeline sink stage building the sampled kmers filter
  43. ///
  44. struct SampleKmersStage
  45. {
  46. typedef nvbio::io::SequenceDataHost argument_type;
  47. /// empty constructor
  48. ///
  49. SampleKmersStage() {}
  50. /// constructor
  51. ///
  52. ///\param _k kmer length
  53. ///\param _alpha the sampling frequency
  54. ///\param _filter_size the kmer Bloom filter's size, in bits
  55. ///\param _filter_storage the kmer Bloom filter's storage
  56. ///
  57. SampleKmersStage(
  58. const int _device,
  59. const uint32 _k,
  60. const float _alpha,
  61. const uint64 _filter_size,
  62. uint32* _filter_storage,
  63. SequenceStats* _stats) :
  64. device( _device ),
  65. k( _k ),
  66. alpha( _alpha ),
  67. filter_size( _filter_size ),
  68. filter_storage( _filter_storage ),
  69. stats( _stats )
  70. {}
  71. /// process the next batch
  72. ///
  73. bool process(nvbio::PipelineContext& context);
  74. int device;
  75. uint32 k;
  76. float alpha;
  77. uint64 filter_size;
  78. uint32* filter_storage;
  79. SequenceStats* stats;
  80. nvbio::for_each_enactor<nvbio::host_tag> host_for_each;
  81. nvbio::for_each_enactor<nvbio::device_tag> device_for_each;
  82. };
  83. ///
  84. /// A small class implementing an nvbio::Pipeline sink stage building the trusted kmers filter
  85. ///
  86. struct TrustedKmersStage
  87. {
  88. typedef nvbio::io::SequenceDataHost argument_type;
  89. /// default constructor
  90. ///
  91. TrustedKmersStage() {}
  92. /// constructor
  93. ///
  94. ///\param _k kmer length
  95. ///\param _alpha the sampling frequency
  96. ///\param _filter_size the kmer Bloom filter's size, in bits
  97. ///\param _filter_storage the kmer Bloom filter's storage
  98. ///
  99. TrustedKmersStage(
  100. const int _device,
  101. const uint32 _k,
  102. const uint64 _sampled_filter_size,
  103. const uint32* _sampled_filter_storage,
  104. const uint64 _trusted_filter_size,
  105. uint32* _trusted_filter_storage,
  106. const uint32* _threshold,
  107. SequenceStats* _stats) :
  108. device( _device ),
  109. k( _k ),
  110. sampled_filter_size( _sampled_filter_size ),
  111. sampled_filter_storage( _sampled_filter_storage ),
  112. trusted_filter_size( _trusted_filter_size ),
  113. trusted_filter_storage( _trusted_filter_storage ),
  114. threshold(_threshold),
  115. stats( _stats )
  116. {}
  117. /// process the next batch
  118. ///
  119. bool process(nvbio::PipelineContext& context);
  120. int device;
  121. uint32 k;
  122. uint64 sampled_filter_size;
  123. const uint32* sampled_filter_storage;
  124. uint64 trusted_filter_size;
  125. uint32* trusted_filter_storage;
  126. const uint32* threshold;
  127. SequenceStats* stats;
  128. nvbio::for_each_enactor<nvbio::host_tag> host_for_each;
  129. nvbio::for_each_enactor<nvbio::device_tag> device_for_each;
  130. };
  131. ///@} // group nvLighterModule