def get_sequencer_platform(dirn, instrument=None, settings=None): """ Return the platform for the sequencing instrument Attempts to identify the platform (e.g. 'hiseq', 'miseq' etc) for a sequencing run. If 'settings' is supplied then the platform is looked up based on the instrument names and platforms listed in the 'sequencers' section of the configuration. If 'instrument' is also supplied then this is used; otherwise the instrument name is extracted from the supplied directory name. If no match can be found then there is a final attempt to determine the platform from the hard-coded names in the 'bcftbx.platforms' module. Arguments: dirn (str): path to the data or analysis directory instrument (str): (optional) the instrument name settings (Settings): (optional) a Settings instance with the configuration loaded Returns: String: either the platform or None, if the platform cannot be determined. """ # Attempt to look up the instrument name platform = None if instrument is None: print "Extracting instrument name from directory name" try: datestamp,instrument,run_number,\ flow_cell_prefix,flow_cell_id = \ IlluminaData.split_run_name_full(dirn) except Exception as ex: logging.warning("Unable to extract instrument name: " "%s" % ex) if instrument and settings: print "Identifying platform from instrument name" try: return settings.sequencers[instrument] except KeyError: # Instrument not listed in the settings logging.warning("Instrument name '%s' not found in " "configuration file" % instrument) # Fall back to old method print "Identifying platform from data directory name" platform = platforms.get_sequencer_platform(dirn) if platform is None: logging.warning("Unable to identify platform from " "directory name") return platform
def update_metadata(self): """ Migrates and updates metadata values """ # Migrate missing values from parameter file if self.has_parameter_file: # Migrate relevant values across print("Migrating metadata values from parameter file") for param in ( 'platform', 'run_number', 'source', ): if param not in self.params: continue if self.metadata[param] is None: logging.debug("Importing metadata item '%s': set to " "'%s'" % (param, self.params[param])) print("Importing metadata item '%s'" % param) self.metadata[param] = self.params[param] # Run name if self.metadata.run_name is None: print("Attempting to set missing 'run_name' metadata item") self.metadata['run_name'] = self.run_name # Instrument-related metadata if self.metadata.instrument_name is None or \ self.metadata.instrument_datestamp is None or \ self.metadata.instrument_run_number is None: print("Attempting to set missing instrument metadata items") # Extract from run name try: datestamp,instrument,run_number,\ flow_cell_prefix,flow_cell_id = \ IlluminaData.split_run_name_full(self.run_name) if self.metadata.instrument_name is None: self.metadata['instrument_name'] = instrument if self.metadata.instrument_datestamp is None: self.metadata['instrument_datestamp'] = datestamp if self.metadata.instrument_run_number is None: self.metadata['instrument_run_number'] = run_number if self.metadata.instrument_flow_cell_id is None: self.metadata['instrument_flow_cell_id'] = \ flow_cell_prefix + flow_cell_id except Exception as ex: logging.warning( "Unable to extract missing instrument metadata " "from run name") # Sequencing platform if self.metadata.platform is None: # Attempt to look up the instrument name platform = get_sequencer_platform( self.analysis_dir, instrument=self.metadata.instrument_name, settings=self.settings) if platform: print("Setting 'platform' metadata item to %s" % platform) self.metadata['platform'] = platform # Sequencer model if self.metadata.sequencer_model is None: instrument_name = self.metadata.instrument_name if instrument_name: try: self.metadata['sequencer_model'] = \ self.settings.sequencers[instrument_name].model print("Setting 'sequencer_model' metadata item to " "'%s'" % self.metadata.sequencer_model) except KeyError: print("Unable to get sequencer model for " "instrument '%s'" % instrument_name)