sequence_test.cu 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. // sequence_test.cu
  28. //
  29. #include <nvbio/basic/timer.h>
  30. #include <nvbio/basic/console.h>
  31. #include <nvbio/basic/packedstream.h>
  32. #include <nvbio/basic/packedstream_loader.h>
  33. #include <nvbio/basic/shared_pointer.h>
  34. #include <nvbio/basic/console.h>
  35. #include <nvbio/basic/dna.h>
  36. #include <nvbio/io/sequence/sequence.h>
  37. #include <nvbio/io/sequence/sequence_mmap.h>
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. using namespace nvbio;
  41. namespace nvbio {
  42. int sequence_test(int argc, char* argv[])
  43. {
  44. char* index_name = NULL;
  45. char* reads_name = NULL;
  46. for (int i = 0; i < argc; ++i)
  47. {
  48. if (strcmp( argv[i], "-map" ) == 0)
  49. index_name = argv[++i];
  50. else if (strcmp( argv[i], "-reads" ) == 0)
  51. reads_name = argv[++i];
  52. }
  53. log_info(stderr,"testing sequence-data... started\n");
  54. try
  55. {
  56. if (index_name != NULL)
  57. {
  58. log_verbose(stderr, " loading sequence file %s\n", index_name );
  59. // try to load the index in memory
  60. io::SequenceDataHost index;
  61. if (io::load_sequence_file(
  62. DNA,
  63. &index,
  64. index_name ) == false)
  65. {
  66. log_error(stderr," loading file %s failed\n", index_name);
  67. return 0;
  68. }
  69. log_verbose(stderr, " sequences : %u\n", index.size() );
  70. log_verbose(stderr, " bps : %u\n", index.bps() );
  71. log_verbose(stderr, " avg bps : %u (min: %u, max: %u)\n",
  72. index.avg_sequence_len(),
  73. index.min_sequence_len(),
  74. index.max_sequence_len() );
  75. // try to load the index in mapped-memory
  76. io::SequenceDataMMAPServer server;
  77. if (server.load( DNA, index_name, "test", io::SequenceFlags( io::SEQUENCE_DATA | io::SEQUENCE_NAMES ) ) == false)
  78. {
  79. log_error(stderr," server mapping of file %s failed\n", index_name);
  80. return 0;
  81. }
  82. // scope the client so as to make sure it's destroyed before the server
  83. {
  84. // and map it into a client
  85. io::SequenceDataMMAP client;
  86. if (client.load( "test" ) == false)
  87. {
  88. log_error(stderr," client mapping of file %s failed\n", index_name);
  89. return 0;
  90. }
  91. log_verbose(stderr, " sequences : %u\n", client.size() );
  92. log_verbose(stderr, " bps : %u\n", client.bps() );
  93. log_verbose(stderr, " avg bps : %u (min: %u, max: %u)\n",
  94. client.avg_sequence_len(),
  95. client.min_sequence_len(),
  96. client.max_sequence_len() );
  97. // check whether the stats match
  98. if (static_cast<const io::SequenceDataInfo&>( index ) !=
  99. static_cast<const io::SequenceDataInfo&>( client ))
  100. {
  101. log_error(stderr," loaded and mapped versions of file %s do not match!\n", index_name);
  102. return 0;
  103. }
  104. }
  105. }
  106. if (reads_name != NULL)
  107. {
  108. SharedPointer<io::SequenceDataStream> read_file( io::open_sequence_file( reads_name ) );
  109. if (read_file == NULL || read_file->is_ok() == false)
  110. {
  111. log_error(stderr," failed opening reads file %s\n", reads_name);
  112. return 0;
  113. }
  114. io::SequenceDataHost read_data;
  115. io::next( DNA_N, &read_data, read_file.get(), 10000 );
  116. log_verbose(stderr, " sequences : %u\n", read_data.size() );
  117. log_verbose(stderr, " bps : %u\n", read_data.bps() );
  118. log_verbose(stderr, " avg bps : %u (min: %u, max: %u)\n",
  119. read_data.avg_sequence_len(),
  120. read_data.min_sequence_len(),
  121. read_data.max_sequence_len() );
  122. }
  123. }
  124. catch (...)
  125. {
  126. log_error(stderr, "caught an unknown exception!\n");
  127. return 0;
  128. }
  129. log_info(stderr,"testing sequence-data... done\n");
  130. return 1;
  131. }
  132. } // namespace nvbio