def main(): usage = 'Usage: %prog [-h] [--version] --samplelist [sample list] --config [config file] [options]' description = Rhea_Chip.__description__ author = Rhea_Chip.__author__ version = Rhea_Chip.__version__ parser = OptionParser(usage=usage, version=version, description=description, epilog=author) expect = OptionGroup(parser, 'Expected arguments', 'Caution: These parameters are necessary for Rhea_Chip.') expect.add_option('-s', '--samplelist', metavar='FILE', dest='samplelist', help=r'''The sample list file Column 1: sample name Column 2: family name Column 3: library Column 4: FQ file [formact: lane1/fq1:lane1/adapter1;lane1/fq2:lane1/adapter2| lane2/fq1:lane2/adapter1;lane2/fq2:lane2/adapter2|...] Column 5: case/control''') expect.add_option('-c', '--config', metavar='FILE', dest='config', help='The config file, contain all specific settings') parser.add_option_group(expect) optinal = OptionGroup(parser, 'Optional arguments', 'Caution: If you do not set these parameters in addition,' ' Rhea_Chip will select the default value.') optinal.add_option('-o', '--outdir', dest='outdir', default=os.getcwd(), help='The output dir [ default: %s ]' % os.getcwd()) optinal.add_option('-p', '--project_name', dest='project_name', help='set your project name', default=None) parser.add_option_group(optinal) options, args = parser.parse_args() if not options.samplelist or not options.config: parser.print_help() return 'Expected arguments lost !!!' samplelist = os.path.abspath(options.samplelist) config = os.path.abspath(options.config) outdir = os.path.abspath(options.outdir) logger.info("Rhea_Chip Tasks initialization !") logger.info("Parser the setting config file !") baseconfig = ParserConfig(config) config_stat = baseconfig.config_check() if config_stat != "Success": return config_stat logger.info("Parser the Sample list file !") samples = SampleMessageParser(samplelist) logger.info("Total {0} sample(s) in our analysis !".format(len(samples))) prepair_dir = FolderMaker(outdir) logger.info("Create the whole working directory !") prepair_dir.create_subdirectory(['alignment', 'doc', 'doc/QC', 'fq', 'fq/raw_data', 'cnv', 'fq/clean_data', 'javatmp', 'script', 'variation', 'annotation']) baseconfig.config_save(os.path.join(outdir, 'doc', 'Rhea_Chip.conf')) job_client = process(samples, baseconfig.handle, prepair_dir) open(os.path.join(outdir, 'doc', 'Rhea_Chip.log'), "wb").write(open(LogFile, "rb").read()) if samplelist != os.path.join(outdir, 'doc', 'sample.list'): open(os.path.join(outdir, 'doc', 'sample.list'), "wb").write(open(samplelist, "rb").read()) return "All scripts have been generated, Next, please run : %s" % job_client
def __init__(self, **kwargs): self.region = os.path.abspath(kwargs["region"]) sample_f = os.path.abspath(kwargs["samplelist"]) depth_dir = os.path.abspath( kwargs["depths"] ) if kwargs["depths"] is not None else os.path.join( os.path.dirname(sample_f), 'QC') self.reference = os.path.abspath(kwargs["reference"]) self.rmsk = os.path.abspath(kwargs["repeatdb"]) self.outdir = os.path.abspath(kwargs["outdir"]) self.script = os.path.join(self.outdir, 'script') self.log = os.path.join(self.script, 'log') self.winlen = int(kwargs["winlen"]) or 30 self.siftlen = int(kwargs["siftlen"]) or 25 self.SamplesDepth = dict() self.contigs = set() self.databases = os.path.abspath(kwargs["dbdir"]) self.plot = kwargs["plot"] samples = set() with smart_open(sample_f) as sam: for line in sam: if line.startswith("#"): continue sample_name = str(line.strip().split()[0]) samples.add(sample_name) dep = os.path.join( depth_dir, "{0}/depthAnno/Flank/{0}.Rmdup.depth.tsv.gz".format( sample_name)) self.SamplesDepth[sample_name] = dep if len(samples) <= 5: raise IOError('Sorry, Six or more samples are needed !!!') self.samples = sorted(samples) with smart_open(self.region) as bed: for line in bed: if line.startswith("#"): continue chrom_name = str(line.strip().split()[0]) self.contigs.add(chrom_name) prepair_dir = FolderMaker(self.outdir) prepair_dir.create_subdirectory(self.samples) if not os.path.isdir(self.script): os.makedirs(self.script)
def __init__(self, **kwargs): self.region = os.path.abspath(kwargs["region"]) sample_f = os.path.abspath(kwargs["samplelist"]) depth_dir = os.path.abspath(kwargs["depths"]) if kwargs["depths"] is not None else os.path.join( os.path.dirname(sample_f), 'QC') self.reference = os.path.abspath(kwargs["reference"]) self.rmsk = os.path.abspath(kwargs["repeatdb"]) self.outdir = os.path.abspath(kwargs["outdir"]) self.script = os.path.join(self.outdir, 'script') self.log = os.path.join(self.script, 'log') self.winlen = int(kwargs["winlen"]) or 30 self.siftlen = int(kwargs["siftlen"]) or 25 self.SamplesDepth = dict() self.contigs = set() self.databases = os.path.abspath(kwargs["dbdir"]) self.plot = kwargs["plot"] samples = set() with smart_open(sample_f) as sam: for line in sam: if line.startswith("#"): continue sample_name = str(line.strip().split()[0]) samples.add(sample_name) dep = os.path.join(depth_dir, "{0}/depthAnno/Flank/{0}.Rmdup.depth.tsv.gz".format(sample_name)) self.SamplesDepth[sample_name] = dep if len(samples) <= 5: raise IOError('Sorry, Six or more samples are needed !!!') self.samples = sorted(samples) with smart_open(self.region) as bed: for line in bed: if line.startswith("#"): continue chrom_name = str(line.strip().split()[0]) self.contigs.add(chrom_name) prepair_dir = FolderMaker(self.outdir) prepair_dir.create_subdirectory(self.samples) if not os.path.isdir(self.script): os.makedirs(self.script)
def main(): usage = 'Usage: %prog [-h] [--version] --target [target bed] -b [bam file] -r [ref seq] [options]' description = Rhea_Chip.__description__ author = Rhea_Chip.__author__ version = Rhea_Chip.__version__ parser = OptionParser(usage=usage, version=version, description=description, epilog=author) expect = OptionGroup(parser, 'Expected arguments', 'Caution: These parameters are necessary for depthQC.') expect.add_option('-b', '--bam', metavar='FILE', dest='bam', help='bam file') expect.add_option('-r', '--reference', metavar='FILE', dest='reference', help='humman reference') expect.add_option('--target', metavar='FILE', dest='target', help='target bed region file') parser.add_option_group(expect) optinal = OptionGroup(parser, 'Optional arguments', 'Caution: If you do not set these parameters in addition,' ' depthQC will select the default value.') optinal.add_option('-o', '--outdir', dest='outdir', default=os.getcwd(), help='The output dir [ default: %s ]' % os.getcwd()) optinal.add_option('-t', '--threads', dest='threads', default=0, help='The max threads [ default: <cpus> ], only use in plot exon graph') optinal.add_option('--flank', dest='flank', default=None, help='Flank bed region file [ default: None ]') optinal.add_option('--trans', dest='trans', default=None, help='Trans list file [ default: None ]') optinal.add_option('--genes', dest='genes', default=None, help='Genes list file [ default: None ]') optinal.add_option('-p', '--plot', help='Plot exon depth graph', dest='plot', default=False, action="store_true") parser.add_option_group(optinal) (options, args) = parser.parse_args() if not options.bam or not options.reference or not options.target: parser.print_help() return 'Expected arguments lost !!!' bam = os.path.abspath(options.bam) reference = os.path.abspath(options.reference) target = os.path.abspath(options.target) outdir = os.path.abspath(options.outdir) threads = int(options.threads) flank = os.path.abspath(options.flank) if options.flank else None trans = os.path.abspath(options.trans) if options.trans else None genes = os.path.abspath(options.genes) if options.genes else None plot = options.plot assert trans or genes, "Genes and Trans must set one ~" prepair_dir = FolderMaker(outdir) subdir = ["depthAnno", "depthAnno/Target"] if flank: subdir.append("depthAnno/Flank") if plot: prepair_dir.create_subdirectory(["graph_exon"]) prepair_dir.create_subdirectory(subdir) depths = BamDepth(bam, reference) sample = depths.name depths.depths(target, prefix=os.path.join(outdir, "depthAnno/Target", sample + '.Rmdup')) depths.depths(target, prefix=os.path.join(outdir, "depthAnno/Target", sample + '.Raw'), read_filter="nofilter") if flank: depths.depths(flank, prefix=os.path.join(outdir, "depthAnno/Flank", sample + '.Rmdup')) depths.depths(target, prefix=os.path.join(outdir, "depthAnno/Flank", sample + '.Raw'), read_filter="nofilter") depths.__del__() uncovers = glob(os.path.join(outdir, 'depthAnno', "*", sample + ".Rmdup.uncover.bed")) bedanno = BedAnno(reference=reference, trans=trans, genes=genes) for bed in uncovers: file_out = re.sub("\.bed$", ".anno", bed) bedanno.bedanno(bed, fileout=file_out) if plot: depth_f = os.path.join(outdir, "depthAnno/Target", sample + '.Rmdup.depth.tsv.gz') exon_graph(depth=depth_f, refseq=bedanno.refdb, prefix=sample, outdir=os.path.join(outdir, "graph_exon"), trans=trans, genes=genes, threads=threads) bedanno.__del__()
def main(): usage = 'Usage: %prog [-h] [--version] --samplelist [sample list] --config [config file] [options]' description = Rhea_Chip.__description__ author = Rhea_Chip.__author__ version = Rhea_Chip.__version__ parser = OptionParser(usage=usage, version=version, description=description, epilog=author) expect = OptionGroup( parser, 'Expected arguments', 'Caution: These parameters are necessary for Rhea_Chip.') expect.add_option('-s', '--samplelist', metavar='FILE', dest='samplelist', help=r'''The sample list file Column 1: sample name Column 2: family name Column 3: library Column 4: FQ file [formact: lane1/fq1:lane1/adapter1;lane1/fq2:lane1/adapter2| lane2/fq1:lane2/adapter1;lane2/fq2:lane2/adapter2|...] Column 5: case/control''') expect.add_option('-c', '--config', metavar='FILE', dest='config', help='The config file, contain all specific settings') parser.add_option_group(expect) optinal = OptionGroup( parser, 'Optional arguments', 'Caution: If you do not set these parameters in addition,' ' Rhea_Chip will select the default value.') optinal.add_option('-o', '--outdir', dest='outdir', default=os.getcwd(), help='The output dir [ default: %s ]' % os.getcwd()) optinal.add_option('-p', '--project_name', dest='project_name', help='set your project name', default=None) parser.add_option_group(optinal) options, args = parser.parse_args() if not options.samplelist or not options.config: parser.print_help() return 'Expected arguments lost !!!' samplelist = os.path.abspath(options.samplelist) config = os.path.abspath(options.config) outdir = os.path.abspath(options.outdir) logger.info("Rhea_Chip Tasks initialization !") logger.info("Parser the setting config file !") baseconfig = ParserConfig(config) config_stat = baseconfig.config_check() if config_stat != "Success": return config_stat logger.info("Parser the Sample list file !") samples = SampleMessageParser(samplelist) logger.info("Total {0} sample(s) in our analysis !".format(len(samples))) prepair_dir = FolderMaker(outdir) logger.info("Create the whole working directory !") prepair_dir.create_subdirectory([ 'alignment', 'doc', 'doc/QC', 'fq', 'fq/raw_data', 'cnv', 'fq/clean_data', 'javatmp', 'script', 'variation', 'annotation' ]) baseconfig.config_save(os.path.join(outdir, 'doc', 'Rhea_Chip.conf')) job_client = process(samples, baseconfig.handle, prepair_dir) open(os.path.join(outdir, 'doc', 'Rhea_Chip.log'), "wb").write(open(LogFile, "rb").read()) if samplelist != os.path.join(outdir, 'doc', 'sample.list'): open(os.path.join(outdir, 'doc', 'sample.list'), "wb").write(open(samplelist, "rb").read()) return "All scripts have been generated, Next, please run : %s" % job_client
def main(): usage = 'Usage: %prog [-h] [--version] --target [target bed] -b [bam file] -r [ref seq] [options]' description = Rhea_Chip.__description__ author = Rhea_Chip.__author__ version = Rhea_Chip.__version__ parser = OptionParser(usage=usage, version=version, description=description, epilog=author) expect = OptionGroup( parser, 'Expected arguments', 'Caution: These parameters are necessary for depthQC.') expect.add_option('-b', '--bam', metavar='FILE', dest='bam', help='bam file') expect.add_option('-r', '--reference', metavar='FILE', dest='reference', help='humman reference') expect.add_option('--target', metavar='FILE', dest='target', help='target bed region file') parser.add_option_group(expect) optinal = OptionGroup( parser, 'Optional arguments', 'Caution: If you do not set these parameters in addition,' ' depthQC will select the default value.') optinal.add_option('-o', '--outdir', dest='outdir', default=os.getcwd(), help='The output dir [ default: %s ]' % os.getcwd()) optinal.add_option( '-t', '--threads', dest='threads', default=0, help='The max threads [ default: <cpus> ], only use in plot exon graph' ) optinal.add_option('--flank', dest='flank', default=None, help='Flank bed region file [ default: None ]') optinal.add_option('--trans', dest='trans', default=None, help='Trans list file [ default: None ]') optinal.add_option('--genes', dest='genes', default=None, help='Genes list file [ default: None ]') optinal.add_option('-p', '--plot', help='Plot exon depth graph', dest='plot', default=False, action="store_true") parser.add_option_group(optinal) (options, args) = parser.parse_args() if not options.bam or not options.reference or not options.target: parser.print_help() return 'Expected arguments lost !!!' bam = os.path.abspath(options.bam) reference = os.path.abspath(options.reference) target = os.path.abspath(options.target) outdir = os.path.abspath(options.outdir) threads = int(options.threads) flank = os.path.abspath(options.flank) if options.flank else None trans = os.path.abspath(options.trans) if options.trans else None genes = os.path.abspath(options.genes) if options.genes else None plot = options.plot assert trans or genes, "Genes and Trans must set one ~" prepair_dir = FolderMaker(outdir) subdir = ["depthAnno", "depthAnno/Target"] if flank: subdir.append("depthAnno/Flank") if plot: prepair_dir.create_subdirectory(["graph_exon"]) prepair_dir.create_subdirectory(subdir) depths = BamDepth(bam, reference) sample = depths.name depths.depths(target, prefix=os.path.join(outdir, "depthAnno/Target", sample + '.Rmdup')) depths.depths(target, prefix=os.path.join(outdir, "depthAnno/Target", sample + '.Raw'), read_filter="nofilter") if flank: depths.depths(flank, prefix=os.path.join(outdir, "depthAnno/Flank", sample + '.Rmdup')) depths.depths(target, prefix=os.path.join(outdir, "depthAnno/Flank", sample + '.Raw'), read_filter="nofilter") depths.__del__() uncovers = glob( os.path.join(outdir, 'depthAnno', "*", sample + ".Rmdup.uncover.bed")) bedanno = BedAnno(reference=reference, trans=trans, genes=genes) for bed in uncovers: file_out = re.sub("\.bed$", ".anno", bed) bedanno.bedanno(bed, fileout=file_out) if plot: depth_f = os.path.join(outdir, "depthAnno/Target", sample + '.Rmdup.depth.tsv.gz') exon_graph(depth=depth_f, refseq=bedanno.refdb, prefix=sample, outdir=os.path.join(outdir, "graph_exon"), trans=trans, genes=genes, threads=threads) bedanno.__del__()