Пример #1
0
def archive_demux_stat(run_id, fastq_output_dir, reports_data_path, basecall_stats_file,
                       basecall_stats_prefix, samplesheet_csv_path, conf):
    """ Archive demultplexing statistics results file.

    Arguments:
        run_id: The run id
        fastq_output_dir: fastq directory to save result on demultiplexing
        reports_data_path: directory to save archives
        basecall_stats_file: file to archive
        basecall_stats_prefix: prefix file to archive
        samplesheet_csv_path: samplesheet in csv
        conf: configuration dictionary
    """

    archive_run_dirname = basecall_stats_prefix + run_id
    archive_run_dir = reports_data_path + '/' + archive_run_dirname
    archive_run_tar_file = reports_data_path + '/' + basecall_stats_file

    # With bcl2fastq 2
    cmd_list = []
    cmd_list.extend(['cd', quote(fastq_output_dir), '&&'])
    cmd_list.extend(['mkdir', quote(archive_run_dir), '&&'])
    cmd_list.extend(['cp', '-r', 'Reports', 'Stats', 'InterOp', quote(samplesheet_csv_path), quote(archive_run_dir), '&&'])
    cmd_list.extend(['tar cjf', quote(archive_run_tar_file), '-C', quote(reports_data_path), quote(archive_run_dirname)])

    cmd = " ".join(cmd_list)

    common.log("INFO", "exec: " + cmd, conf)
    if os.system(cmd) != 0:
        error("Error while saving the basecall stats files for " + run_id,
              'Error while saving the basecall stats files.\nCommand line:\n' + cmd, conf)
        return False

    # Set read only basecall stats archives files
    common.chmod(archive_run_tar_file, conf)


    return True
