Commit 8197a29d authored by Sander Bollen's avatar Sander Bollen
Browse files

create genome file from fai.

parent 9f156daf
......@@ -15,13 +15,16 @@
*/
package nl.lumc.sasc.biopet.extensions.bedtools
import java.io.File
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.core.Reference
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.utils.commandline.{ Argument, Input, Output }
import org.broadinstitute.gatk.utils.commandline.{Argument, Input, Output}
import scala.io.Source
/** Extension for bedtools coverage */
class BedtoolsCoverage(val root: Configurable) extends Bedtools {
class BedtoolsCoverage(val root: Configurable) extends Bedtools with Reference {
@Input(doc = "Input file (bed/gff/vcf/bam)")
var input: File = null
......@@ -41,6 +44,7 @@ class BedtoolsCoverage(val root: Configurable) extends Bedtools {
@Argument(doc = "diffStrand", required = false)
var diffStrand: Boolean = false
@Argument(doc = "sorted", required= false)
var sorted: Boolean = config("sorted", default = false, freeVar = false)
override def defaultCoreMemory = 4.0
......@@ -53,7 +57,24 @@ class BedtoolsCoverage(val root: Configurable) extends Bedtools {
conditional(sameStrand, "-s") +
conditional(diffStrand, "-S") +
conditional(sorted, "-sorted") +
(if (sorted) required("-g", createGenomeFile(referenceFai)) else "") +
(if (outputAsStsout) "" else " > " + required(output))
/**
* Creates the genome file. i.e. the first two columns of the fasta index
* @return
*/
def createGenomeFile(fai: File): File = {
val tmp = File.createTempFile(fai.getName, ".genome", output.getParentFile)
tmp.deleteOnExit()
val writer = new PrintWriter(tmp)
Source.fromFile(fai).
getLines().
map(s => s.split("\t").take(2).mkString("\t")).
foreach(f => writer.println(f))
writer.close()
tmp
}
}
object BedtoolsCoverage {
......
chr1 9 6 9 10
\ No newline at end of file
package nl.lumc.sasc.biopet.extensions
import java.io.File
import java.nio.file.Paths
import nl.lumc.sasc.biopet.extensions.bedtools.BedtoolsCoverage
import org.scalatest.Matchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test
import scala.io.Source
/**
* Created by Sander Bollen on 12-5-16.
*/
class BedToolsTest extends TestNGSuite with Matchers {
@Test
def testBedtoolsCoverageCreateGenomeFile() = {
val file = new File(Paths.get(this.getClass.getResource("/ref.fa.fai").toURI).toString)
val cov = new BedtoolsCoverage(null)
val tmp = File.createTempFile("test", ".bed")
tmp.deleteOnExit()
cov.output = tmp
val genome = cov.createGenomeFile(file)
Source.fromFile(genome).getLines().mkString("\n") shouldBe "chr1\t9"
}
}
Markdown is supported
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