Commit 8360ae8d authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Replace getSequence for getContig

parent fa935dce
...@@ -102,7 +102,7 @@ object ExtractAlignedFastq extends ToolCommand { ...@@ -102,7 +102,7 @@ object ExtractAlignedFastq extends ToolCommand {
val queries: Array[QueryInterval] = iv.toList val queries: Array[QueryInterval] = iv.toList
// transform to QueryInterval // transform to QueryInterval
.map(x => new QueryInterval(getSequenceIndex(x.getSequence), x.getStart, x.getEnd)) .map(x => new QueryInterval(getSequenceIndex(x.getContig), x.getStart, x.getEnd))
// sort Interval // sort Interval
.sortBy(x => (x.referenceIndex, x.start, x.end)) .sortBy(x => (x.referenceIndex, x.start, x.end))
// cast to array // cast to array
......
...@@ -358,7 +358,7 @@ object VcfStats extends ToolCommand { ...@@ -358,7 +358,7 @@ object VcfStats extends ToolCommand {
logger.info("Starting on: " + interval) logger.info("Starting on: " + interval)
for ( for (
record <- reader.query(interval.getSequence, interval.getStart, interval.getEnd) if record.getStart <= interval.getEnd record <- reader.query(interval.getContig, interval.getStart, interval.getEnd) if record.getStart <= interval.getEnd
) { ) {
mergeNestedStatsMap(stats.generalStats, checkGeneral(record, adInfoTags)) mergeNestedStatsMap(stats.generalStats, checkGeneral(record, adInfoTags))
for (sample1 <- samples) yield { for (sample1 <- samples) yield {
...@@ -376,7 +376,7 @@ object VcfStats extends ToolCommand { ...@@ -376,7 +376,7 @@ object VcfStats extends ToolCommand {
reader.close() reader.close()
if (commandArgs.writeBinStats) { if (commandArgs.writeBinStats) {
val binOutputDir = new File(commandArgs.outputDir, "bins" + File.separator + interval.getSequence) val binOutputDir = new File(commandArgs.outputDir, "bins" + File.separator + interval.getContig)
writeGenotypeField(stats, samples, "general", binOutputDir, prefix = "genotype-" + interval.getStart + "-" + interval.getEnd) writeGenotypeField(stats, samples, "general", binOutputDir, prefix = "genotype-" + interval.getStart + "-" + interval.getEnd)
writeField(stats, "general", binOutputDir, prefix = interval.getStart + "-" + interval.getEnd) writeField(stats, "general", binOutputDir, prefix = interval.getStart + "-" + interval.getEnd)
...@@ -439,7 +439,7 @@ object VcfStats extends ToolCommand { ...@@ -439,7 +439,7 @@ object VcfStats extends ToolCommand {
} }
protected def writeWiggle(intervals: List[Interval], row: String, column: String, outputFile: File, genotype: Boolean): Unit = { protected def writeWiggle(intervals: List[Interval], row: String, column: String, outputFile: File, genotype: Boolean): Unit = {
val groupedIntervals = intervals.groupBy(_.getSequence).map { case (k, v) => k -> v.sortBy(_.getStart) } val groupedIntervals = intervals.groupBy(_.getContig).map { case (k, v) => k -> v.sortBy(_.getStart) }
outputFile.getParentFile.mkdirs() outputFile.getParentFile.mkdirs()
val writer = new PrintWriter(outputFile) val writer = new PrintWriter(outputFile)
writer.println("track type=wiggle_0") writer.println("track type=wiggle_0")
......
...@@ -149,12 +149,12 @@ object WipeReads extends ToolCommand { ...@@ -149,12 +149,12 @@ object WipeReads extends ToolCommand {
throw new IllegalArgumentException("Unexpected interval file type: " + inFile.getPath) throw new IllegalArgumentException("Unexpected interval file type: " + inFile.getPath)
iterFunc(inFile).toList iterFunc(inFile).toList
.sortBy(x => (x.getSequence, x.getStart, x.getEnd)) .sortBy(x => (x.getContig, x.getStart, x.getEnd))
.foldLeft(List.empty[Interval])( .foldLeft(List.empty[Interval])(
(acc, x) => { (acc, x) => {
acc match { acc match {
case head :: tail if x.intersects(head) => case head :: tail if x.intersects(head) =>
new Interval(x.getSequence, min(x.getStart, head.getStart), max(x.getEnd, head.getEnd)) :: tail new Interval(x.getContig, min(x.getStart, head.getStart), max(x.getEnd, head.getEnd)) :: tail
case _ => x :: acc case _ => x :: acc
} }
} }
...@@ -193,16 +193,16 @@ object WipeReads extends ToolCommand { ...@@ -193,16 +193,16 @@ object WipeReads extends ToolCommand {
*/ */
def makeQueryInterval(in: SamReader, iv: Interval): Option[QueryInterval] = { def makeQueryInterval(in: SamReader, iv: Interval): Option[QueryInterval] = {
val getIndex = in.getFileHeader.getSequenceIndex _ val getIndex = in.getFileHeader.getSequenceIndex _
if (getIndex(iv.getSequence) > -1) if (getIndex(iv.getContig) > -1)
Some(new QueryInterval(getIndex(iv.getSequence), iv.getStart, iv.getEnd)) Some(new QueryInterval(getIndex(iv.getContig), iv.getStart, iv.getEnd))
else if (iv.getSequence.startsWith("chr") && getIndex(iv.getSequence.substring(3)) > -1) { else if (iv.getContig.startsWith("chr") && getIndex(iv.getContig.substring(3)) > -1) {
logger.warn("Removing 'chr' prefix from interval " + iv.toString) logger.warn("Removing 'chr' prefix from interval " + iv.toString)
Some(new QueryInterval(getIndex(iv.getSequence.substring(3)), iv.getStart, iv.getEnd)) Some(new QueryInterval(getIndex(iv.getContig.substring(3)), iv.getStart, iv.getEnd))
} else if (!iv.getSequence.startsWith("chr") && getIndex("chr" + iv.getSequence) > -1) { } else if (!iv.getContig.startsWith("chr") && getIndex("chr" + iv.getContig) > -1) {
logger.warn("Adding 'chr' prefix to interval " + iv.toString) logger.warn("Adding 'chr' prefix to interval " + iv.toString)
Some(new QueryInterval(getIndex("chr" + iv.getSequence), iv.getStart, iv.getEnd)) Some(new QueryInterval(getIndex("chr" + iv.getContig), iv.getStart, iv.getEnd))
} else { } else {
logger.warn("Sequence " + iv.getSequence + " does not exist in alignment") logger.warn("Sequence " + iv.getContig + " does not exist in alignment")
None None
} }
} }
......
...@@ -58,7 +58,7 @@ class ExtractAlignedFastqTest extends TestNGSuite with MockitoSugar with Matcher ...@@ -58,7 +58,7 @@ class ExtractAlignedFastqTest extends TestNGSuite with MockitoSugar with Matcher
@Test def testIntervalStartEnd() = { @Test def testIntervalStartEnd() = {
val obs = makeIntervalFromString(List("chr5:1000-1100")).next() val obs = makeIntervalFromString(List("chr5:1000-1100")).next()
val exp = new Interval("chr5", 1000, 1100) val exp = new Interval("chr5", 1000, 1100)
obs.getSequence should ===(exp.getSequence) obs.getContig should ===(exp.getContig)
obs.getStart should ===(exp.getStart) obs.getStart should ===(exp.getStart)
obs.getEnd should ===(exp.getEnd) obs.getEnd should ===(exp.getEnd)
} }
...@@ -66,7 +66,7 @@ class ExtractAlignedFastqTest extends TestNGSuite with MockitoSugar with Matcher ...@@ -66,7 +66,7 @@ class ExtractAlignedFastqTest extends TestNGSuite with MockitoSugar with Matcher
@Test def testIntervalStartEndComma() = { @Test def testIntervalStartEndComma() = {
val obs = makeIntervalFromString(List("chr5:1,000-1,100")).next() val obs = makeIntervalFromString(List("chr5:1,000-1,100")).next()
val exp = new Interval("chr5", 1000, 1100) val exp = new Interval("chr5", 1000, 1100)
obs.getSequence should ===(exp.getSequence) obs.getContig should ===(exp.getContig)
obs.getStart should ===(exp.getStart) obs.getStart should ===(exp.getStart)
obs.getEnd should ===(exp.getEnd) obs.getEnd should ===(exp.getEnd)
} }
...@@ -74,7 +74,7 @@ class ExtractAlignedFastqTest extends TestNGSuite with MockitoSugar with Matcher ...@@ -74,7 +74,7 @@ class ExtractAlignedFastqTest extends TestNGSuite with MockitoSugar with Matcher
@Test def testIntervalStartEndDot() = { @Test def testIntervalStartEndDot() = {
val obs = makeIntervalFromString(List("chr5:1.000-1.100")).next() val obs = makeIntervalFromString(List("chr5:1.000-1.100")).next()
val exp = new Interval("chr5", 1000, 1100) val exp = new Interval("chr5", 1000, 1100)
obs.getSequence should ===(exp.getSequence) obs.getContig should ===(exp.getContig)
obs.getStart should ===(exp.getStart) obs.getStart should ===(exp.getStart)
obs.getEnd should ===(exp.getEnd) obs.getEnd should ===(exp.getEnd)
} }
...@@ -82,7 +82,7 @@ class ExtractAlignedFastqTest extends TestNGSuite with MockitoSugar with Matcher ...@@ -82,7 +82,7 @@ class ExtractAlignedFastqTest extends TestNGSuite with MockitoSugar with Matcher
@Test def testIntervalStart() = { @Test def testIntervalStart() = {
val obs = makeIntervalFromString(List("chr5:1000")).next() val obs = makeIntervalFromString(List("chr5:1000")).next()
val exp = new Interval("chr5", 1000, 1000) val exp = new Interval("chr5", 1000, 1000)
obs.getSequence should ===(exp.getSequence) obs.getContig should ===(exp.getContig)
obs.getStart should ===(exp.getStart) obs.getStart should ===(exp.getStart)
obs.getEnd should ===(exp.getEnd) obs.getEnd should ===(exp.getEnd)
} }
......
...@@ -140,10 +140,10 @@ class WipeReadsTest extends TestNGSuite with MockitoSugar with Matchers { ...@@ -140,10 +140,10 @@ class WipeReadsTest extends TestNGSuite with MockitoSugar with Matchers {
@Test def testMakeIntervalFromBed() = { @Test def testMakeIntervalFromBed() = {
val intervals: List[Interval] = makeIntervalFromFile(BedFile1) val intervals: List[Interval] = makeIntervalFromFile(BedFile1)
intervals.length shouldBe 3 intervals.length shouldBe 3
intervals.head.getSequence should ===("chrQ") intervals.head.getContig should ===("chrQ")
intervals.head.getStart shouldBe 991 intervals.head.getStart shouldBe 991
intervals.head.getEnd shouldBe 1000 intervals.head.getEnd shouldBe 1000
intervals.last.getSequence should ===("chrQ") intervals.last.getContig should ===("chrQ")
intervals.last.getStart shouldBe 291 intervals.last.getStart shouldBe 291
intervals.last.getEnd shouldBe 320 intervals.last.getEnd shouldBe 320
} }
...@@ -151,13 +151,13 @@ class WipeReadsTest extends TestNGSuite with MockitoSugar with Matchers { ...@@ -151,13 +151,13 @@ class WipeReadsTest extends TestNGSuite with MockitoSugar with Matchers {
@Test def testMakeIntervalFromRefFlat() = { @Test def testMakeIntervalFromRefFlat() = {
val intervals: List[Interval] = makeIntervalFromFile(RefFlatFile1) val intervals: List[Interval] = makeIntervalFromFile(RefFlatFile1)
intervals.length shouldBe 5 intervals.length shouldBe 5
intervals.head.getSequence should ===("chrS") intervals.head.getContig should ===("chrS")
intervals.head.getStart shouldBe 101 intervals.head.getStart shouldBe 101
intervals.head.getEnd shouldBe 500 intervals.head.getEnd shouldBe 500
intervals(2).getSequence should ===("chrQ") intervals(2).getContig should ===("chrQ")
intervals(2).getStart shouldBe 801 intervals(2).getStart shouldBe 801
intervals(2).getEnd shouldBe 1000 intervals(2).getEnd shouldBe 1000
intervals.last.getSequence should ===("chrQ") intervals.last.getContig should ===("chrQ")
intervals.last.getStart shouldBe 101 intervals.last.getStart shouldBe 101
intervals.last.getEnd shouldBe 200 intervals.last.getEnd shouldBe 200
} }
...@@ -165,10 +165,10 @@ class WipeReadsTest extends TestNGSuite with MockitoSugar with Matchers { ...@@ -165,10 +165,10 @@ class WipeReadsTest extends TestNGSuite with MockitoSugar with Matchers {
@Test def testMakeIntervalFromGtf() = { @Test def testMakeIntervalFromGtf() = {
val intervals: List[Interval] = makeIntervalFromFile(GtfFile1, "exon") val intervals: List[Interval] = makeIntervalFromFile(GtfFile1, "exon")
intervals.length shouldBe 3 intervals.length shouldBe 3
intervals.head.getSequence should ===("chrQ") intervals.head.getContig should ===("chrQ")
intervals.head.getStart shouldBe 669 intervals.head.getStart shouldBe 669
intervals.head.getEnd shouldBe 778 intervals.head.getEnd shouldBe 778
intervals.last.getSequence should ===("chrP") intervals.last.getContig should ===("chrP")
intervals.last.getStart shouldBe 2949 intervals.last.getStart shouldBe 2949
intervals.last.getEnd shouldBe 3063 intervals.last.getEnd shouldBe 3063
} }
...@@ -176,10 +176,10 @@ class WipeReadsTest extends TestNGSuite with MockitoSugar with Matchers { ...@@ -176,10 +176,10 @@ class WipeReadsTest extends TestNGSuite with MockitoSugar with Matchers {
@Test def testMakeIntervalFromBedOverlap() = { @Test def testMakeIntervalFromBedOverlap() = {
val intervals: List[Interval] = makeIntervalFromFile(BedFile2) val intervals: List[Interval] = makeIntervalFromFile(BedFile2)
intervals.length shouldBe 4 intervals.length shouldBe 4
intervals.head.getSequence should ===("chrQ") intervals.head.getContig should ===("chrQ")
intervals.head.getStart shouldBe 451 intervals.head.getStart shouldBe 451
intervals.head.getEnd shouldBe 480 intervals.head.getEnd shouldBe 480
intervals.last.getSequence should ===("chrQ") intervals.last.getContig should ===("chrQ")
intervals.last.getStart shouldBe 2 intervals.last.getStart shouldBe 2
intervals.last.getEnd shouldBe 250 intervals.last.getEnd shouldBe 250
} }
......
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