Skip to content

Instantly share code, notes, and snippets.

@hanfeisun
Created July 17, 2012 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanfeisun/3127287 to your computer and use it in GitHub Desktop.
Save hanfeisun/3127287 to your computer and use it in GitHub Desktop.
DC
import sys
import os
from ConfigParser import SafeConfigParser
from jinja2 import Environment, PackageLoader
from chilin.qc import MappingQC, PeakcallingQC
jinja_env = env = Environment(loader=PackageLoader('chilin', 'templates'))
def check_conf(conf):
if True:
return True
else:
return False
class PathFinder:
def __init__(self, conf):
# For more details about config file:
# See http://docsmei.readthedocs.org/en/latest/config_file.html
self.parser = SafeConfigParser()
self.parser.read(conf)
self.datasetID = self.parser.get("meta","dataset.ID")
tmpfolder = lambda self,tool: "%s_%s_tmp".%(self.datasetID, tool)
rstfolder = lambda self,tool: "%s_%s_result".%(self.datasetID, tool)
join_path = os.path.join
def qc_template(self):
return "qc.jinja2"
def macs2_summit(self, rep):
path = "%s_rep%s_summits.bed"%(self.datasetID, rep)
return join_path(rstfolder("macs"),
path)
def macs2_top1k(self):
# For SeqPos
path = "%s_top1000_summits.bed"%(self.datasetID)
return join_path(tmpfolder("macs"),
path)
def raw_fastq(self):
return ""
def mapped_sam(self):
return ""
class LogWriter:
def __init__(self, logfile):
self.logfile = logfile
pass
def info(self.exp):
with open(self.logfile) as lgf:
lgf.write(exp)
class PipeController(object):
def __init__(self, logwriter, conf):
self.logwriter = logwriter
self.pathfinder = PathFinder(conf)
self.parser = SafeConfigParser()
self.parser.read(conf)
def info(self.exp):
# use logwriter to delegate
self.logwriter.info(exp)
def run(self):
pass
class BowtieController(PipeController):
def __init__(self, logwriter, conf):
super(BowtieController, self).__init__
self.mappingqc = MappingQC(conf)
self.bowtie_main = self.parser.get("bowtie","bowtie_main")
self.gene_index = self.parser.get("bowtie","bowtie_genome_index_path")
self.format_option= "-q"
self.max_align = 1
def info(self,exp):
# use logwriter to delegate
self.logwriter.info(exp)
def run(self):
cmd = '{0} -S ${1} -m ${2} ${3} ${4} ${5}'
cmd = cmd.format( self.bowtie_main,
self.format_option,
self.max_align,
self.gene_index,
self.pathfinder.fastqfile(),
self.pathfinder.raw_fastq(),
self.pathfinder.mapped_sam())
print cmd
def render(self):
return self.mappingqc.render()
def check(self):
return self.mappingqc.check()
class MacsController(PipeController):
def __init__(self, logwriter, conf):
super(MacsController, self).__init__
self.peakcallingqc = PeakcallingQC(conf)
def info(self,exp):
self.logwriter.info(exp)
def run(self):
cmd = "demo"
print cmd
def render(self):
return self.peakcallingqc.render()
def check(self):
return self.peakcallingqc.check()
if check_conf("example.conf"):
lg = LogWriter("test.log")
bc = BowtieController("example.conf", lg)
bc.run()
bc.check()
print bc.render()
mc = MacsController("example.conf", lg)
mc.run()
mc.check()
print mc.render()
else:
sys.exit()
@qinqian
Copy link

qinqian commented Jul 17, 2012

great design~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment