Example #1
0
def archive_samplesheet(run_id, original_samplesheet_path, samplesheet_csv_path, conf):
    """ Archive samplesheet file in archive samplesheet directory.

    Arguments:
        run_id: The run id
        original_samplesheet_path: samplesheet path in format xls if exists
        samplesheet_csv_path: samplesheet path in format csv
        conf: configuration dictionary
    """

    # Add samplesheet to the archive of samplesheets
    if (common.is_conf_value_defined(BCL2FASTQ_SAMPLESHEET_FORMAT_KEY, 'xls', conf) \
            and original_samplesheet_path.endswith(".xls")) or \
            (common.is_conf_value_defined(BCL2FASTQ_SAMPLESHEET_FORMAT_KEY, 'xlsx', conf) \
            and original_samplesheet_path.endswith(".xlsx")):

        cmd = 'cp ' + quote(original_samplesheet_path) + ' ' + quote(conf[TMP_PATH_KEY]) + \
              ' && cd ' + quote(conf[TMP_PATH_KEY]) + \
              ' && zip -q ' + quote(conf[BCL2FASTQ_SAMPLESHEETS_PATH_KEY] + '/' + \
              conf[BCL2FASTQ_SAMPLESHEET_PREFIX_FILENAME_KEY] + 's.zip') + ' ' + \
              quote(os.path.basename(samplesheet_csv_path)) + ' ' + quote(os.path.basename(original_samplesheet_path))
    else:
        cmd = 'cd ' + quote(conf[TMP_PATH_KEY]) + \
              ' && zip -q ' + quote(conf[BCL2FASTQ_SAMPLESHEETS_PATH_KEY] + '/' + \
              conf[BCL2FASTQ_SAMPLESHEET_PREFIX_FILENAME_KEY] + 's.zip') + ' ' + \
              quote(os.path.basename(samplesheet_csv_path))

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

    # Remove temporary samplesheet files
    if common.is_conf_value_defined(BCL2FASTQ_SAMPLESHEET_FORMAT_KEY, 'xls', conf) or \
       common.is_conf_value_defined(BCL2FASTQ_SAMPLESHEET_FORMAT_KEY, 'xlsx', conf):
        file_to_remove = conf[TMP_PATH_KEY] + '/' + os.path.basename(original_samplesheet_path)
        if os.path.exists(file_to_remove):
            os.remove(file_to_remove)

    return True
Example #2
0
def aozan_main():
    """Aozan main method.
    """

    # Define command line parser
    parser = OptionParser(usage='usage: ' + Globals.APP_NAME_LOWER_CASE + '.sh [options] conf_file')
    parser.add_option('-q', '--quiet', action='store_true', dest='quiet',
                      default=False, help='quiet')
    parser.add_option('-v', '--version', action='store_true', dest='version', help='Aozan version')
    parser.add_option('-e', '--exit-code', action='store_true', dest='exit_code',
                      help='Returns non zero exit code if a step fails')
    parser.add_option('-c', '--conf', action='store_true', dest='conf',
                      help='Default Aozan configuration, loads before configuration file.')

    # Parse command line arguments
    (options, args) = parser.parse_args()

    # Print Aozan current version
    if options.version:
        print Globals.WELCOME_MSG
        sys.exit(0)

    #  Print default configuration option
    if options.conf:
        print common.print_default_configuration()
        sys.exit(0)

    # If no argument print usage
    if len(args) < 1:
        parser.print_help()
        sys.exit(1)

    # Create configuration object
    conf = LinkedHashMap()

    # Set the default value in the configuration object
    common.set_default_conf(conf)

    # Use default (US) locale
    Locale.setDefault(Globals.DEFAULT_LOCALE)

    # Check if OS is Linux
    if not SystemUtils.isLinux():
        sys.stderr.write('ERROR: Aozan can not be executed. Operating system is not Linux\n')
        sys.exit(1)

    # Check if configuration file exists
    conf_file = args[0]
    if not os.path.isfile(conf_file):
        sys.stderr.write('ERROR: Aozan can not be executed. Configuration file is missing: ' + \
                         conf_file + '\n')
        sys.exit(1)

    # Load Aozan conf file
    common.load_conf(conf, conf_file)

    # End of Aozan if aozan is not enable
    if common.is_conf_value_defined(AOZAN_ENABLE_KEY, 'false', conf):
        sys.exit(0)

    # Init logger
    try:
        Common.initLogger(conf[AOZAN_LOG_PATH_KEY], conf[AOZAN_LOG_LEVEL_KEY])
    except AozanException, exp:
        common.exception_msg(exp, conf)
