1
0

bamcmp.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. biobambam
  3. Copyright (C) 2009-2014 German Tischler
  4. Copyright (C) 2011-2014 Genome Research Limited
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. **/
  16. #include <libmaus2/util/ArgInfo.hpp>
  17. #include <libmaus2/bambam/BamDecoder.hpp>
  18. int main(int argc, char * argv[])
  19. {
  20. try
  21. {
  22. libmaus2::util::ArgInfo const arginfo(argc,argv);
  23. std::string const fn1 = arginfo.stringRestArg(0);
  24. std::string const fn2 = arginfo.stringRestArg(1);
  25. libmaus2::bambam::BamDecoder bamdec1(fn1);
  26. libmaus2::bambam::BamDecoder bamdec2(fn2);
  27. libmaus2::bambam::BamHeader const & header1(bamdec1.getHeader());
  28. libmaus2::bambam::BamHeader const & header2(bamdec2.getHeader());
  29. libmaus2::bambam::BamAlignment const & al1 = bamdec1.getAlignment();
  30. libmaus2::bambam::BamAlignment const & al2 = bamdec2.getAlignment();
  31. uint64_t lcnt = 0;
  32. while ( bamdec1.readAlignment() )
  33. {
  34. if ( ! bamdec2.readAlignment() )
  35. {
  36. libmaus2::exception::LibMausException lme;
  37. lme.getStream() << "EOF on second file\n";
  38. lme.finish();
  39. throw lme;
  40. }
  41. std::string const s1 = al1.formatAlignment(header1);
  42. std::string const s2 = al2.formatAlignment(header2);
  43. if ( s1 != s2 )
  44. {
  45. libmaus2::exception::LibMausException lme;
  46. lme.getStream() << "Difference in line " << lcnt << "\n" << s1 << "\n" << s2 << "\n";
  47. lme.finish();
  48. throw lme;
  49. }
  50. lcnt += 1;
  51. }
  52. if ( bamdec2.readAlignment() )
  53. {
  54. libmaus2::exception::LibMausException lme;
  55. lme.getStream() << "EOF on first file\n";
  56. lme.finish();
  57. throw lme;
  58. }
  59. return EXIT_SUCCESS;
  60. }
  61. catch(std::exception const & ex)
  62. {
  63. std::cerr << ex.what() << std::endl;
  64. return EXIT_FAILURE;
  65. }
  66. }