Parse MIP config file.

    Args:
        data (dict): raw YAML input from MIP analysis config file

    Returns:
        dict: parsed data
492509
def parse_config(data: dict) -> dict:
    
    return {
        'email': data.get('email'),
        'family': data['family_id'],
        'samples': [{
            'id': sample_id,
            'type': analysis_type,
        } for sample_id, analysis_type in data['analysis_type'].items()],
        'config_path': data['config_file_analysis'],
        'is_dryrun': True if 'dry_run_all' in data else False,
        'log_path': data['log_file'],
        'out_dir': data['outdata_dir'],
        'priority': data['slurm_quality_of_service'],
        'sampleinfo_path': data['sample_info_file'],
    }
92083
def parse(self, data):
        
        graph = self._init_graph()
        # ensure is NetJSON NetworkGraph object
        if 'type' not in data or data['type'] != 'NetworkGraph':
            raise ParserError('Parse error, not a NetworkGraph object')
        # ensure required keys are present
        required_keys = ['protocol', 'version', 'metric', 'nodes', 'links']
        for key in required_keys:
            if key not in data:
                raise ParserError('Parse error, "{0}" key not found'.format(key))

        # store metadata
        self.protocol = data['protocol']
        self.version = data['version']
        self.revision = data.get('revision')  # optional
        self.metric = data['metric']

        # create graph
        for node in data['nodes']:
            graph.add_node(node['id'],
                           label=node['label'] if 'label' in node else None,
                           local_addresses=node.get('local_addresses', []),
                           **node.get('properties', {}))
        for link in data['links']:
            try:
                source = link["source"]
                dest = link["target"]
                cost = link["cost"]
            except KeyError as e:
                raise ParserError('Parse error, "%s" key not found' % e)
            properties = link.get('properties', {})
            graph.add_edge(source, dest, weight=cost, **properties)
        return graph
1371243
def parse_data_to_internal(self, data=None):
        
        if data is None:
            kwargs = self.kwargs
            data = np.loadtxt(
                open(self.location_dat, "rb"), **kwargs
            )
        if self.filetype is "pickle":
            pickle.dump(data, open(self.location_internal, "wb"))
        elif self.filetype is "hickle":
            import hickle
            hickle.dump(data, open(self.location_internal, "wb"))
        else:
            raise ValueError(
                "Invalid filetype {} (must be {} or {})".format(
                    self.filetype, "pickle", "hickle"
                )
            )
881111
def parse_yaml(self, y):
        '''

        '''
        self.id = y['id']
        self._config_data = []
        if 'configurationData' in y:
            for d in y.get('configurationData'):
                self._config_data.append(ConfigurationData().parse_yaml(d))
        return self
798355
def _parse_table_data(self, data):
        
        header = data.split(':')

        self.current_table.data_header = header

        for i, h in enumerate(header):
            header[i] = h.strip()

        x_count = header.count('x')
        y_count = header.count('y')

        if not self.current_table.xheaders:
            raise BadFormat("*xheader line needs to appear before *data: %s" % data)

        if not self.current_table.yheaders:
            raise BadFormat("*yheader line needs to appear before *data: %s" % data)

        # use deepcopy to avoid references in yaml... may not be required, and will very probably be refactored
        # TODO - is this appropriate behavior, or are references in YAML files acceptable, they are certainly less human readable
        self.current_table.data = {'independent_variables': [{'header': self.current_table.xheaders[i] if i < len(self.current_table.xheaders) else copy.deepcopy(self.current_table.xheaders[-1]),
                                                              'values': []} for i in range(x_count)],
                                      'dependent_variables': [{'header': self.current_table.yheaders[i] if i < len(self.current_table.yheaders) else copy.deepcopy(self.current_table.yheaders[-1]),
                                                               'qualifiers': [self.current_table.qualifiers[j][i] if i < len(self.current_table.qualifiers[j]) else copy.deepcopy(self.current_table.qualifiers[j][-1]) for j in range(len(self.current_table.qualifiers)) ],
                                                               'values': []} for i in range(y_count)]}

        xy_mapping = []

        current_x_count = 0
        current_y_count = 0

        for h in header:
            if h == 'x':
                xy_mapping.append(current_x_count)
                current_x_count += 1
            if h == 'y':
                xy_mapping.append(current_y_count)
                current_y_count += 1

        last_index = self.current_file.tell()
        line = self._strip_comments(self.current_file.readline())

        while line and not line.startswith('*'):
            data_entry_elements = line.split(';')[:-1] # split and also strip newline character at the end

            if len(data_entry_elements) == len(header):
            # this is kind of a big stretch... I assume that x is always first
                for i, h in enumerate(header):
                    single_element = data_entry_elements[i].strip()

                    # number patterns copied from old subs.pl parsing script
                    pmnum1 = '[-+]?[\d]+\.?[\d]*'
                    pmnum2 = '[-+]?\.[\d]+'
                    pmnum3 = '[-+]?[\d]+\.?[\d]*\s*[eE]+\s*[+-]?\s*[\d]+'
                    pmnum = '(' + pmnum1 + '|' + pmnum2 + '|' + pmnum3 + ')'

                    # implement same regular expression matching as in old subs.pl parsing script

                    if h == 'x': # independent variables

                        r = re.search('^(?P<value>' + pmnum + ')$', single_element)
                        if r: # "value"
                            single_element = {'value': r.group('value')}
                        else:
                            r = re.search('^(?P<value>' + pmnum + ')\s*\(\s*BIN\s*=\s*(?P<low>' + pmnum + \
                                          ')\s+TO\s+(?P<high>' + pmnum + ')\s*\)$', single_element)
                            if r: # "value (BIN=low TO high)"
                                single_element = {'value': float(r.group('value')),
                                                  'low': float(r.group('low')), 'high': float(r.group('high'))}
                            else:
                                r = re.search('^(?P<low>' + pmnum + ')\s+TO\s+(?P<high>' + pmnum + ')$',
                                              single_element)
                                if r: # "low TO high"
                                    single_element = {'low': float(r.group('low')), 'high': float(r.group('high'))}
                                else: # everything else: don't try to convert to float
                                    single_element = {'value': single_element}

                        # TO DO: subs.pl also parses other formats such as "low high", "value low high" (sorted),
                        # "value +- err", and "value -err_m, +err_p".  Do we need to support these formats here?
                        # Probably not: unsupported formats will just be written as a text string.

                        self.current_table.data['independent_variables'][xy_mapping[i]]['values'].append(single_element)

                        # extract energy if SQRT(S) is one of the 'x' variables
                        xheader = self.current_table.data['independent_variables'][xy_mapping[i]]['header']
                        if xheader['name'].startswith('SQRT(S)') and lower(xheader['units']) in ('gev'):
                            for energy in single_element.values():
                                try:
                                    energy = float(energy)
                                    self.set_of_energies.add(energy)
                                except:
                                    pass

                    elif h == 'y': # dependent variable

                        pmnum_pct = pmnum + '(\s*PCT)?' # errors can possibly be given as percentages

                        r = re.search('^(?P<value>' + pmnum + ')\s+(?P<err_p>' + pmnum_pct + '|-)\s*,\s*(?P<err_m>' +
                                      pmnum_pct + '|-)\s*(?P<err_sys>\(\s*DSYS=[^()]+\s*\))?$', single_element)
                        element = {'errors': []}
                        if r: # asymmetric first error
                            element['value'] = r.group('value').strip()
                            err_p = r.group('err_p').strip().lstrip('+')
                            if err_p == '-': err_p = '' # represent missing error as '-' in oldhepdata format
                            err_p = err_p[:-3].strip() + '%' if err_p[-3:] == 'PCT' else err_p
                            err_m = r.group('err_m').strip().lstrip('+')
                            if err_m == '-': err_m = '' # represent missing error as '-' in oldhepdata format
                            err_m = err_m[:-3].strip() + '%' if err_m[-3:] == 'PCT' else err_m
                            if err_p and err_m and err_p[-1] != '%' and err_m[-1] == '%':
                                err_p = err_p + '%'
                            if not err_p and not err_m:
                                raise ValueError("Both asymmetric errors cannot be '-': %s" % line)
                            if r.group('err_sys'):
                                element['errors'] += [{'label': 'stat', 'asymerror': {'plus': err_p, 'minus': err_m}}]
                            else:
                                element['errors'] += [{'asymerror': {'plus': err_p, 'minus': err_m}}]

                        else:
                            r = re.search('^(?P<value>' + pmnum + ')\s*(\+-\s*(?P<error>' +
                                          pmnum_pct + '))?\s*(?P<err_sys>\(\s*DSYS=[^()]+\s*\))?$', single_element)
                            if r: # symmetric first error
                                element['value'] = r.group('value').strip()
                                if r.group('error'):
                                    error = r.group('error').strip().lstrip('+')
                                    error = error[:-3].strip() + '%' if error[-3:] == 'PCT' else error
                                    if r.group('err_sys'):
                                        element['errors'] += [{'label': 'stat', 'symerror': error}]
                                    else:
                                        element['errors'] += [{'symerror': error}]
                            else: # everything else
                                element['value'] = single_element

                        err_sys = []
                        if r and r.group('err_sys'):
                            err_sys = r.group('err_sys').strip(' \t()').split('DSYS=')

                        for err in err_sys + self.current_table.dserrors:
                            err = err.strip(' \t,')
                            if not err:
                                continue
                            error = {}
                            label = 'sys'
                            r = re.search('^(\+-)?\s*(?P<error>' + pmnum_pct + ')\s*(\:\s*(?P<label>.+))?$', err)
                            if r: # symmetric systematic error
                                if r.group('label'):
                                    label += ',' + r.group('label')
                                error = r.group('error').strip().lstrip('+')
                                error = error[:-3].strip() + '%' if error[-3:] == 'PCT' else error
                                error = {'symerror': error}

                            else:
                                r = re.search('^(?P<err_p>' + pmnum_pct + '|-)\s*,\s*(?P<err_m>' +
                                              pmnum_pct + '|-)\s*(\:\s*(?P<label>.+))?$', err)
                                if r: # asymmetric systematic error
                                    if r.group('label'):
                                        label += ',' + r.group('label')
                                    err_p = r.group('err_p').strip().lstrip('+')
                                    if err_p == '-': err_p = '' # represent missing error as '-' in oldhepdata format
                                    err_p = err_p[:-3].strip() + '%' if err_p[-3:] == 'PCT' else err_p
                                    err_m = r.group('err_m').strip().lstrip('+')
                                    if err_m == '-': err_m = '' # represent missing error as '-' in oldhepdata format
                                    err_m = err_m[:-3].strip() + '%' if err_m[-3:] == 'PCT' else err_m
                                    if err_p and err_m and err_p[-1] != '%' and err_m[-1] == '%':
                                        err_p = err_p + '%'
                                    if not err_p and not err_m:
                                        raise ValueError("Both asymmetric errors cannot be '-': %s" % line)
                                    error = {'asymerror': {'plus': err_p, 'minus': err_m}}
                            if not r:
                                # error happened
                                raise ValueError("Error while parsing data line: %s" % line)

                            error['label'] = label
                            if element['value'] != single_element:
                                element['errors'].append(error)
                        self.current_table.data['dependent_variables'][xy_mapping[i]]['values'].append(element)

            elif data_entry_elements:
                raise BadFormat("%s data entry elements but %s expected: %s" %
                                (len(data_entry_elements), len(header), line))

            last_index = self.current_file.tell()
            l = self.current_file.readline()
            line = self._strip_comments(l)

        self.current_file.seek(last_index)

        # extract minimum and maximum from set of energies
        if self.set_of_energies:
            energy_min = min(self.set_of_energies)
            energy_max = max(self.set_of_energies)
            if energy_max > energy_min:
                energy = str(energy_min) + '-' + str(energy_max)
            else:
                energy = energy_min
            self._parse_energies(energy)

        if self.current_table.description:
            if any(word in self.current_table.description.lower() for word in ['covariance', 'correlation', 'matrix']):
                reformatted = self._reformat_matrix()
136930
def parse_sampleinfo(data: dict) -> dict:
    

    genome_build = data['human_genome_build']
    genome_build_str = f"{genome_build['source']}{genome_build['version']}"
    if 'svdb' in data['program']:
        svdb_outpath = (f"{data['program']['svdb']['path']}")
    else:
        svdb_outpath = ''
    outdata = {
        'date': data['analysis_date'],
        'family': data['family'],
        'genome_build': genome_build_str,
        'rank_model_version': data['program']['genmod']['rank_model']['version'],
        'is_finished': True if data['analysisrunstatus'] == 'finished' else False,
        'pedigree_path': data['pedigree_minimal'],
        'peddy': {
            'ped': (data['program']['peddy']['peddy']['path'] if
                    'peddy' in data['program'] else None),
            'ped_check': (data['program']['peddy']['ped_check']['path'] if
                          'peddy' in data['program'] else None),
            'sex_check': (data['program']['peddy']['sex_check']['path'] if
                          'peddy' in data['program'] else None),
        },
        'qcmetrics_path': data['program']['qccollect']['path'],
        'samples': [],
        'snv': {
            'bcf': data['most_complete_bcf']['path'],
            'clinical_vcf': data['vcf_binary_file']['clinical']['path'],
            'gbcf': data['gbcf_file']['path'],
            'research_vcf': data['vcf_binary_file']['research']['path'],
        },
        'svdb_outpath': svdb_outpath,
        'sv': {
            'bcf': data.get('sv_bcf_file', {}).get('path'),
            'clinical_vcf': (data['sv_vcf_binary_file']['clinical']['path'] if
                             'sv_vcf_binary_file' in data else None),
            'merged': svdb_outpath,
            'research_vcf': (data['sv_vcf_binary_file']['research']['path'] if
                             'sv_vcf_binary_file' in data else None),
        },
        'version': data['mip_version'],
    }

    for sample_id, sample_data in data['sample'].items():
        sample = {
            'id': sample_id,
            'bam': sample_data['most_complete_bam']['path'],
            'sambamba': list(sample_data['program']['sambamba_depth'].values())[0]['path'],
            'sex': sample_data['sex'],
            # subsample mt is only for wgs data
            'subsample_mt': (list(sample_data['program']['samtools_subsample_mt'].values())[0]['path'] if
                             'samtools_subsample_mt' in sample_data['program'] else None),
            'vcf2cytosure': list(sample_data['program']['vcf2cytosure'].values())[0]['path'],
        }
        chanjo_sexcheck = list(sample_data['program']['chanjo_sexcheck'].values())[0]
        sample['chanjo_sexcheck'] = chanjo_sexcheck['path']
        outdata['samples'].append(sample)

    return outdata
994620
def _post_process_yaml_data(self,
                                fixture_data: Dict[str, Dict[str, Any]],
                                relationship_columns: Set[str],
                                ) -> Tuple[Dict[str, Dict[str, Any]], List[str]]:
        
        rv = {}
        relationships = set()
        if not fixture_data:
            return rv, relationships

        for identifier_id, data in fixture_data.items():
            new_data = {}
            for col_name, value in data.items():
                if col_name not in relationship_columns:
                    new_data[col_name] = value
                    continue

                identifiers = normalize_identifiers(value)
                if identifiers:
                    relationships.add(identifiers[0].class_name)

                if isinstance(value, str) and len(identifiers) <= 1:
                    new_data[col_name] = identifiers[0] if identifiers else None
                else:
                    new_data[col_name] = identifiers

            rv[identifier_id] = new_data
        return rv, list(relationships)
586647
def load(self):
        
        data = self.dict_class()
        
        for path in self.paths:
            if path in self.paths_loaded: continue
            
            try:
                with open(path, 'r') as file:
                    path_data = yaml.load(file.read())
                    data = dict_merge(data, path_data)
                self.paths_loaded.add(path)
            except IOError:
                # TODO: Log this correctly once logging is implemented
                if not path.endswith('.local.yml'):
                    print 'CONFIG NOT FOUND: %s' % (path)

        self.data = data
1196662
def _parse_config(self, config):
        
        self._batch_size = config['batch_size']
        self._im_height = config['im_height']
        self._im_width = config['im_width']
        self._num_channels = config['channels']
        self._output_layer = config['out_layer']
        self._feature_layer = config['feature_layer']
        self._out_size = None
        if 'out_size' in config.keys():
            self._out_size = config['out_size']
        self._input_arr = np.zeros([self._batch_size, self._im_height,
                                    self._im_width, self._num_channels])

        if self._model_dir is None:
            self._net_data = np.load(config['caffe_weights']).item()
            self._mean = np.load(config['mean_file'])
            self._model_filename = None
        else:
            self._net_data = None
            self._mean = np.load(os.path.join(self._model_dir, 'mean.npy'))
            self._model_filename = os.path.join(self._model_dir, 'model.ckpt')
377672
def parse_from_file
      parsed_opts = YAML.load_file(config_path)
      parsed_opts.delete_if{|k| k.to_s == 'config_path'}
      parsed_opts.each_pair{|k,v| self[k] = v}
      true
    rescue Errno::ENOENT
      false
    end
1247183
def loadYAML (filename=None, data=None):
    
    config = None

    try:
        if filename:
            data = open(filename, 'rt')

        config = yaml.load(data)

        if type(data) is file:
            data.close()
    except IOError, e:
        msg = 'Could not read AIT configuration file "%s": %s'
        log.error(msg, filename, str(e))

    return config
150737
def parse_data_to_internal(self, data=None):
        
        if data is None:
            data = parse.getdata(open(self.location_dat, "rb"),
                                 argnum=self.argnum, close=True)
        if self.filetype is "pickle":
            pickle.dump(data, open(self.location_internal, "wb"))
        elif self.filetype is "hickle":
            import hickle
            hickle.dump(data, open(self.location_internal, "wb"))
        else:
            raise ValueError(
                "Invalid filetype {} (must be {} or {})".format(
                    self.filetype, "pickle", "hickle"
                )
            )
620559
def parse(data):
    

    # convert to string
    data = data.decode("ascii")

    if len(data) == 2 and data == "A5":
        return AckMessage()

    # split into bytes
    raw = [data[i:i+2] for i in range(len(data)) if i % 2 == 0]

    if len(raw) != 7:
        return UnknownMessage(raw)

    if raw[1] == "B8":
        return StateMessage(raw)
    elif raw[3] == "12":
        return CommandMessage(raw)
    elif raw[3] == "14":
        return ScenarioTriggeredMessage(raw)
    elif raw[3] == "15":
        return RequestStatusMessage(raw)
    else:
        return UnknownMessage(raw)
462995
def parse_yaml(file)
      file_content = File.exist?(file) ? ERB.new(File.read(file)).result : '---'

      config = YAML.load(file_content) || {}
      env    = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['APP_CONFIG_ENV']

      config_from config['default'], config[env]
    end
651172
def _parse_config(config_file_path):
    
    config_file = open(config_file_path, 'r')
    config = yaml.load(config_file)
    config_file.close()
    return config
192577
def parse_json(data):
    
    sample_rate = data['datarate']
    unit = data['units']
    dtype = CIS_DATA_TYPE[data['datatype']]
    model = data['source']
    url = data['displayurl']
    return Channel(data['name'], sample_rate=sample_rate, unit=unit,
                   dtype=dtype, model=model, url=url)
662167
def parse_payload(data, payload_fmt, *payload_names):
    
    payload = struct.unpack(payload_fmt, data)
    return dict(zip(payload_names, payload))