Last active
December 28, 2015 11:19
-
-
Save mpkocher/7492576 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import os | |
from pbsmrtpipe.resource_types import (MovieFofn, BarcodeFofn, BarcodeFasta, | |
MappingCmph5, BarcodeFastq) | |
from pbsmrtpipe.model import (TaskTypes, TaskBase, | |
TaskOption, TaskChoiceOption, | |
P_Module, TempDir) | |
log = logging.getLogger(__name__) | |
class LabelZmwsTask(TaskBase): | |
INPUTS = (MovieFofn, BarcodeFasta) | |
OUTPUTS = BarcodeFofn | |
NPROC = 1 | |
TASK_TYPE = TaskTypes.DistributableTask | |
score_mode = TaskOption('barcode_mode', 'symmetric', str) | |
adapterSidePad = TaskOption('adapterSidePad', 4, int) | |
insertSidePad = TaskOption('insertSidePad', 4, int) | |
fastqType = TaskChoiceOption('readType', 'subreads', str, ('subreads', 'CCS')) | |
def to_cmd(self): | |
mfofn, bfasta = self.inputs[:2] | |
bfofn = self.outputs[0] | |
output_dir = os.path.dirname(bfofn.path) | |
d = dict(n=self.nproc, b=bfofn.path, s=self.score_mode, d=output_dir, | |
a=self.adapterSidePad, i=self.insertSidePad, fa=bfasta.path, | |
m=mfofn.path) | |
cmd = "pbbarcode.py -vv labelZMWs --nProcs {n} --outFofn {b} --outDir {d} --scoreMode {s} --adapterSidePad {a} --insertSidePad {i} {fa} {m}" | |
return cmd.format(**d) | |
class CopyBarcodesToCmpH5Task(TaskBase): | |
INPUTS = (BarcodeFofn, MappingCmph5) | |
OUTPUTS = MappingCmph5WithBarcode | |
NPROC = 1 | |
TASK_TYPE = TaskTypes.LocallyDistributableTask | |
def to_cmd(self): | |
d = dict(f=self.inputs[0].path, a=self.inputs[1].path) | |
return "pbbarcode.py labelAlignments {f} {a}".format(**d) | |
class EmitFastqTask(TaskBase): | |
INPUTS = (MovieFofn, BarcodeFofn) | |
OUTPUTS = BarcodeFastq | |
NPROC = 1 | |
TASK_TYPE = TaskTypes.LocallyDistributableTask | |
TMP_DIR = TempDir('barcode_fqs_tmp') | |
def to_cmd(self): | |
mfofn, bfofn = self.inputs[:2] | |
fastq = self.outputs[0] | |
output_dir = fastq.path.replace(".") | |
d = dict(m=mfofn.path, b=bfofn.path, fq=fastq.path) | |
cmds = [] | |
cmds.append("mkdir {s}".format(s=output_dir) | |
cmds.append("pbbarcode.py emitFastqs {s} --outDir {o} {b} {q}".format(o=output_dir, b=bfofn.path, q=fastq.path) | |
cmds.append("pushd %s && tar czf ../%s *.fastq && popd") | |
return cmds | |
class P_Barcode(P_Module): | |
TASKS = (LabelZmwsTask, CopyBarcodesToCmpH5Task, EmitFastqTask) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment