diff --git a/src/sam.cpp b/src/sam.cpp index 0fb5a272..320c833b 100644 --- a/src/sam.cpp +++ b/src/sam.cpp @@ -83,7 +83,7 @@ void Sam::add_unmapped(const KSeq& record, uint16_t flags) { sam_string.append("\t"); sam_string.append(std::to_string(flags)); sam_string.append("\t*\t0\t" SAM_UNMAPPED_MAPQ_STRING "\t*\t*\t0\t0\t"); - sam_string.append(record.seq); + append_seq(record.seq); append_qual(record.qual); append_rg_and_newline(); } @@ -105,7 +105,7 @@ void Sam::add_unmapped_mate(const KSeq& record, uint16_t flags, const std::strin sam_string.append("\t"); sam_string.append(std::to_string(mate_pos + 1)); sam_string.append("\t0\t"); - sam_string.append(record.seq); + append_seq(record.seq); append_qual(record.qual); append_rg_and_newline(); } @@ -176,11 +176,11 @@ void Sam::add_record( sam_string.append("\t"); if (flags & SECONDARY) { - sam_string.append("*"); + append_seq(""); } else if (flags & REVERSE) { - sam_string.append(query_sequence_rc); + append_seq(query_sequence_rc); } else { - sam_string.append(query_sequence); + append_seq(query_sequence); } if (!(flags & UNMAP)) { diff --git a/src/sam.hpp b/src/sam.hpp index ae9fb62a..74968aea 100644 --- a/src/sam.hpp +++ b/src/sam.hpp @@ -86,6 +86,11 @@ class Sam { private: void add_record(const std::string& query_name, uint16_t flags, const std::string& reference_name, uint32_t pos, uint8_t mapq, const Cigar& cigar, const std::string& mate_reference_name, uint32_t mate_pos, int32_t template_len, const std::string& query_sequence, const std::string& query_sequence_rc, const std::string& qual, int ed, int aln_score, const Details& details); + + void append_seq(const std::string& seq) { + sam_string.append(seq.empty() ? "*" : seq); + } + void append_qual(const std::string& qual) { sam_string.append("\t"); sam_string.append(qual.empty() ? "*" : qual); diff --git a/tests/phix.pe.sam b/tests/phix.pe.sam index 5d5c8195..ef4157d7 100644 --- a/tests/phix.pe.sam +++ b/tests/phix.pe.sam @@ -89,5 +89,5 @@ rescuable.43 83 NC_001422.1 3137 60 120S14=1X4=1X9=1X4=1X4=1X9=1X4=1X4=1X4=1X9=1 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EF<@EDFFF### RG:Z:1 -empty 77 * 0 0 * * 0 0 * RG:Z:1 -empty 141 * 0 0 * * 0 0 * RG:Z:1 +empty 77 * 0 0 * * 0 0 * * RG:Z:1 +empty 141 * 0 0 * * 0 0 * * RG:Z:1 diff --git a/tests/phix.se.sam b/tests/phix.se.sam index 23b3ffd6..4ce2a053 100644 --- a/tests/phix.se.sam +++ b/tests/phix.se.sam @@ -45,4 +45,4 @@ unmappable.41 4 * 0 0 * * 0 0 TGCATGCAGTACGTGCTCGCCGTAGGTTGTGGCTCATTCCTGCAACACGT rescuable.42 16 NC_001422.1 3017 60 116=1X183=1X * 0 0 CTCCGGTGGCATTCAAGGTGATGTGCTTGCTACCGATAACAATACTGTAGGCATGGGTGATGCTGGTATTAAATCTGCCATTCAAGGCTCTAATGTTCCTAACCCTGATGAGGCCGTCCCTAGTTTTGTTTCTGGTGCTATGGCTAAAGCTGGTAAAGGACTTCTTGAAGGTACGTTGCAGGCTGGCACTTCTGCCGTTTCTGATAAGTTGCTTGATTTGGTTGGACTTGGTGGCAAGTCTGCCGCTGATAAAGGAAAGGATACTCGTGATTATCTTGCTGCTGCATTTCCTGAGCTTAAN 6FFFFFB?FBFFFBFFFFE@<@;FDFEC62,+;FEFFFFECFEFFFFFFFFFFFFFGFGFGGFGFGGGGFD>?7DGGGGGGGGGGGGGGFGGGGGGGGGGGEGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCCB8# NM:i:2 AS:i:602 RG:Z:1 rescuable.43 4 * 0 0 * * 0 0 ATAAGATCAGAAAATACAGCAGCAAAATAAACACGAGTATACTTTACTTTATCAGAGGCAAACTTACCACAAAGTACAACAAAATAAAGCAACTTAT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GGGGGGGGFGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCCB8# NM:i:2 AS:i:602 RG:Z:1 -empty 4 * 0 0 * * 0 0 * RG:Z:1 +empty 4 * 0 0 * * 0 0 * * RG:Z:1 diff --git a/tests/run.sh b/tests/run.sh index 0e11f7fe..097e64d1 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -69,3 +69,24 @@ if ${strobealign} --create-index tests/phix.fasta > /dev/null 2> /dev/null; then # --details output is proper SAM ${strobealign} --details tests/phix.fasta tests/phix.1.fastq tests/phix.2.fastq 2> /dev/null | samtools view -o /dev/null ${strobealign} --details tests/phix.fasta tests/phix.1.fastq 2> /dev/null | samtools view -o /dev/null + +# Secondary alignments + +# No secondary alignments on phix +${strobealign} tests/phix.fasta tests/phix.1.fastq | grep -v '^@PG' > no-secondary.sam +${strobealign} -N 5 tests/phix.fasta tests/phix.1.fastq | grep -v '^@PG' > with-secondary.sam +test $(samtools view -f 0x100 -c with-secondary.sam) -eq 0 +rm no-secondary.sam with-secondary.sam + +# Secondary alignments for repeated phiX +cp tests/phix.fasta repeated-phix.fasta +echo ">repeated_NC_001422" >> repeated-phix.fasta +sed 1d tests/phix.fasta >> repeated-phix.fasta +${strobealign} repeated-phix.fasta tests/phix.1.fastq | grep -v '^@PG' > no-secondary.sam +${strobealign} -N 5 repeated-phix.fasta tests/phix.1.fastq | grep -v '^@PG' > with-secondary.sam +test $(samtools view -f 0x100 -c with-secondary.sam) -gt 0 + +# Removing secondary alignments gives same result as not producing them in the first place +samtools view -h --no-PG -F 0x100 with-secondary.sam > with-secondary-only-primary.sam +diff no-secondary.sam with-secondary-only-primary.sam +rm no-secondary.sam with-secondary.sam with-secondary-only-primary.sam repeated-phix.fasta