Пример #2
0
def create_run_summary_reports(run_id, conf):
    """ Copy main files and directory from hiseq run directory to save in report run data directory.
        Save data in two distinct directory on hiseq and on report, and tar.bz2 version

    Arguments:
        run_id: the run id
        conf: configuration dictionary
    """

    hiseq_data_path = hiseq_run.find_hiseq_run_path(run_id, conf)
    tmp_base_path = conf[TMP_PATH_KEY]
    reports_data_base_path = conf[REPORTS_DATA_PATH_KEY]

    source_path = hiseq_data_path + '/' + run_id
    reports_data_path = common.get_report_run_data_path(run_id, conf)
    report_prefix = 'report_'
    hiseq_log_prefix = 'hiseq_log_'
    report_archive_file = report_prefix + run_id + '.tar.bz2'
    hiseq_log_archive_file = hiseq_log_prefix + run_id + '.tar.bz2'

    # Save quality control data
    tmp_path = tmp_base_path + '/' + run_id

    # Check if reports_data_path exists
    if not os.path.exists(reports_data_base_path):
        error("Failed to create report archive: Report directory does not exist",
              "Failed to create report archive: Report directory does not exist: " + reports_data_base_path, conf)
        return False

    # Check if temporary directory exists
    if not os.path.exists(tmp_base_path):
        error("Failed to create report archive: Temporary directory does not exist",
              "Failed to create report archive: Temporary directory does not exist: " + tmp_base_path, conf)
        return False

    # Check if reports archive exists
    if os.path.exists(reports_data_path + '/' + report_archive_file):
        error("Failed to create report archive: Report archive already exists for run " + run_id,
              "Failed to create report archive: Report archive already exists for run " + run_id + " : " + report_archive_file, conf)
        return False

    # Check if hiseq log archive exists
    if os.path.exists(reports_data_path + '/' + hiseq_log_archive_file):
        error("Failed to create report archive: Hiseq log archive already exists for run " + run_id,
              "Failed to create report archive: Hiseq log archive already exists for run " + run_id + " : " + hiseq_log_archive_file, conf)
        return False

    # Create if not exist archive directory for the run
    if not os.path.exists(reports_data_path):
        os.mkdir(reports_data_path)

    # Create run tmp  directory
    if os.path.exists(tmp_path):
        error("Failed to create report archive: Temporary run data directory already exists for run " + run_id,
              "Failed to create report archive: Temporary run data directory already exists for run " + run_id + " : " + hiseq_log_archive_file, conf)
    else:
        os.mkdir(tmp_path)

    # Define set file to copy in report archive, check if exists (depend on parameters Illumina)
    files = ['InterOp', 'RunInfo.xml', 'runParameters.xml', 'RunParameters.xml']
    files_to_copy = list_existing_files(source_path, files)

    if len(files_to_copy) == 0:
        common.log("WARNING",
                   "Archive " + hiseq_log_archive_file + " not created: none file exists " + str(files) +
                   ' in ' + source_path, conf)
    else:
        cmd = 'cd ' + quote(source_path) + ' && ' + \
              'cp -rp ' + files_to_copy + ' ' + quote(tmp_path) + ' && ' + \
              'cd ' + quote(tmp_base_path) + ' && ' + \
              'mv ' + quote(run_id) + ' ' + quote(hiseq_log_prefix + run_id) + ' && ' + \
              'tar cjf ' + quote(reports_data_path + '/' + hiseq_log_archive_file) + ' ' + quote(hiseq_log_prefix + run_id) + ' && ' +\
              'rm -rf ' + quote(tmp_path)
        # + ' && rm -rf ' + hiseq_log_prefix + run_id

        common.log("INFO", "exec: " + cmd, conf)
        if os.system(cmd) != 0:
            error("Failed to create report archive: Error while saving Illumina quality control for run " + run_id,
                  "Failed to create report archive: Error saving Illumina quality control.\nCommand line:\n" + cmd, conf)
            return False

    # Save html reports
    if os.path.exists(tmp_path):
        cmd = 'rm -rf ' + quote(tmp_path)

        common.log("INFO", "exec: " + cmd, conf)
        if os.system(cmd) != 0:
            error("Failed to create report archive: Error while removing existing temporary directory",
                  "Failed to create report archive: Error while removing existing temporary directory.\nCommand line:\n" + cmd, conf)
            return False

    os.mkdir(tmp_path)

    # Define set file to copy in report archive, check if exists (depend on parameters Illumina)
    if common.get_rta_major_version(run_id, conf) == 1:
        files = ['./Data/Status_Files', './Data/reports', './Data/Status.htm', './First_Base_Report.htm']
    else:
        files = ['./Config', './Recipe', './RTALogs', './RTAConfiguration.xml', './RunCompletionStatus.xml']

    files_to_copy = list_existing_files(source_path, files)
    if len(files_to_copy) == 0:
        common.log("WARNING", "Archive " + report_archive_file + " not created: none file exists " + str(
            files) + ' in ' + source_path, conf)
    else:
        cmd = 'cd ' + quote(source_path) + ' && ' + \
              'cp -rp ' + files_to_copy + ' ' + quote(tmp_path) + ' && ' + \
              'cd ' + quote(tmp_base_path) + ' && ' + \
              'mv ' + quote(run_id) + ' ' + quote(report_prefix + run_id) + ' && ' + \
              'tar cjf ' + quote(reports_data_path + '/' + report_archive_file) + ' ' + quote(report_prefix + run_id) + ' && ' + \
              'mv ' + quote(report_prefix + run_id) + ' ' + quote(reports_data_path)

        common.log("INFO", "exec: " + cmd, conf)
        if os.system(cmd) != 0:
            error("Failed to create report archive: Error while saving Illumina HTML reports for run " + run_id,
                  "Failed to create report archive: Error saving Illumina HTML reports.\nCommand line:\n" + cmd, conf)
            return False

    # Create index.hml file
    common.create_html_index_file(conf, run_id, [HISEQ_STEP_KEY])

    # Set read only the report directory
    common.chmod_files_in_dir(reports_data_path + '/' + report_prefix, None, conf)

    # Set read only archives files
    common.chmod(reports_data_path + '/' + report_archive_file, conf)
    common.chmod(reports_data_path + '/' + hiseq_log_archive_file, conf)

    return True
Пример #3
0
    # Check if the report has been generated
    if not os.path.exists(html_report_file):
        error("Error while computing QC report for run " + run_id + ".", "No HTML report generated", conf)
        return False

    # Archive the reports
    cmd = 'cd ' + quote(reports_data_path) + ' && ' + \
          'tar cjf qc_' + run_id + '.tar.bz2 qc_' + run_id
    common.log("INFO", "exec: " + cmd, conf)
    if os.system(cmd) != 0:
        error("Error while saving the QC archive file for " + run_id,
              'Error while saving the  QC archive file.\nCommand line:\n' + cmd, conf)
        return False

    # Set read only basecall stats archives files
    common.chmod(reports_data_path + '/qc_' + run_id + '.tar.bz2', conf)

    # Check if the report has been generated
    if not os.path.exists(html_report_file):
        error("Error while computing QC report for run " + run_id + ".", "No HTML report generated", conf)
        return False

    # The output directory must be read only
    if not common.chmod_files_in_dir(qc_output_dir, None, conf):
        error("Error while setting the output QC directory to read only for run " + run_id,
              'Error while setting the output QC directory to read only.\nCommand line:\n' + cmd, conf)
        return False

    # Create index.hml file
    sessions = [Settings.HISEQ_STEP_KEY, Settings.DEMUX_STEP_KEY, Settings.QC_STEP_KEY]
    common.create_html_index_file(conf, run_id, sessions)