Commit 8bf01dfa authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added fromReference method

parent f9649b70
......@@ -41,8 +41,8 @@ case class BedRecord(chr: String,
else {
val size = length / binNumber
val buffer = ListBuffer[BedRecord]()
for (i <- 1 to binNumber) buffer += BedRecord(chr, start + ((i - 1) * size), start + (i * end))
buffer += BedRecord(chr, start + (binNumber * size), end)
for (i <- 1 until binNumber) buffer += BedRecord(chr, start + ((i - 1) * size), start + (i * size))
buffer += BedRecord(chr, start + ((binNumber - 1) * size), end)
buffer.toList
}
}
......
......@@ -2,8 +2,11 @@ package nl.lumc.sasc.biopet.utils.intervals
import java.io.{ PrintWriter, File }
import htsjdk.samtools.reference.FastaSequenceFile
import htsjdk.samtools.util.Interval
import scala.collection.JavaConversions._
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.Source
......@@ -77,6 +80,10 @@ case class BedRecordList(val chrRecords: Map[String, List[BedRecord]], val heade
})
}
def scatter(binSize: Int) = BedRecordList(
chrRecords.map(x => x._1 -> x._2.flatMap(_.scatter(binSize)))
)
def writeToFile(file: File): Unit = {
val writer = new PrintWriter(file)
header.foreach(writer.println)
......@@ -121,4 +128,12 @@ object BedRecordList {
reader.close()
}
}
def fromReference(file: File) = {
val referenceFile = new FastaSequenceFile(file, true)
fromList(for (contig <- referenceFile.getSequenceDictionary.getSequences) yield {
BedRecord(contig.getSequenceName, 0, contig.getSequenceLength)
})
}
}
\ No newline at end of file
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