@@ -148,6 +148,7 @@ struct MappingOpts {
148148 bool noOrphans{false };
149149 bool noDovetail{false };
150150 bool recoverOrphans{false };
151+ bool writeUnmapped{false };
151152};
152153
153154using AlnCacheMap = selective_alignment::utils::AlnCacheMap;
@@ -315,15 +316,13 @@ void processReadsSingleSA(single_parser * parser,
315316 }
316317 }
317318
318- if (hits.size () > 0 and !mopts->noOutput ) {
319- /*
320- std::sort(hits.begin(), hits.end(),
321- [](const QuasiAlignment& a, const QuasiAlignment& b) -> bool {
322- return a.tid < b.tid;
323- });
324- */
319+ if (!mopts->noOutput ){
320+ if (hits.size () > 0 ) {
325321 rapmap::utils::writeAlignmentsToStream (read, formatter,
326322 hctr, hits, sstream);
323+ } else {
324+ rapmap::utils::writeUnalignedSingleToStream (read, sstream);
325+ }
327326 }
328327
329328 if (hctr.numReads > hctr.lastPrint + 1000000 ) {
@@ -702,9 +701,13 @@ void processReadsPairSA(paired_parser* parser,
702701 hctr.totHits += jointHits.size ();
703702
704703 // If we have reads to output, and we're writing output.
705- if (jointHits.size () > 0 and !mopts->noOutput and jointHits.size () <= mopts->maxNumHits ) {
704+ if (!mopts->noOutput ) {
705+ if (jointHits.size () > 0 and jointHits.size () <= mopts->maxNumHits ) {
706706 rapmap::utils::writeAlignmentsToStream (rpair, formatter,
707707 hctr, jointHits, sstream);
708+ } else {
709+ rapmap::utils::writeUnalignedPairToStream (rpair, sstream);
710+ }
708711 }
709712
710713 if (hctr.numReads > hctr.lastPrint + 1000000 ) {
@@ -1001,10 +1004,11 @@ int rapMapSAMap(int argc, char* argv[]) {
10011004 TCLAP::SwitchArg chain (" c" , " chaining" , " Score the hits to find the best chain" , false );
10021005 TCLAP::SwitchArg compressedOutput (" x" , " compressed" , " Compress the output SAM file using zlib" , false );
10031006 TCLAP::SwitchArg quiet (" q" , " quiet" , " Disable all console output apart from warnings and errors" , false );
1007+ TCLAP::SwitchArg writeUnmapped (" u" , " writeUnmapped" , " include unmapped reads in the output SAM records" , false );
1008+
10041009 TCLAP::SwitchArg recoverOrphans (" " , " recoverOrphans" , " perform orphan recovery to try and recover endpoints of orphaned reads" , false );
10051010 TCLAP::SwitchArg noDovetail (" " , " noDovetail" , " discard dovetailing mappings" , false );
10061011 TCLAP::SwitchArg noOrphans (" " , " noOrphans" , " discard orphaned mappings" , false );
1007-
10081012 TCLAP::SwitchArg selAln (" s" , " selAln" , " Perform selective alignment to validate mapping hits" , false );
10091013 TCLAP::ValueArg<int16_t > gapOpenPen (" " , " go" , " [only with selAln]: gap open penalty" , false , 4 , " positive integer" );
10101014 TCLAP::ValueArg<int16_t > gapExtendPen (" " , " ge" , " [only with selAln]: gap extend penalty" , false , 2 , " positive integer" );
@@ -1026,6 +1030,7 @@ int rapMapSAMap(int argc, char* argv[]) {
10261030 cmd.add (fuzzy);
10271031 cmd.add (chain);
10281032 cmd.add (quiet);
1033+ cmd.add (writeUnmapped);
10291034 cmd.add (hardFilter);
10301035 cmd.add (recoverOrphans);
10311036 cmd.add (noDovetail);
@@ -1099,6 +1104,7 @@ int rapMapSAMap(int argc, char* argv[]) {
10991104 } else {
11001105 mopts.unmatedReads = unmatedReads.getValue ();
11011106 }
1107+ mopts.writeUnmapped = writeUnmapped.getValue ();
11021108 mopts.numThreads = numThreads.getValue ();
11031109 mopts.maxNumHits = maxNumHits.getValue ();
11041110 mopts.outname = (outname.isSet ()) ? outname.getValue () : " " ;
0 commit comments