Example #3
0
def load_samplesheet(run_id, input_run_data_path, samplesheet_filename, conf):
    """ Load the samplesheet.

    Arguments:
        run id: The run id
        input_run_data_path: The input run data path
        samplesheet_filename: samplesheet filename
        conf: configuration dictionary

    Return:
        a Samplesheet object and the original path of the samplesheet
    """

    run_info_path = input_run_data_path + '/RunInfo.xml'

    if not os.path.isfile(run_info_path):
        error("no RunInfo.xml file found for run " + run_id,
              "No RunInfo.xml file found for run " + run_id + ': ' + run_info_path + '.\n', conf)
        return None, None

    run_info = RunInfo.parse(run_info_path)
    flow_cell_id = run_info.getFlowCell()

    common.log("INFO", "Flowcell id: " + flow_cell_id, conf)
    common.log("INFO", "Samplesheet format: " + str(conf[BCL2FASTQ_SAMPLESHEET_FORMAT_KEY]), conf)

    try:
        if common.is_conf_value_defined(BCL2FASTQ_SAMPLESHEET_FORMAT_KEY, 'xls', conf):
            return load_samplesheet_using_extension(conf,samplesheet_filename,'xls',input_run_data_path,run_id)

        elif common.is_conf_value_defined(BCL2FASTQ_SAMPLESHEET_FORMAT_KEY, 'csv', conf):
            return load_samplesheet_using_extension(conf,samplesheet_filename,'csv',input_run_data_path,run_id)

        elif common.is_conf_value_defined(BCL2FASTQ_SAMPLESHEET_FORMAT_KEY, 'xlsx', conf):
            return load_samplesheet_using_extension(conf,samplesheet_filename,'xlsx',input_run_data_path,run_id)

        elif common.is_conf_value_defined(BCL2FASTQ_SAMPLESHEET_FORMAT_KEY, 'command', conf):
            action_error_msg = 'Error while creating Bcl2fastq CSV samplesheet file'
            if not common.is_conf_key_exists(BCL2FASTQ_SAMPLESHEET_GENERATOR_COMMAND_KEY, conf):
                error(action_error_msg + ' for run ' + run_id, action_error_msg + ' the command is empty.', conf)
                return None, None

            input_samplesheet_generated_path = conf[TMP_PATH_KEY] + '/' + samplesheet_filename + 'generated.csv'

            cmd = conf[
                      BCL2FASTQ_SAMPLESHEET_GENERATOR_COMMAND_KEY] + ' ' + run_id + ' ' + quote(input_samplesheet_generated_path)
            common.log("INFO", "exec: " + cmd, conf)
            if os.system(cmd) != 0:
                error(action_error_msg + ' for run ' + run_id,
                      action_error_msg + '.\nCommand line:\n' + cmd, conf)

            if not os.path.exists(input_samplesheet_generated_path):
                error(action_error_msg + ' for run ' + run_id,
                      action_error_msg + ', the external command did not create Bcl2fastq CSV file:\n' + cmd, conf)
                return None, None

            # Load CSV samplesheet file
            samplesheet = SampleSheetCSVReader(input_samplesheet_generated_path).read()

            # Remove generated samplesheet
            os.unlink(input_samplesheet_generated_path)

            return samplesheet, None

        else:
            error('Error while creating Bcl2fastq CSV samplesheet file for run ' + run_id,
                  'No method to get Bcl2fastq samplesheet file has been defined. Please, set the ' +
                  '"bcl2fastq.samplesheet.format" property.\n',
                  conf)
            return None, None

    except AozanException, exp:
        print StringUtils.stackTraceToString(exp)

        error("Error reading samplesheet: " + samplesheet_filename, exp.getMessage(), conf)
        return None, None
Example #4
0
    try:

        # Initialize the QC object
        qc = QC(Settings(conf), input_run_data_path, fastq_input_dir, qc_output_dir, conf[TMP_PATH_KEY], run_id)

        # Compute the report
        report = qc.computeReport()
    except AozanException, exp:
        error("Error while computing QC report for run " + run_id + ".", common.exception_msg(exp, conf), conf)
        return False
    except Throwable, exp:
        error("Error while computing QC report for run " + run_id + ".", common.exception_msg(exp, conf), conf)
        return False

    # Remove QC data if not demand
    if common.is_conf_value_defined(QC_REPORT_SAVE_RAW_DATA_KEY, 'false', conf):
        try:
            os.remove(qc_output_dir + '/data-' + run_id + '.txt')
            # qc.writeRawData(report, qc_output_dir + '/data-' + run_id + '.txt')
        except AozanException, exp:
            error("Error while removing QC raw data for run " + run_id + ".", exp.getMessage(), conf)
            return False

    # Write the XML report
    if common.is_conf_value_equals_true(QC_REPORT_SAVE_REPORT_DATA_KEY, conf):
        try:
            qc.writeXMLReport(report, qc_output_dir + '/' + run_id + '.xml')
        except AozanException, exp:
            error("Error while computing QC XML report for run " + run_id + ".", common.exception_msg(exp, conf), conf)
            return False
        except Throwable, exp: