Commit 110b16b0 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Merge branch 'feature-prerelease_fixes' into 'develop'

Feature prerelease fixes

Commit messages should be clear enough :).

See merge request !61
parents d057ab01 b83f5736
...@@ -19,9 +19,10 @@ import nl.lumc.sasc.biopet.core.ToolCommand ...@@ -19,9 +19,10 @@ import nl.lumc.sasc.biopet.core.ToolCommand
object ExtractAlignedFastq extends ToolCommand { object ExtractAlignedFastq extends ToolCommand {
/** type alias for Fastq input (may or may not be paired) */
type FastqInput = (FastqRecord, Option[FastqRecord]) type FastqInput = (FastqRecord, Option[FastqRecord])
/** function to get FastqRecord ID */ /** Get the FastqRecord ID */
def fastqId(rec: FastqRecord) = rec.getReadHeader.split(" ")(0) def fastqId(rec: FastqRecord) = rec.getReadHeader.split(" ")(0)
/** /**
...@@ -54,14 +55,13 @@ object ExtractAlignedFastq extends ToolCommand { ...@@ -54,14 +55,13 @@ object ExtractAlignedFastq extends ToolCommand {
// by the Interval constructor only accepting ints // by the Interval constructor only accepting ints
def intFromCoord(s: String): Int = s.replaceAll(",", "").replaceAll("\\.", "").toInt def intFromCoord(s: String): Int = s.replaceAll(",", "").replaceAll("\\.", "").toInt
inStrings.map(x => x match { inStrings.map {
case ptn1(chr, start, end) => new Interval(chr, intFromCoord(start), intFromCoord(end)) case ptn1(chr, start, end) => new Interval(chr, intFromCoord(start), intFromCoord(end))
case ptn2(chr, start) => case ptn2(chr, start) =>
val startCoord = intFromCoord(start) val startCoord = intFromCoord(start)
new Interval(chr, startCoord, startCoord) new Interval(chr, startCoord, startCoord)
case _ => throw new IllegalArgumentException("Invalid interval string: " + x) case _ => throw new IllegalArgumentException("Invalid interval string: " + x)
}) }.toIterator
.toIterator
} }
/** /**
...@@ -125,6 +125,13 @@ object ExtractAlignedFastq extends ToolCommand { ...@@ -125,6 +125,13 @@ object ExtractAlignedFastq extends ToolCommand {
} }
} }
/**
* Extracts reads from the given input Fastq file and writes to a new output Fastq file
*
* @param memFunc Predicate for extracting reads. If evaluates to true, the read is extracted.
* @param inputFastq1 Input [[FastqReader]] object.
* @param outputFastq1 Output [[BasicFastqWriter]] object.
*/
def extractReads(memFunc: FastqInput => Boolean, def extractReads(memFunc: FastqInput => Boolean,
inputFastq1: FastqReader, outputFastq1: BasicFastqWriter): Unit = inputFastq1: FastqReader, outputFastq1: BasicFastqWriter): Unit =
inputFastq1.iterator.asScala inputFastq1.iterator.asScala
...@@ -132,6 +139,15 @@ object ExtractAlignedFastq extends ToolCommand { ...@@ -132,6 +139,15 @@ object ExtractAlignedFastq extends ToolCommand {
.filter(rec => memFunc(rec._1, rec._2)) .filter(rec => memFunc(rec._1, rec._2))
.foreach(rec => outputFastq1.write(rec._1)) .foreach(rec => outputFastq1.write(rec._1))
/**
* Extracts reads from the given input Fastq pairs and writes to new output Fastq pair files
*
* @param memFunc Predicate for extracting reads. If evaluates to true, the read is extracted.
* @param inputFastq1 Input [[FastqReader]] object for pair 1.
* @param outputFastq1 Input [[FastqReader]] object for pair 2.
* @param inputFastq2 Output [[BasicFastqWriter]] object for pair 1.
* @param outputFastq2 Output [[BasicFastqWriter]] object for pair 2.
*/
def extractReads(memFunc: FastqInput => Boolean, def extractReads(memFunc: FastqInput => Boolean,
inputFastq1: FastqReader, outputFastq1: BasicFastqWriter, inputFastq1: FastqReader, outputFastq1: BasicFastqWriter,
inputFastq2: FastqReader, outputFastq2: BasicFastqWriter): Unit = inputFastq2: FastqReader, outputFastq2: BasicFastqWriter): Unit =
...@@ -143,6 +159,7 @@ object ExtractAlignedFastq extends ToolCommand { ...@@ -143,6 +159,7 @@ object ExtractAlignedFastq extends ToolCommand {
outputFastq2.write(rec._2) outputFastq2.write(rec._2)
}) })
/** Default arguments */
case class Args(inputBam: File = new File(""), case class Args(inputBam: File = new File(""),
intervals: List[String] = List.empty[String], intervals: List[String] = List.empty[String],
inputFastq1: File = new File(""), inputFastq1: File = new File(""),
...@@ -152,6 +169,7 @@ object ExtractAlignedFastq extends ToolCommand { ...@@ -152,6 +169,7 @@ object ExtractAlignedFastq extends ToolCommand {
minMapQ: Int = 0, minMapQ: Int = 0,
commonSuffixLength: Int = 0) extends AbstractArgs commonSuffixLength: Int = 0) extends AbstractArgs
/** Command line argument parser */
class OptParser extends AbstractOptParser { class OptParser extends AbstractOptParser {
head( head(
...@@ -213,6 +231,7 @@ object ExtractAlignedFastq extends ToolCommand { ...@@ -213,6 +231,7 @@ object ExtractAlignedFastq extends ToolCommand {
} }
} }
/** Parses the command line argument */
def parseArgs(args: Array[String]): Args = def parseArgs(args: Array[String]): Args =
new OptParser() new OptParser()
.parse(args, Args()) .parse(args, Args())
......
...@@ -47,12 +47,7 @@ class WipeReads(val root: Configurable) extends BiopetJavaCommandLineFunction { ...@@ -47,12 +47,7 @@ class WipeReads(val root: Configurable) extends BiopetJavaCommandLineFunction {
object WipeReads extends ToolCommand { object WipeReads extends ToolCommand {
/** /** Creates a SamReader object from an input BAM file, ensuring it is indexed */
* Creates a SamReader object from an input BAM file, ensuring it is indexed
*
* @param inBam input BAM file
* @return
*/
private def prepInBam(inBam: File): SamReader = { private def prepInBam(inBam: File): SamReader = {
val bam = SamReaderFactory val bam = SamReaderFactory
.make() .make()
...@@ -62,6 +57,7 @@ object WipeReads extends ToolCommand { ...@@ -62,6 +57,7 @@ object WipeReads extends ToolCommand {
bam bam
} }
/** Creates a [[SAMFileWriter]] object for writing, indexed */
private def prepOutBam(outBam: File, templateBam: File, private def prepOutBam(outBam: File, templateBam: File,
writeIndex: Boolean = true, async: Boolean = true): SAMFileWriter = writeIndex: Boolean = true, async: Boolean = true): SAMFileWriter =
new SAMFileWriterFactory() new SAMFileWriterFactory()
...@@ -336,6 +332,7 @@ object WipeReads extends ToolCommand { ...@@ -336,6 +332,7 @@ object WipeReads extends ToolCommand {
} }
} }
/** Default arguments */
case class Args(inputBam: File = new File(""), case class Args(inputBam: File = new File(""),
targetRegions: File = new File(""), targetRegions: File = new File(""),
outputBam: File = new File(""), outputBam: File = new File(""),
...@@ -348,6 +345,7 @@ object WipeReads extends ToolCommand { ...@@ -348,6 +345,7 @@ object WipeReads extends ToolCommand {
bloomSize: Long = 70000000, bloomSize: Long = 70000000,
bloomFp: Double = 4e-7) extends AbstractArgs bloomFp: Double = 4e-7) extends AbstractArgs
/** Command line argument parser */
class OptParser extends AbstractOptParser { class OptParser extends AbstractOptParser {
head( head(
...@@ -418,12 +416,7 @@ object WipeReads extends ToolCommand { ...@@ -418,12 +416,7 @@ object WipeReads extends ToolCommand {
} }
/** /** Parses the command line argument */
* Parses the command line argument
*
* @param args Array of arguments
* @return
*/
def parseArgs(args: Array[String]): Args = new OptParser() def parseArgs(args: Array[String]): Args = new OptParser()
.parse(args, Args()) .parse(args, Args())
.getOrElse(sys.exit(1)) .getOrElse(sys.exit(1))
......
...@@ -11,7 +11,7 @@ import org.scalatest.Matchers ...@@ -11,7 +11,7 @@ import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test import org.testng.annotations.Test
class LnUnitTest extends TestNGSuite with Matchers { class LnTest extends TestNGSuite with Matchers {
@Test(description = "Target and link in the same directory, relative set to true") @Test(description = "Target and link in the same directory, relative set to true")
def testSameLevelRelative() { def testSameLevelRelative() {
......
...@@ -17,7 +17,7 @@ import org.testng.annotations.{ DataProvider, Test } ...@@ -17,7 +17,7 @@ import org.testng.annotations.{ DataProvider, Test }
import htsjdk.samtools.util.Interval import htsjdk.samtools.util.Interval
import htsjdk.samtools.fastq.{ BasicFastqWriter, FastqReader, FastqRecord } import htsjdk.samtools.fastq.{ BasicFastqWriter, FastqReader, FastqRecord }
class ExtractAlignedFastqUnitTest extends TestNGSuite with MockitoSugar with Matchers { class ExtractAlignedFastqTest extends TestNGSuite with MockitoSugar with Matchers {
import ExtractAlignedFastq._ import ExtractAlignedFastq._
......
...@@ -25,7 +25,7 @@ import org.scalatest.mock.MockitoSugar ...@@ -25,7 +25,7 @@ import org.scalatest.mock.MockitoSugar
import org.scalatest.testng.TestNGSuite import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test import org.testng.annotations.Test
class WipeReadsUnitTest extends TestNGSuite with MockitoSugar with Matchers { class WipeReadsTest extends TestNGSuite with MockitoSugar with Matchers {
import WipeReads._ import WipeReads._
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment