def start(config, debug): # This will ensure config is loaded through-out # the app. Config.load_config(config) # Start Tornado app. app = create_app(debug) app.listen(port=8888) tornado.ioloop.IOLoop.current().start()
def create_config_from_request(self, runfolder, request_data): """ For the specified runfolder, will look it up from the place setup in the configuration, and then parse additinoal data from the request_data object. This can be used to override any default setting in the resulting Bcl2FastqConfig instance. :param runfolder: name of the runfolder we want to create a config for :param request_data: dict containing additional configurations :return: an instances of Bcl2FastqConfig """ # TODO Make sure to escape them for sec. reasons. bcl2fastq_version = "" runfolder_input = "" output = "" barcode_mismatches = "" tiles = "" use_base_mask = "" additional_args = "" runfolder_base_path = Config.load_config()["runfolder_path"] runfolder_input = "{0}/{1}".format(runfolder_base_path, runfolder) import os.path as p if not p.isdir(runfolder_input): raise RuntimeError("No such file: {0}".format(runfolder_input)) if "bcl2fastq_version" in request_data: bcl2fastq_version = request_data["bcl2fastq_version"] if "output" in request_data: output = request_data["output"] if "barcode_mismatches" in request_data: barcode_mismatches = request_data["barcode_mismatches"] if "tiles" in request_data: tiles = request_data["tiles"] if "use_base_mask" in request_data: use_base_mask = request_data["use_base_mask"] if "additional_args" in request_data: additional_args = request_data["additional_args"] config = Bcl2FastqConfig( bcl2fastq_version, runfolder_input, output, barcode_mismatches, tiles, use_base_mask, additional_args) return config
def create_config_from_request(self, runfolder, request_data): """ For the specified runfolder, will look it up from the place setup in the configuration, and then parse additinoal data from the request_data object. This can be used to override any default setting in the resulting Bcl2FastqConfig instance. :param runfolder: name of the runfolder we want to create a config for :param request_data: dict containing additional configurations :return: an instances of Bcl2FastqConfig """ # TODO Make sure to escape them for sec. reasons. bcl2fastq_version = "" runfolder_input = "" output = "" barcode_mismatches = "" tiles = "" use_base_mask = "" additional_args = "" runfolder_base_path = Config.load_config()["runfolder_path"] runfolder_input = "{0}/{1}".format(runfolder_base_path, runfolder) import os.path as p if not p.isdir(runfolder_input): raise RuntimeError("No such file: {0}".format(runfolder_input)) if "bcl2fastq_version" in request_data: bcl2fastq_version = request_data["bcl2fastq_version"] if "output" in request_data: output = request_data["output"] if "barcode_mismatches" in request_data: barcode_mismatches = request_data["barcode_mismatches"] if "tiles" in request_data: tiles = request_data["tiles"] if "use_base_mask" in request_data: use_base_mask = request_data["use_base_mask"] if "additional_args" in request_data: additional_args = request_data["additional_args"] config = Bcl2FastqConfig(bcl2fastq_version, runfolder_input, output, barcode_mismatches, tiles, use_base_mask, additional_args) return config
def post(self, runfolder): """ Starts a bcl2fastq for a runfolder. The input data can contain extra parameters for bcl2fastq. It should be a json encoded object and can contain one or more of the following parameters: - bcl2fastq_version - output - barcode_mismatches - tiles - use_base_mask - additional_args If these are not set defaults setup in Bcl2FastqConfig will be used (and those should be good enough for most cases). :param runfolder: name of the runfolder we want to start bcl2fastq for """ try: runfolder_config = self.create_config_from_request( runfolder, json.loads(self.request.body)) cmd = self.bcl2fastq_cmd_generation_service().\ create_bcl2fastq_runner(runfolder_config).\ construct_command() general_config = Config.load_config() log_base_path = general_config["bcl2fastq_logs_path"] log_file = "{0}/{1}.log".format(log_base_path, runfolder) job_id = self.runner_service().start( cmd, nbr_of_cores=runfolder_config.nbr_of_cores, run_dir=runfolder_config.runfolder_input, stdout=log_file, stderr=log_file) status_end_point = self.reverse_url("status", job_id) response_data = { "job_id": job_id, "link": status_end_point, "state": State.STARTED } self.set_status(202, reason="started processing") self.write_json(response_data) except RuntimeError as e: self.send_error(status_code=500, reason=e.message)
def post(self, runfolder): """ Starts a bcl2fastq for a runfolder. The input data can contain extra parameters for bcl2fastq. It should be a json encoded object and can contain one or more of the following parameters: - bcl2fastq_version - output - barcode_mismatches - tiles - use_base_mask - additional_args If these are not set defaults setup in Bcl2FastqConfig will be used (and those should be good enough for most cases). :param runfolder: name of the runfolder we want to start bcl2fastq for """ try: #TODO Make sure this works even if body is not set! /JD 20150820 runfolder_config = self.create_config_from_request(runfolder, json.loads(self.request.body)) cmd = self.bcl2fastq_cmd_generation_service().\ create_bcl2fastq_runner(runfolder_config).\ construct_command() general_config = Config.load_config() log_base_path = general_config["bcl2fastq_logs_path"] log_file = "{0}/{1}.log".format(log_base_path, runfolder) job_id = self.runner_service().start( cmd, nbr_of_cores=runfolder_config.nbr_of_cores, run_dir=runfolder_config.runfolder_input, stdout=log_file, stderr=log_file) status_end_point = "{0}://{1}{2}".format( self.request.protocol, self.request.host, self.reverse_url("status", job_id)) response_data = {"job_id": job_id, "link": status_end_point, "state": State.STARTED} self.set_status(202, reason="started processing") self.write_json(response_data) except RuntimeError as e: self.send_error(status_code=500, reason=e.message)
def get_bcl2fastq_version_from_run_parameters(runfolder, config=None): """ Guess which bcl2fastq version to use based on the machine type specified in the runfolder meta data, and the corresponding mappings in the config file. :param runfolder: to get bcl2fastq version to use for :param config: to use matching machine type to bcl2fastq versions (will be loaded from default config if not set). :return the version of bcl2fastq to use. """ meta_data = InteropMetadata(runfolder) model = meta_data.model current_config = config or Config.load_config() version = current_config["machine_type"][model]["bcl2fastq_version"] return version
def __init__(self, bcl2fastq_version, runfolder_input, output, barcode_mismatches=None, tiles=None, use_base_mask=None, additional_args=None, nbr_of_cores=None): self.runfolder_input = runfolder_input self.samplesheet_file = runfolder_input + "/SampleSheet.csv" self.base_calls_input = runfolder_input + "/Data/Intensities/BaseCalls" if bcl2fastq_version: self.bcl2fastq_version = bcl2fastq_version else: self.bcl2fastq_version = Bcl2FastqConfig.\ get_bcl2fastq_version_from_run_parameters(runfolder_input) if output: self.output = output else: output_base = Config.load_config()["default_output_path"] runfolder_base_name = os.path.basename(runfolder_input) self.output = "{0}/{1}".format(output_base, runfolder_base_name) self.barcode_mismatches = barcode_mismatches self.tiles = tiles # TODO Ensure that this is included in any user facing documentation. # Note that for the base mask the "--use-bases-mask" must be included in the # commandline passed. E.g. "--use-bases-mask 1:y*,6i,6i, y* --use-bases-mask y*,6i,6i, y* " self.use_base_mask = use_base_mask self.additional_args = additional_args # Nbr of cores to use will default to the number of cpus on the system. if nbr_of_cores: self.nbr_of_cores = nbr_of_cores else: import multiprocessing self.nbr_of_cores = multiprocessing.cpu_count()
def get(self): config = Config.load_config() available_versions = config["bcl2fastq"]["versions"].keys() self.write_object(available_versions)
def __init__(self, config=None): config = config or Config.load_config() self.bcl2fastq_mappings = config["bcl2fastq"]["versions"]