Exemplo n.º 1
0
 def __init__(self, args):
     self.args = args
     self.log_level = self.get_log_level(self.args.debug, self.args.verbose,
                                         self.args.quiet)
     self.log_path = self.args.log_path
     if self.log_path:
         # we are verifying the log path, so don't write output there yet
         path_validator(self.log_level).validate_output_file(self.log_path)
     self.logger = self.get_logger(self.log_level, __name__, self.log_path)
     self.data_dir = os.path.join(os.path.dirname(__file__),
                                  constants.DATA_DIR_NAME)
     self.legacy = self.args.legacy
     self.wait_script = which(self.WAIT_SCRIPT_NAME)
     if not self.wait_script:
         msg = "Unable to find {0} on the PATH".format(
             self.WAIT_SCRIPT_NAME)
         self.logger.error(msg)
         raise RuntimeError(msg)
     # validate the command-line arguments
     validator = path_validator(self.log_level, self.log_path)
     if (args.ready and args.execute):
         msg = "Cannot specify both --ready and --execute: On the OICR cluster "+\
               "--ready requires a compute node to run bcftools, while "+\
               "--execute requires a head node with job submission privileges."
         self.logger.error(msg)
         raise ValueError(msg)
     elif args.ready:
         if not (args.donor and args.study):
             msg = "--ready requires --donor and --study"
             self.logger.error(msg)
             raise ValueError(msg)
     self._read_config(args.config)
     validator.validate_output_dir(args.work_dir)
     self.work_dir = os.path.abspath(args.work_dir)
     self.dry_run = args.dry_run
Exemplo n.º 2
0
 def __init__(self, args):
     source_dir = os.path.dirname(os.path.realpath(__file__))
     self.ini_defaults = os.path.join(source_dir, constants.DATA_DIR_NAME,
                                      self.INI_DEFAULT_NAME)
     self.ini_template = os.path.join(source_dir, constants.DATA_DIR_NAME,
                                      self.INI_TEMPLATE_NAME)
     self.args = args
     self.log_level = self.get_log_level(self.args.debug, self.args.verbose,
                                         self.args.quiet)
     self.log_path = self.args.log_path
     if self.log_path:
         # we are verifying the log path, so don't write output there yet
         path_validator(self.log_level).validate_output_file(self.log_path)
     self.logger = self.get_logger(self.log_level, __name__, self.log_path)
     self.validate_args(args)  # checks subparser and args are valid
Exemplo n.º 3
0
def main(args):
    if args.subparser_name == LOCATE:
        print(locate_sequenza_path(args))
    elif args.subparser_name == READ:
        path_validator().validate_input_file(args.in_path)
        log_level = logger.get_args_log_level(args)
        reader = sequenza_reader(args.in_path, log_level, args.log_path)
        if args.gamma_selection:
            reader.print_gamma_selection()
        if args.purity_ploidy:
            reader.print_purity_ploidy_table()
        if args.summary:
            reader.print_summary()
        if args.json:
            reader.write_json(args.json)
Exemplo n.º 4
0
 def _read_config(self, config_path):
     """Set instance variables from the config file"""
     validator = path_validator(self.log_level, self.log_path)
     if config_path:
         validator.validate_input_file(config_path)
     else:
         config_path = os.path.join(self.data_dir, self.INPUT_CONFIG)
     self.logger.debug("Reading config path: {0}".format(config_path))
     config = ConfigParser()
     config.read(config_path)
     settings = config[self.SETTINGS_KEY]
     self.logger.debug("Mavis settings: {0}".format([(k, settings[k])
                                                     for k in settings]))
     self.config_name = settings.get(self.CONFIG_NAME_KEY)
     self.cromwell_host_url = settings.get(self.CROMWELL_HOST_URL_KEY)
     self.cromwell_scratch_dir = settings.get(self.CROMWELL_SCRATCH_DIR_KEY)
     self.email_recipients = settings.get(self.EMAIL_KEY)
     self.provenance_path = settings.get(self.PROVENANCE_KEY)
     if self.legacy:
         self.wdl_path = settings.get(self.LEGACY_WDL_KEY)
     else:
         self.wdl_path = settings.get(self.WDL_KEY)
     self.logger.debug("WDL path: {0}".format(self.wdl_path))
     for input_path in [self.provenance_path, self.wdl_path]:
         validator.validate_input_file(input_path)
Exemplo n.º 5
0
def main(args):
    v = path_validator()
    v.validate_input_file(args.html)
    v.validate_output_file(args.pdf)
    pdf_renderer().run(os.path.abspath(args.html),
                       os.path.abspath(args.pdf),
                       footer=False)
