1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
// -----------------------------------------------------------------------------------------------------
// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
// shipped with this file and also available at: https://github.com/seqan/seqan3/blob/master/LICENSE.md
// -----------------------------------------------------------------------------------------------------
#include <sstream>
#include <gtest/gtest.h>
#include <seqan3/io/sequence_file/output.hpp>
#include <seqan3/io/sequence_file/input.hpp>
#include <seqan3/range/views/persist.hpp>
#include <seqan3/range/views/take.hpp>
#include <seqan3/test/tmp_filename.hpp>
#include <seqan3/std/iterator>
TEST(rows, assign_sequence_files)
{
std::string const input
{
">TEST 1\n"
"ACGT\n"
"> Test2\n"
"AGGCTGN AGGCTGN AGGCTGN AGGCTGN AGGCTGN AGGCTGN AGGCTGN AGGCTGN AGGCTGN AGGCTGN AGGCTGN AGGCTGN AGGCTGN\n\n"
"> Test3\n"
"GGAGTATAATATATATATATATAT\n"
};
std::string const output_comp
{
"> TEST 1\n"
"ACGT\n"
"> Test2\n"
"AGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGN\n"
"> Test3\n"
"GGAGTATAATATATATATATATAT\n"
};
seqan3::sequence_file_input fin{std::istringstream{input}, seqan3::format_fasta{}};
seqan3::sequence_file_output fout{std::ostringstream{}, seqan3::format_fasta{}};
fout.options.fasta_letters_per_line = 0;
fout = fin;
fout.get_stream().flush();
EXPECT_EQ(reinterpret_cast<std::ostringstream&>(fout.get_stream()).str(), output_comp);
}
TEST(integration, assign_sequence_file_pipes)
{
std::string const input
{
"> TEST1\n"
"ACGT\n"
"> Test2\n"
"AGGCTGNAGGCTGAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGN\n"
"> Test3\n"
"GGAGTATAATATATATATATATAT\n"
};
// valid without assignment?
seqan3::sequence_file_input{std::istringstream{input}, seqan3::format_fasta{}} |
seqan3::sequence_file_output{std::ostringstream{}, seqan3::format_fasta{}};
// valid with assignment and check contents
auto fout = seqan3::sequence_file_input{std::istringstream{input}, seqan3::format_fasta{}} |
seqan3::sequence_file_output{std::ostringstream{}, seqan3::format_fasta{}};
fout.get_stream().flush();
EXPECT_EQ(reinterpret_cast<std::ostringstream&>(fout.get_stream()).str(), input);
}
TEST(integration, view)
{
std::string const input
{
"> TEST1\n"
"ACGT\n"
"> Test2\n"
"AGGCTGNAGGCTGAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGN\n"
"> Test3\n"
"GGAGTATAATATATATATATATAT\n"
};
std::string const output
{
"> TEST1\n"
"ACGT\n"
"> Test2\n"
"AGGCTGNAGGCTGAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGNAGGCTGN\n"
};
#if !SEQAN3_WORKAROUND_GCC_93983
// valid without assignment?
seqan3::sequence_file_input{std::istringstream{input},
seqan3::format_fasta{}} | seqan3::views::persist
| seqan3::views::take(2)
| seqan3::sequence_file_output{std::ostringstream{},
seqan3::format_fasta{}};
// valid with assignment and check contents
auto fout = seqan3::sequence_file_input{std::istringstream{input}, seqan3::format_fasta{}}
| seqan3::views::persist
| seqan3::views::take(2)
| seqan3::sequence_file_output{std::ostringstream{}, seqan3::format_fasta{}};
fout.get_stream().flush();
EXPECT_EQ(reinterpret_cast<std::ostringstream&>(fout.get_stream()).str(), output);
#endif // !SEQAN3_WORKAROUND_GCC_93983
}
TEST(integration, convert_fastq_to_fasta)
{
std::string const fastq_in
{
"@ID1\n"
"ACGTT\n"
"+\n"
"!##$%\n"
"@ID2\n"
"TATTA\n"
"+\n"
",BDEB\n"
};
std::string const fasta_out
{
"> ID1\n"
"ACGTT\n"
"> ID2\n"
"TATTA\n"
};
auto fout = seqan3::sequence_file_input{std::istringstream{fastq_in}, seqan3::format_fastq{}} |
seqan3::sequence_file_output{std::ostringstream{}, seqan3::format_fasta{}};
fout.get_stream().flush();
EXPECT_EQ(reinterpret_cast<std::ostringstream&>(fout.get_stream()).str(), fasta_out);
}
|