From d7df6de4e38ed09a7b3cf747ea1356b47c7e43cd Mon Sep 17 00:00:00 2001 From: Peter van 't Hof <p.j.van_t_hof@lumc.nl> Date: Sat, 22 Aug 2015 14:09:27 +0200 Subject: [PATCH] Code style fixes --- .../extensions/rscript/ScatterPlot.scala | 2 +- .../sasc/biopet/tools/RegionAfCount.scala | 22 ++++++------ .../nl/lumc/sasc/biopet/tools/SquishBed.scala | 36 +++++++++++++++++++ .../biopet/utils/intervals/BedRecord.scala | 10 +++--- 4 files changed, 53 insertions(+), 17 deletions(-) create mode 100644 public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/SquishBed.scala diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/rscript/ScatterPlot.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/rscript/ScatterPlot.scala index e03ce0b4b..f4cccdda1 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/rscript/ScatterPlot.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/rscript/ScatterPlot.scala @@ -19,7 +19,7 @@ import java.io.File import nl.lumc.sasc.biopet.core.config.Configurable import nl.lumc.sasc.biopet.extensions.RscriptCommandLineFunction -import org.broadinstitute.gatk.utils.commandline.{Input, Output} +import org.broadinstitute.gatk.utils.commandline.{ Input, Output } /** * Extension for en general line plot with R diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/RegionAfCount.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/RegionAfCount.scala index 7cf9e74b5..0435f9d6d 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/RegionAfCount.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/RegionAfCount.scala @@ -15,20 +15,20 @@ */ package nl.lumc.sasc.biopet.tools -import java.io.{PrintWriter, InputStream, File} +import java.io.{ PrintWriter, InputStream, File } import java.util import htsjdk.samtools.util.Interval -import htsjdk.samtools.{QueryInterval, SAMRecord, SamReader, SamReaderFactory} +import htsjdk.samtools.{ QueryInterval, SAMRecord, SamReader, SamReaderFactory } import htsjdk.tribble.AbstractFeatureReader._ -import htsjdk.tribble.{AbstractFeatureReader, TabixFeatureReader} -import htsjdk.tribble.bed.{BEDFeature, SimpleBEDFeature, BEDCodec, FullBEDFeature} -import htsjdk.variant.variantcontext.writer.{AsyncVariantContextWriter, VariantContextWriterBuilder} -import htsjdk.variant.variantcontext.{VariantContext, VariantContextBuilder} -import htsjdk.variant.vcf.{VCFFileReader, VCFHeaderLineCount, VCFHeaderLineType, VCFInfoHeaderLine} +import htsjdk.tribble.{ AbstractFeatureReader, TabixFeatureReader } +import htsjdk.tribble.bed.{ BEDFeature, SimpleBEDFeature, BEDCodec, FullBEDFeature } +import htsjdk.variant.variantcontext.writer.{ AsyncVariantContextWriter, VariantContextWriterBuilder } +import htsjdk.variant.variantcontext.{ VariantContext, VariantContextBuilder } +import htsjdk.variant.vcf.{ VCFFileReader, VCFHeaderLineCount, VCFHeaderLineType, VCFInfoHeaderLine } import nl.lumc.sasc.biopet.core.ToolCommand import nl.lumc.sasc.biopet.extensions.rscript.ScatterPlot -import nl.lumc.sasc.biopet.utils.intervals.{BedRecord, BedRecordList} +import nl.lumc.sasc.biopet.utils.intervals.{ BedRecord, BedRecordList } import scala.collection.JavaConversions._ import scala.collection.JavaConverters._ @@ -54,10 +54,10 @@ object RegionAfCount extends ToolCommand { c.copy(scatterpPlot = Some(x)) } opt[File]('V', "vcfFile") unbounded () minOccurs 1 action { (x, c) => - c.copy(vcfFiles = c.vcfFiles ::: x :: Nil ) + c.copy(vcfFiles = c.vcfFiles ::: x :: Nil) } opt[Unit]("exonsOnly") unbounded () action { (x, c) => - c.copy(exonsOnly = true ) + c.copy(exonsOnly = true) } } @@ -87,7 +87,7 @@ object RegionAfCount extends ToolCommand { for (variant <- it) { val sum = (variant.getAttribute("AF", 0) match { case a: util.ArrayList[_] => a.map(_.toString.toDouble).toArray - case s => Array(s.toString.toDouble) + case s => Array(s.toString.toDouble) }).sum bedRecords .overlapWith(BedRecord(variant.getContig, variant.getStart, variant.getEnd)) diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/SquishBed.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/SquishBed.scala new file mode 100644 index 000000000..41ac62d31 --- /dev/null +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/tools/SquishBed.scala @@ -0,0 +1,36 @@ +package nl.lumc.sasc.biopet.tools + +import java.io.File + +import nl.lumc.sasc.biopet.core.ToolCommand +import nl.lumc.sasc.biopet.utils.intervals.BedRecordList + +/** + * Created by pjvanthof on 22/08/15. + */ +object SquishBed extends ToolCommand { + + case class Args(input: File = null, output: File = null) extends AbstractArgs + + class OptParser extends AbstractOptParser { + opt[File]('I', "input") required () valueName "<file>" action { (x, c) => + c.copy(input = x) + } + opt[File]('o', "output") required () unbounded () valueName "<file>" action { (x, c) => + c.copy(output = x) + } + } + + /** + * @param args the command line arguments + */ + def main(args: Array[String]): Unit = { + val argsParser = new OptParser + val cmdArgs: Args = argsParser.parse(args, Args()) getOrElse sys.exit(1) + + if (!cmdArgs.input.exists) throw new IllegalStateException("Input file not found, file: " + cmdArgs.input) + + val records = BedRecordList.fromFile(cmdArgs.input).squishBed() + + } +} diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecord.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecord.scala index 55f5907cc..58901c955 100644 --- a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecord.scala +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecord.scala @@ -24,7 +24,7 @@ case class BedRecord(chr: String, Some(BedRecordList.fromList(for (i <- 0 to blockCount.get) yield { val exonNumber = strand match { case Some(false) => blockCount.get - i - case _ => i + 1 + case _ => i + 1 } val record = BedRecord(chr, start + blockStarts(i), start + blockStarts(i) + blockSizes(i), name.map(_ + s"_exon-$exonNumber")) @@ -37,7 +37,7 @@ case class BedRecord(chr: String, Some(BedRecordList.fromList(for (i <- 0 to (blockCount.get - 1)) yield { val intronNumber = strand match { case Some(false) => blockCount.get - i - case _ => i + 1 + case _ => i + 1 } val record = BedRecord(chr, start + start + blockStarts(i) + blockSizes(i) + 1, start + blockStarts(i + 1) - 1, name.map(_ + s"_intron-$intronNumber")) @@ -65,11 +65,11 @@ object BedRecord { values.lift(5).map(_ match { case "-" => false case "+" => true - case _ => throw new IllegalStateException("Strand (column 6) must be '+' or '-'") + case _ => throw new IllegalStateException("Strand (column 6) must be '+' or '-'") }), values.lift(6).map(_.toInt), - values.lift(7)map(_.toInt), - values.lift(8).map(_.split(",", 3).map(_.toInt)).map(x => (x.lift(0).getOrElse(0),x.lift(1).getOrElse(0),x.lift(2).getOrElse(0))), + values.lift(7) map (_.toInt), + values.lift(8).map(_.split(",", 3).map(_.toInt)).map(x => (x.lift(0).getOrElse(0), x.lift(1).getOrElse(0), x.lift(2).getOrElse(0))), values.lift(9).map(_.toInt), values.lift(10).map(_.split(",").map(_.toInt)).getOrElse(Array()), values.lift(11).map(_.split(",").map(_.toInt)).getOrElse(Array()) -- GitLab