Exemplo n.º 6
0
 def validate_args(self, args):
     """Check we can read/write paths in command-line arguments"""
     self.logger.info("Validating paths in command-line arguments")
     v = path_validator(self.log_level, self.log_path)
     if args.log_path:
         v.validate_output_file(args.log_path)
     if args.subparser_name == constants.SETUP:
         v.validate_output_dir(args.base)
     elif args.subparser_name == constants.CONFIGURE:
         v.validate_input_file(args.ini)
         v.validate_output_file(args.out)
     elif args.subparser_name == constants.EXTRACT:
         v.validate_input_file(args.ini)
         v.validate_output_dir(args.dir)
         if args.json:
             v.validate_output_file(args.json)
     elif args.subparser_name == constants.HTML:
         v.validate_input_dir(args.dir)
         if args.html:
             v.validate_output_file(args.html)
     elif args.subparser_name == constants.PDF:
         v.validate_output_dir(args.dir)
         if args.html:
             v.validate_input_file(args.html)
     elif args.subparser_name == constants.DRAFT:
         v.validate_input_file(args.ini)
         v.validate_output_dir(args.dir)
         if args.html:
             v.validate_output_file(args.html)
         if args.ini_out:
             v.validate_output_file(args.ini_out)
         if args.json:
             v.validate_output_file(args.json)
     elif args.subparser_name == constants.ALL:
         v.validate_input_file(args.ini)
         if args.ini_out:
             v.validate_output_file(args.ini_out)
         if args.dir:
             v.validate_output_dir(args.dir)
         if args.json:
             v.validate_output_file(args.json)
         if args.html:
             v.validate_output_file(args.html)
     else:
         # shouldn't happen, but handle this case for completeness
         raise ValueError("Unknown subparser: " + args.subparser_name)
     self.logger.info("Command-line path validation finished.")
     # warning for inconsistent arguments
     if self.args.subparser_name in [constants.HTML, constants.DRAFT, constants.ALL] and \
        args.wgs_only and args.failed:
         msg = 'Both --failed and --wgs-only options specified; but '+\
               'failed report format is identical for WGS and WGS+WTS'
         self.logger.warn(msg)
Exemplo n.º 7
0
 def run(self, archive_dir=None):
     """Write INI to a file of the form $ARCHIVE_DIR/$PATIENT_INI/$CHECKSUM/${PATIENT_ID}.ini"""
     if not archive_dir:
         archive_dir = self.config.get(ini.SETTINGS, ini.ARCHIVE_DIR)
     path_validator().validate_output_dir(archive_dir)
     out_dir_0 = os.path.join(archive_dir, self.patient_id)
     if not os.path.exists(out_dir_0):
         os.mkdir(out_dir_0)
     out_dir_1 = os.path.join(out_dir_0, self.md5sum)
     out_path = None
     if os.path.exists(out_dir_1):
         msg = "Output directory {0} exists; an identical file has already been archived; not writing to archive".format(
             out_dir_1)
         self.logger.warning(msg)
     else:
         os.mkdir(out_dir_1)
         out_path = os.path.join(out_dir_1,
                                 "{0}.ini".format(self.patient_id))
         with open(out_path, 'w') as out_file:
             out_file.write(self.config_string)
         self.logger.info("Archived INI file to {0}".format(out_path))
     return out_path
Exemplo n.º 8
0
 def main(self):
     """Main method to run Mavis operations"""
     action = 0  # bitwise flag to show which actions were taken
     if self.args.ready:
         self.logger.info("Finding inputs in file provenance: " +
                          self.provenance_path)
         inputs = self.find_inputs()
         self.logger.info("Linking inputs to working directory: " +
                          self.work_dir)
         local_inputs = self.link_and_copy_inputs(inputs)
         self.logger.info("Writing JSON Cromwell config")
         config_json = self.write_config(local_inputs)
         action += 1
     else:
         config_json = os.path.join(self.work_dir, self.config_name)
         path_validator().validate_input_file(config_json)
     if self.args.execute:
         self.check_config_version(config_json)
         self.logger.info("Launching Mavis WDL: " + self.wdl_path)
         self.execute(config_json)
         action += 2
     self.logger.info("Finished.")
     return action
Exemplo n.º 9
0
 def _read_clinical_data_fields(self, input_dir):
     """Read the clinical data TSV into a dictionary"""
     input_path = os.path.join(input_dir, constants.CLINICAL_DATA_FILENAME)
     path_validator(self.log_level,
                    self.log_path).validate_input_file(input_path)
     with open(input_path) as input_file:
         input_lines = input_file.readlines()
     # first sanity check
     if not (len(input_lines) == 2
             and re.match(constants.PATIENT_LIMS_ID, input_lines[0])):
         msg = "Incorrect format in clinical data file at {0}".format(
             input_path)
         self.logger.error(msg)
         raise ValueError(msg)
     head = re.split("\t", input_lines[0].strip())
     body = re.split("\t", input_lines[1].strip())
     # second sanity check
     if len(head) != len(body):
         msg = "Mismatched header and body fields in {0}".format(input_path)
         self.logger.error(msg)
         raise ValueError(msg)
     clinical_data = {head[i]: body[i] for i in range(len(head))}
     return clinical_data
Exemplo n.º 10
0
def locate_sequenza_path(args):
    path_validator().validate_input_file(args.file_provenance)
    log_level = logger.get_args_log_level(args)
    reader = provenance_reader(args.file_provenance, args.project, args.donor, log_level)
    return reader.parse_sequenza_path()