def run_smalt_paired(consensus_file, read1_fastq, read2_fastq, **kwarg):
    index1 = '%s.sma' % consensus_file
    command = 'rm -rf %s' % index1
    if os.path.exists(index1):
        return_code = command_runner.run_command(command)
    index2 = '%s.smi' % consensus_file
    command = 'rm -rf %s' % index2
    if os.path.exists(index2):
        return_code = command_runner.run_command(command)
    index3 = '%s.fai' % consensus_file
    command = 'rm -rf %s' % index3
    if os.path.exists(index3):
        return_code = command_runner.run_command(command)

    command = "smalt index %s %s" % (consensus_file, consensus_file)
    return_code = command_runner.run_command(command)
    name = longest_common_substr_from_start(read1_fastq,
                                            read2_fastq).rstrip('_')
    read2_fastq_rev_comp = reverse_complement(read2_fastq)

    sam_file = name + '.sam'
    command = "smalt map -f samsoft -o %s %s %s %s" % (
        sam_file, consensus_file, read1_fastq, read2_fastq_rev_comp)
    return_code = command_runner.run_command(command)
    return sam_file
def run_smalt_paired(consensus_file, read1_fastq, read2_fastq, **kwarg):
    index1 = '%s.sma' % consensus_file
    command = 'rm -rf %s' % index1
    if os.path.exists(index1):
        return_code = command_runner.run_command(command)
    index2 = '%s.smi' % consensus_file
    command = 'rm -rf %s' % index2
    if os.path.exists(index2):
        return_code = command_runner.run_command(command)
    index3 = '%s.fai' % consensus_file
    command = 'rm -rf %s' % index3
    if os.path.exists(index3):
        return_code = command_runner.run_command(command)

    command = "smalt index %s %s" % (consensus_file, consensus_file)
    return_code = command_runner.run_command(command)
    name = longest_common_substr_from_start(read1_fastq, read2_fastq).rstrip('_')
    read2_fastq_rev_comp = reverse_complement(read2_fastq)

    sam_file = name + '.sam'
    command = "smalt map -f samsoft -o %s %s %s %s" % (sam_file, consensus_file, read1_fastq, read2_fastq_rev_comp)
    return_code = command_runner.run_command(command)
    return sam_file
Example #3
0
         run_fine = False
     fastq_file1=fastq_file1_unzip
     files_and_dir.append(fastq_file1)
 if fastq_file2 and fastq_file2.endswith('.gz'):
     fastq_file2_unzip,ext = os.path.splitext(fastq_file2)
     command = 'gunzip -c %s > %s'%(fastq_file2,fastq_file2_unzip)
     return_code = command_runner.run_command(command)
     if return_code is not 0:
         run_fine = False 
     fastq_file2=fastq_file2_unzip
     files_and_dir.append(fastq_file2)
 
 #Get the sample name
 if not sample_name:
     if fastq_file2:
         fastq_common = longest_common_substr_from_start(fastq_file1,fastq_file2)
         #remove trailing underscore _ and get the base name
         sample_name = os.path.basename(fastq_common.rstrip('_'))
     else:
         tmp,ext=os.path.splitext(os.path.basename(fastq_file1))
         tmp=tmp.rstrip('1')
         sample_name = os.path.basename(tmp.rstrip('_'))
 
 BWA_bin=os.path.join(BWA_dir,'bwa')
 # Check bwa version do not allow read group before version 0.9
 if compare_version_number(get_bwa_version(BWA_bin), "0.5.9") <0:
     logging.warning("Your version of bwa does not support the read group. Get version 0.5.9 or later to use this function.")
     read_group_command=''
 else:
     if read_group:
         read_group_command='-r "%s"'%(read_group)
Example #4
0
            run_fine = False
        fastq_file1 = fastq_file1_unzip
        files_and_dir.append(fastq_file1)
    if fastq_file2 and fastq_file2.endswith('.gz'):
        fastq_file2_unzip, ext = os.path.splitext(fastq_file2)
        command = 'gunzip -c %s > %s' % (fastq_file2, fastq_file2_unzip)
        return_code = command_runner.run_command(command)
        if return_code is not 0:
            run_fine = False
        fastq_file2 = fastq_file2_unzip
        files_and_dir.append(fastq_file2)

    #Get the sample name
    if not sample_name:
        if fastq_file2:
            fastq_common = longest_common_substr_from_start(
                fastq_file1, fastq_file2)
            #remove trailing underscore _ and get the base name
            sample_name = os.path.basename(fastq_common.rstrip('_'))
        else:
            tmp, ext = os.path.splitext(os.path.basename(fastq_file1))
            tmp = tmp.rstrip('1')
            sample_name = os.path.basename(tmp.rstrip('_'))

    BWA_bin = os.path.join(BWA_dir, 'bwa')
    # Check bwa version do not allow read group before version 0.9
    if compare_version_number(get_bwa_version(BWA_bin), "0.5.9") < 0:
        logging.warning(
            "Your version of bwa does not support the read group. Get version 0.5.9 or later to use this function."
        )
        read_group_command = ''
    else:
    open_corrected_sam.close()
    return corrected_sam_file


def run_alignment(consensus_file, read1_fastq, read2_fastq, single_fastq, all_read_groups, snp_call=False):
    try:
        pipeline_param = utils_param.get_pipeline_parameters()
        picard_dir = pipeline_param.get_picard_dir()
        # GATK_dir=pipeline_param.get_gatk_dir()
        samtools_dir = pipeline_param.get_samtools_dir()
    except Config_file_error, e:
        logging.exception('Config_file_error:')
        sys.exit(1)

    # Cleanup previous run if it exist
    name = longest_common_substr_from_start(read1_fastq, read2_fastq).rstrip('_')
    clean_up_prev_run(name)

    file_to_remove = []
    sam_file = run_smalt_paired(consensus_file, read1_fastq, read2_fastq)
    file_to_remove.append(sam_file)
    if os.path.exists(single_fastq):
        sam_file_single = run_smalt_single(consensus_file, single_fastq)
        file_to_remove.append(sam_file_single)
        corrected_sam_file = correct_smalt_sam_file(sam_file, all_read_groups, sam_file_single)
    else:
        corrected_sam_file = correct_smalt_sam_file(sam_file, all_read_groups)
    file_to_remove.append(corrected_sam_file)

    name, ext = os.path.splitext(corrected_sam_file)
                  read1_fastq,
                  read2_fastq,
                  single_fastq,
                  all_read_groups,
                  snp_call=False):
    try:
        pipeline_param = utils_param.get_pipeline_parameters()
        picard_dir = pipeline_param.get_picard_dir()
        # GATK_dir=pipeline_param.get_gatk_dir()
        samtools_dir = pipeline_param.get_samtools_dir()
    except Config_file_error, e:
        logging.exception('Config_file_error:')
        sys.exit(1)

    # Cleanup previous run if it exist
    name = longest_common_substr_from_start(read1_fastq,
                                            read2_fastq).rstrip('_')
    clean_up_prev_run(name)

    file_to_remove = []
    sam_file = run_smalt_paired(consensus_file, read1_fastq, read2_fastq)
    file_to_remove.append(sam_file)
    if os.path.exists(single_fastq):
        sam_file_single = run_smalt_single(consensus_file, single_fastq)
        file_to_remove.append(sam_file_single)
        corrected_sam_file = correct_smalt_sam_file(sam_file, all_read_groups,
                                                    sam_file_single)
    else:
        corrected_sam_file = correct_smalt_sam_file(sam_file, all_read_groups)
    file_to_remove.append(corrected_sam_file)

    name, ext = os.path.splitext(corrected_sam_file)