From 46c6651d56051a52deef372bd4a5fe7aa1bf6414 Mon Sep 17 00:00:00 2001
From: Thomas Krannich <krannich479@googlemail.com>
Date: Thu, 20 Jan 2022 15:39:35 +0100
Subject: [PATCH] new I/O for the crop-unmapped module

---
 Makefile                    |  2 +-
 src/argument_parsing.h      | 19 +++++++++++++++++--
 src/popins2_crop_unmapped.h | 20 +++++++++++---------
 src/popins_find_locations.h |  2 ++
 4 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/Makefile b/Makefile
index 45eb510..218f6c5 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ TOOLS=-DSAMTOOLS=\"$(SAMTOOLS)\" -DBWA=\"$(BWA)\" -DSICKLE=\"$(SICKLE)\" -DVELVE
 
 # Date and version number from git
 DATE := on $(shell git log --pretty=format:"%cd" --date=iso | cut -f 1,2 -d " " | head -n 1)
-VERSION := 0.0.2-snake-$(shell git log --pretty=format:"%h" --date=iso | head -n 1)
+VERSION := 0.0.3-snake-$(shell git log --pretty=format:"%h" --date=iso | head -n 1)
 CXXFLAGS += -DDATE=\""$(DATE)"\" -DVERSION=\""$(VERSION)"\"
 
 # Compiler flags
