Exemple #1
0
 def control_func(preprocess=preprocess, key=key):
     control_bamfile = preprocess.control_bamfile_list[key]
     processed_bam = control_bamfile  #control_bamfile.dirname + "/" + control_bamfile.samplename#+"_preprocessed.bam"
     if control_bamfile.isexist(
     ):  #and control_bamfile.ln(processed_bam, control_bamfile.samplename):
         control_bamfile = BamFile(processed_bam,
                                   control_bamfile.samplename, cfg)
         #control_bamfile.index(cfg["samtools"])
         preprocess.control_bamfile_list[key] = control_bamfile
Exemple #2
0
 def convert2bam(self, out_bam):
     config_dict = self.config_dict
     samtools = config_dict["samtools"]
     info("Running samtools to convert %s SAM File to %s Bam file." %
          (self.path, out_bam))
     cmd = "%s view -bS %s -o %s" % (samtools, self.path, out_bam)
     out_bam = BamFile(out_bam, self.samplename, config_dict)
     if out_bam.isexist():
         savecmd(cmd, self.samplename)
         return (out_bam)
     elif self.isexist():
         if not out_bam.isexist():
             runcmd(cmd)
             savecmd(cmd, self.samplename)
             return (out_bam)
     else:
         info(self.path +
              " is not exists, cannot conduct the convert2bam step!")
Exemple #3
0
def pre_process(options):
    """
    pre_process:Be imported in rnaseq.py, conduct the genome index, fastq mapping, several of bam file preprocess step.
    """
    cfg = get_config(options.config)
    preprocess = PreProcessor(options)
    try:
        genome_process = options.genome_index  #Genomeindex be set in rnaseq.py mode parameter
    except:
        genome_process = 0
    try:
        fastq_mapping = options.fastq_mapping  #fastq_mapping be set in rnaseq.py mode parameter
    except:
        fastq_mapping = 0
    add_read_group = options.bamprocess[0]  # -d --bamprocess 0111
    contig_reorder = options.bamprocess[1]  # 0 or 1
    mark_duplicates = options.bamprocess[2]
    split_ntrim = options.bamprocess[3]
    realigner_target_creator = options.bamprocess[4]
    indel_realigner = options.bamprocess[5]
    recalibration = options.bamprocess[6]
    print_reads = options.bamprocess[7]
    ############# Value equal 0 not to be run, and equal 1 will be run ##########
    if genome_process != "0":
        status = preprocess.genome_pre_process()
    if options.mode == "genomeindex":
        return (status)
    if fastq_mapping != "0":
        preprocess.fastq_mapping()
    #Bam process
    if add_read_group != "0":
        preprocess.add_read_group()
    if contig_reorder != "0":
        preprocess.contig_reorder()
    if mark_duplicates != "0":
        preprocess.mark_duplicates()
    if split_ntrim != "0":
        preprocess.split_ntrim()
    if realigner_target_creator != "0":
        preprocess.realigner_target_creator()
    if indel_realigner != "0":
        preprocess.indel_realigner()
    if recalibration != "0":
        preprocess.recalibration()
    if print_reads != "0":
        preprocess.print_reads()
    #Get copy and rename
    for key in preprocess.bamfile_list.keys():
        bamfile = preprocess.bamfile_list[key]
        processed_bam = bamfile  #.dirname + "/" + bamfile.samplename+"_preprocessed.bam"
        if bamfile.isexist(
        ):  #and bamfile.ln(processed_bam, bamfile.samplename):
            bamfile = BamFile(processed_bam, bamfile.samplename, cfg)
            #bamfile.index(cfg["samtools"])
            preprocess.bamfile_list[key] = bamfile
    return (preprocess.bamfile_list)
Exemple #4
0
 def __init__(self, options):
     FundementalPreprocess.__init__(self, options)
     if options.mode != "genomeindex":
         self.case_bamfile_list = {
             "Bwa":
             BamFile(options.case_in_bam, self.samplename + "A", self.cfg)
         }
         self.control_bamfile_list = {
             "Bwa":
             BamFile(options.control_in_bam, self.samplename + "C",
                     self.cfg)
         }
         self.caseoptions = copy.deepcopy(options)
         self.caseoptions.fastq1 = self.options.case_fastq1
         self.caseoptions.fastq2 = self.options.case_fastq2
         self.caseoptions.samplename = options.samplename + "A"
         self.controloptions = copy.deepcopy(options)
         self.controloptions.fastq1 = options.control_fastq1
         self.controloptions.fastq2 = options.control_fastq2
         self.controloptions.samplename = options.samplename + "C"
Exemple #5
0
def pre_process_self(options):
    """
    pre_process_self:Be useed, when run the module of self, using options.dataprocess to control the step be runned.
    """
    cfg = get_config(options.config)
    preprocess = PreProcessor(options)
    genome_process = options.dataprocess[0]
    fastq_mapping = options.dataprocess[1]
    add_read_group = options.dataprocess[2]
    contig_reorder = options.dataprocess[3]
    mark_duplicates = options.dataprocess[4]
    split_ntrim = options.dataprocess[5]
    realigner_target_creator = options.dataprocess[6]
    indel_realigner = options.dataprocess[7]
    recalibration = options.dataprocess[8]
    print_reads = options.dataprocess[9]
    if genome_process != "0":
        status = preprocess.genome_pre_process()
    if options.mode == "genomeindex":
        return (status)
    if fastq_mapping != "0":
        preprocess.fastq_mapping()
    if add_read_group != "0":
        preprocess.add_read_group()
    if contig_reorder != "0":
        preprocess.contig_reorder()
    if mark_duplicates != "0":
        preprocess.mark_duplicates()
    if split_ntrim != "0":
        preprocess.split_ntrim()
    if realigner_target_creator != "0":
        preprocess.realigner_target_creator()
    if indel_realigner != "0":
        preprocess.indel_realigner()
    if recalibration != "0":
        preprocess.recalibration()
    if print_reads != "0":
        preprocess.print_reads()
    for key in preprocess.bamfile_list.keys():
        bamfile = preprocess.bamfile_list[key]
        processed_bam = bamfile  #bamfile.dirname + "/" + bamfile.samplename#+"_preprocessed.bam"
        if bamfile.isexist(
        ):  #and bamfile.ln(processed_bam, bamfile.samplename):
            bamfile = BamFile(processed_bam, bamfile.samplename, cfg)
            #bamfile.index(cfg["samtools"])
            preprocess.bamfile_list[key] = bamfile
        else:
            info("Not found avaliable bam file in input!")
            return (False)

    return (preprocess.bamfile_list)
Exemple #6
0
 def __init__(self, options):
     FundementalPreprocess.__init__(self, options)
     if options.mode != "genomeindex":
         self.bamfile_list = {
             "Default": BamFile(options.in_bam, self.samplename, self.cfg)
         }