Skip to content

Commit 8b93ccc

Browse files
committed
[FEATURE] SAM/BAM almost done
1 parent 05c6dd6 commit 8b93ccc

3 files changed

Lines changed: 117 additions & 81 deletions

File tree

src/lambda.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ loadQuery(GlobalDataHolder<TRedAlph, TScoreScheme, TIndexSpec, TOutFormat, p, h>
472472
options);
473473

474474
// sam and bam need original sequences if translation happened
475-
if (qIsTranslated(globalHolder.blastProgram) && (options.outFileFormat > 0))
475+
if (qIsTranslated(globalHolder.blastProgram) && (options.outFileFormat > 0) &&
476+
(options.samBamSeq > 0))
476477
std::swap(origSeqs, globalHolder.untranslatedQrySeqs);
477478

478479
if (TGH::alphReduction)

src/options.hpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ struct LambdaOptions : public SharedOptions
225225
std::string output;
226226
std::vector<BlastMatchField<>::Enum> columns;
227227
std::string outputBam;
228-
std::bitset<64> samBamColumns;
228+
std::bitset<64> samBamTags;
229229
bool samWithRefHeader;
230230
bool samBamSeq;
231231

@@ -433,30 +433,32 @@ parseCommandLine(LambdaOptions & options, int argc, char const ** argv)
433433

434434
addOption(parser, ArgParseOption("", "sam-with-refheader",
435435
"BAM files require all subject names to be written to the header. For SAM this is not required, so Lambda does "
436-
"not automatically do it to save space (especially for proteine database this is a lot!). If you still want "
437-
"them with SAM, e.g. for better BAM compatability, use this option.",
436+
"not automatically do it to save space (especially for protein database this is a lot!). If you still want "
437+
"them with SAM, e.g. for better BAM compatibility, use this option.",
438438
ArgParseArgument::STRING,
439439
"STR"));
440440
setValidValues(parser, "sam-with-refheader", "on off");
441441
setDefaultValue(parser, "sam-with-refheader", "off");
442442
setAdvanced(parser, "sam-with-refheader");
443443

444444
addOption(parser, ArgParseOption("", "sam-bam-seq",
445-
"Write matching DNA subsequence into SAM/BAM file (BLASTN). For BLASTX and TBLASTX the matching proteine "
445+
"Write matching DNA subsequence into SAM/BAM file (BLASTN). For BLASTX and TBLASTX the matching protein "
446446
"sequence is \"untranslated\" and positions retransformed to the original sequence. For BLASTP and TBLASTN "
447-
"there is no DNA sequence so this option has no effect. [see also --sam-bam-columns].",
447+
"there is no DNA sequence so a \"*\" is written to the SEQ column. The matching protein sequence can be "
448+
"written as an optional tag, see --sam-bam-tags. If set to uniq than "
449+
"the sequence is omitted iff it is identical to the previous match's subsequence.",
448450
ArgParseArgument::STRING,
449451
"STR"));
450-
setValidValues(parser, "sam-bam-seq", "on off");
451-
setDefaultValue(parser, "sam-bam-seq", "on");
452+
setValidValues(parser, "sam-bam-seq", "always uniq never");
453+
setDefaultValue(parser, "sam-bam-seq", "uniq");
452454
setAdvanced(parser, "sam-bam-seq");
453455

454-
addOption(parser, ArgParseOption("", "sam-bam-columns",
455-
"Write the the specified optional columns to the SAM/BAM file. Call --sam-bam-columns help for more details.",
456+
addOption(parser, ArgParseOption("", "sam-bam-tags",
457+
"Write the specified optional columns to the SAM/BAM file. Call --sam-bam-tags help for more details.",
456458
ArgParseArgument::STRING,
457459
"STR"));
458-
setDefaultValue(parser, "sam-bam-columns", "AS NM ZE ZI ZF");
459-
setAdvanced(parser, "sam-bam-columns");
460+
setDefaultValue(parser, "sam-bam-tags", "AS NM ZE ZI ZF");
461+
setAdvanced(parser, "sam-bam-tags");
460462

461463
addSection(parser, "General Options");
462464
#ifdef _OPENMP
@@ -748,9 +750,12 @@ parseCommandLine(LambdaOptions & options, int argc, char const ** argv)
748750

749751
clear(buffer);
750752
getOptionValue(buffer, parser, "sam-bam-seq");
751-
options.samBamSeq = (buffer == "on");
752-
if ((options.blastProgram == BlastProgram::BLASTP) || (options.blastProgram == BlastProgram::TBLASTN))
753-
options.samBamSeq = false;
753+
if (buffer == "never")
754+
options.samBamSeq = 0;
755+
else if (buffer == "uniq")
756+
options.samBamSeq = 1;
757+
else
758+
options.samBamSeq = 2;
754759

755760
clear(buffer);
756761
getOptionValue(buffer, parser, "output-columns");
@@ -795,7 +800,7 @@ parseCommandLine(LambdaOptions & options, int argc, char const ** argv)
795800
}
796801
clear(buffer);
797802

798-
getOptionValue(buffer, parser, "sam-bam-columns");
803+
getOptionValue(buffer, parser, "sam-bam-tags");
799804
if (buffer == "help")
800805
{
801806
std::cout << "Please specify the tags in this format -oc 'tag1 tag2', i.e. space-seperated and "
@@ -818,21 +823,25 @@ parseCommandLine(LambdaOptions & options, int argc, char const ** argv)
818823
{
819824
if (std::get<0>(SamBamExtraTags<>::keyDescPairs[i]) == str)
820825
{
821-
options.samBamColumns[i] = true;
826+
options.samBamTags[i] = true;
822827
resolved = true;
823828
break;
824829
}
825830
}
826831
if (!resolved)
827832
{
828833
std::cerr << "Unknown column specifier \"" << str
829-
<< "\". Please see \"--sam-bam-columns help\" for valid options.\n";
834+
<< "\". Please see \"--sam-bam-tags help\" for valid options.\n";
830835
return ArgumentParser::PARSE_ERROR;
831836
}
832837
}
833838
}
834-
clear(buffer);
839+
// if original is protein, than only write if explicitly asked for
840+
if (((options.blastProgram == BlastProgram::BLASTP) || (options.blastProgram == BlastProgram::TBLASTN)) &&
841+
(!options.samBamTags[SamBamExtraTags<>::Q_AA_CIGAR]))
842+
options.samBamSeq = 0;
835843

844+
clear(buffer);
836845
getOptionValue(options.seedLength, parser, "seed-length");
837846
if ((!isSet(parser, "seed-length")) &&
838847
(options.blastProgram == BlastProgram::BLASTN))

0 commit comments

Comments
 (0)