diff --git a/src/argument_parsing.h b/src/argument_parsing.h
index 1d7c375..87a38d7 100644
--- a/src/argument_parsing.h
+++ b/src/argument_parsing.h
@@ -56,6 +56,9 @@ struct AssemblyOptions {
 
 
 struct CropUnmappedOptions {
+
+    CharString outputFile;
+
     CharString mappingFile;
     CharString matepairFile;
     CharString referenceFile;
@@ -72,7 +75,10 @@ struct CropUnmappedOptions {
 
     float alignment_score_factor;
 
+    bool printSampleInfo;
+
     CropUnmappedOptions () :
+        outputFile("mates.bam"),
         matepairFile(""),
         referenceFile(""),
         prefix("."),
@@ -81,7 +87,8 @@ struct CropUnmappedOptions {
         humanSeqs(maxValue<int>()),
         threads(1),
         memory("768M"),
-        alignment_score_factor(0.67f)
+        alignment_score_factor(0.67f),
+        printSampleInfo(false)
     {}
 };
 
@@ -357,6 +364,8 @@ bool getOptionValues(CropUnmappedOptions & options, ArgumentParser const & parse
 
     getArgumentValue(options.mappingFile, parser, 0);
 
+    if (isSet(parser, "output"))
+       getOptionValue(options.outputFile, parser, "output");
     if (isSet(parser, "prefix"))
        getOptionValue(options.prefix, parser, "prefix");
     if (isSet(parser, "sample"))
@@ -377,6 +386,8 @@ bool getOptionValues(CropUnmappedOptions & options, ArgumentParser const & parse
         getOptionValue(options.memory, parser, "memory");
     if (isSet(parser, "alignment-score-factor"))
         getOptionValue(options.alignment_score_factor, parser, "alignment-score-factor");
+    if (isSet(parser, "printSampleInfo"))
+        options.printSampleInfo = true;
 
     return true;
 }
@@ -816,9 +827,11 @@ void setupParser(ArgumentParser & parser, CropUnmappedOptions & options){
 
     // Setup the options.
     addSection(parser, "Input/output options");
+    addOption(parser, ArgParseOption("o", "output", "File name for the output BAM file.", ArgParseArgument::OUTPUT_FILE, "BAM FILE"));
     addOption(parser, ArgParseOption("p", "prefix", "Path to the sample directories.", ArgParseArgument::STRING, "PATH"));
     addOption(parser, ArgParseOption("s", "sample", "An ID for the sample.", ArgParseArgument::STRING, "SAMPLE_ID"));
     addOption(parser, ArgParseOption("mp", "matePair", "(Currently only available for Velvet.)", ArgParseArgument::INPUT_FILE, "BAM FILE"));
+    addOption(parser, ArgParseOption("i", "printSampleInfo", "Prints sample information sheet if set."));
 
     addSection(parser, "Algorithm options");
     addOption(parser, ArgParseOption("a", "adapters", "Enable adapter removal for Illumina reads. Default: \\fIno adapter removal\\fP.", ArgParseArgument::STRING, "STR"));
@@ -834,12 +847,14 @@ void setupParser(ArgumentParser & parser, CropUnmappedOptions & options){
     // Set valid and default values.
     setValidValues(parser, "adapters", "HiSeq HiSeqX");
     setValidValues(parser, "reference", "fa fna fasta gz");
+    setDefaultValue(parser, "output", options.outputFile);
     setDefaultValue(parser, "prefix", "\'.\'");
     setDefaultValue(parser, "sample", "retrieval from BAM file header");
     setDefaultValue(parser, "kmerLength", options.kmerLength);
     setDefaultValue(parser, "threads", options.threads);
     setDefaultValue(parser, "memory", options.memory);
     setDefaultValue(parser, "alignment-score-factor", options.alignment_score_factor);
+    setDefaultValue(parser, "printSampleInfo", "false");
 
     setMinValue(parser, "threads", "1");
     setMinValue(parser, "alignment-score-factor", "0.0");
@@ -1720,7 +1735,7 @@ void printMultikOptions(const MultikOptions &options){
 }
 
 
-void printMultikOptions(const FindLocationsOptions &options){
+void printFindLocationsOptions(const FindLocationsOptions &options){
     cout << "=========================================================" << endl;
     cout << "popins version     : " << VERSION                          << endl;
     cout << "PARAMETER ======== : VALUE ==============================" << endl;
diff --git a/src/popins2_crop_unmapped.h b/src/popins2_crop_unmapped.h
index 5da97c4..7c7a940 100644
--- a/src/popins2_crop_unmapped.h
+++ b/src/popins2_crop_unmapped.h
@@ -46,8 +46,8 @@ bool retrieveSampleID(CharString & sampleID, CharString & mappingBam)
 // Function popins2_crop_unmapped()
 // ==========================================================================
 
-int popins2_crop_unmapped(int argc, char const ** argv)
-{
+int popins2_crop_unmapped(int argc, char const ** argv){
+
     std::ostringstream msg;
 
     // Parse the command line to get option values.
@@ -73,7 +73,8 @@ int popins2_crop_unmapped(int argc, char const ** argv)
 
     float as_factor = options.alignment_score_factor;
 
-    CharString matesBam = getFileName(workingDirectory, "mates.bam");
+    //CharString matesBam = getFileName(workingDirectory, "mates.bam");
+    CharString matesBam = getFileName(workingDirectory, options.outputFile);
     CharString fastqFirst = getFileName(workingDirectory, "paired.1.fastq");
     CharString fastqSecond = getFileName(workingDirectory, "paired.2.fastq");
     CharString fastqSingle = getFileName(workingDirectory, "single.fastq");
@@ -106,13 +107,14 @@ int popins2_crop_unmapped(int argc, char const ** argv)
                 return 7;
         }
 
-        CharString sampleInfoFile = getFileName(workingDirectory, "POPINS_SAMPLE_INFO");
-        writeSampleInfo(info, sampleInfoFile);
-
-        msg.str("");
-        msg << "Sample info written to \'" << sampleInfoFile << "\'.";
-        printStatus(msg);
+        if(options.printSampleInfo){
+	        CharString sampleInfoFile = getFileName(workingDirectory, "POPINS_SAMPLE_INFO");
+	        writeSampleInfo(info, sampleInfoFile);
 
+	        msg.str("");
+	        msg << "Sample info written to \'" << sampleInfoFile << "\'.";
+	        printStatus(msg);
+	    }
       
     }
 
diff --git a/src/popins_find_locations.h b/src/popins_find_locations.h
index 82e1778..abce682 100644
--- a/src/popins_find_locations.h
+++ b/src/popins_find_locations.h
@@ -133,6 +133,8 @@ int popins_find_locations(int argc, char const ** argv){
     if (res != ArgumentParser::PARSE_OK)
         return res;
 
+    printFindLocationsOptions(options);
+
     CharString workingDirectory = getFileName(options.prefix, options.sampleID);
 
     // Check for input files to exist.
-- 
GitLab