Commit 7c0f0bfc authored by Sander Bollen's avatar Sander Bollen

merging in thresholder itself

parent 04801a50
...@@ -16,6 +16,55 @@ ...@@ -16,6 +16,55 @@
# license, please contact us to obtain a separate license. # license, please contact us to obtain a separate license.
# #
import argparse import argparse
import numpy as np
class Thresholder(object):
def __init__(self, filename, threshold):
self.__handle = open(filename)
self.threshold = threshold
self.chrom = None
self.start = None
self.end = None
self.vals = []
def flush(self):
if all([x is not None for x in [self.chrom, self.start, self.end]]):
v = np.median(self.vals)
print("{0}\t{1}\t{2}\t{3}".format(
self.chrom, self.start, self.end, v
))
self.chrom = None
self.start = None
self.end = None
self.vals = []
def next(self):
self.__next__()
def __next__(self):
line = next(self.__handle)
chrom, start, end, value = line.strip().split("\t")
if abs(float(value)) >= self.threshold:
if chrom != self.chrom:
self.flush()
self.chrom = chrom
self.start = start
self.end = end
self.vals = [float(value)]
else:
self.end = end
self.vals.append(float(value))
else:
self.flush()
pass
def __iter__(self):
return self
def close(self):
self.__handle.close()
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
...@@ -23,8 +72,7 @@ if __name__ == "__main__": ...@@ -23,8 +72,7 @@ if __name__ == "__main__":
parser.add_argument("-t", "--threshold", type=int, default=5) parser.add_argument("-t", "--threshold", type=int, default=5)
args = parser.parse_args() args = parser.parse_args()
with open(args.input) as handle: t = Thresholder(args.input, args.threshold)
for line in handle: for _ in t:
value = float(line.strip().split("\t")[-1]) pass
if abs(value) >= args.threshold: t.flush()
print(line) \ No newline at end of file
\ No newline at end of file
...@@ -146,22 +146,16 @@ class Tarmac(val parent: Configurable) extends QScript with PedigreeQscript with ...@@ -146,22 +146,16 @@ class Tarmac(val parent: Configurable) extends QScript with PedigreeQscript with
val windowDir = new File(sample.sampleDir, s"window_$size") val windowDir = new File(sample.sampleDir, s"window_$size")
val thresholder = new BedThreshold(this) val thresholder = new BedThreshold(this)
thresholder.input = job.output thresholder.input = job.output
thresholder.isIntermediate = true thresholder.output = Some(new File(windowDir, s"${sample.sampleId}.threshold.bed"))
thresholder.output = Some(new File(windowDir, s"${sample.sampleId}.threshold-raw.bed"))
thresholder.threshold = threshold thresholder.threshold = threshold
val merger = new BedtoolsMerge(this) size -> thresholder
merger.input = thresholder.output.get
merger.output = new File(windowDir, s"${sample.sampleId}.threshold.bed")
merger.additionalColumns = Some(List(4))
merger.operation = Some("median")
size -> List(thresholder, merger)
} }
sample -> threshSubMap sample -> threshSubMap
} }
_finalFiles = thresholdJobs map { _finalFiles = thresholdJobs map {
case (sample, subMap) => case (sample, subMap) =>
sample -> subMap.values.flatten.collect { case j: BedtoolsMerge => j.output }.toList sample -> subMap.values.flatMap(_.output).toList
} }
addAll(xhmmRefJobs.values.flatMap(_._1)) addAll(xhmmRefJobs.values.flatMap(_._1))
...@@ -171,8 +165,8 @@ class Tarmac(val parent: Configurable) extends QScript with PedigreeQscript with ...@@ -171,8 +165,8 @@ class Tarmac(val parent: Configurable) extends QScript with PedigreeQscript with
addAll(wisecondorSyncJobs.values) addAll(wisecondorSyncJobs.values)
addAll(xhmmSyncJobs.values) addAll(xhmmSyncJobs.values)
addAll(zScoreMergeJobs.values) addAll(zScoreMergeJobs.values)
addAll(windowStouffJobs.values.flatMap(_.values)) addAll(windowStouffJobs.flatMap(_._2).values)
addAll(thresholdJobs.values.flatMap(_.values).flatten) addAll(thresholdJobs.flatMap(_._2).values)
} }
/** /**
......
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