Parse a tab-separated file containing reaction IDs and properties

    The reaction properties are parsed according to the header which specifies
    which property is contained in each column.
541421
def parse_reaction_table_file(path, f, default_compartment):
    

    context = FilePathContext(path)

    for lineno, row in enumerate(csv.DictReader(f, delimiter=str('\t'))):
        if 'id' not in row or row['id'].strip() == '':
            raise ParseError('Expected `id` column in table')

        props = {key: value for key, value in iteritems(row) if value != ''}

        if 'equation' in props:
            props['equation'] = parse_reaction_equation_string(
                props['equation'], default_compartment)

        mark = FileMark(context, lineno + 2, 0)
        yield ReactionEntry(props, mark)
1164698
def get_parsed_data(fn, *args, **kwargs):
    
    file_format = detect_format(fn, *args, **kwargs)
    data = get_header(fn, file_format, *args, **kwargs)
    parsed_data = parse_header(data, *args, **kwargs)
    return parsed_data
300260
function(src_excel_file, dest_dir, head, separator) {

        arraySeparator = separator;

        if (!fs.existsSync(dest_dir)) {
            fs.mkdirSync(dest_dir);
        };
        console.log("parsing excel:", src_excel_file);
        var excel = xlsx.parse(src_excel_file);
        _toJson(excel, dest_dir, head);
    }
1320747
def parse_properties(parent_index_name, parent_name, nested_path, esProperties):
    
    columns = FlatList()
    for name, property in esProperties.items():
        index_name = parent_index_name
        column_name = concat_field(parent_name, name)
        jx_name = column_name

        if property.type == "nested" and property.properties:
            # NESTED TYPE IS A NEW TYPE DEFINITION
            # MARKUP CHILD COLUMNS WITH THE EXTRA DEPTH
            self_columns = parse_properties(index_name, column_name, [column_name] + nested_path, property.properties)
            columns.extend(self_columns)
            columns.append(Column(
                name=jx_name,
                es_index=index_name,
                es_column=column_name,
                es_type="nested",
                jx_type=NESTED,
                last_updated=Date.now(),
                nested_path=nested_path
            ))

            continue

        if property.properties:
            child_columns = parse_properties(index_name, column_name, nested_path, property.properties)
            columns.extend(child_columns)
            columns.append(Column(
                name=jx_name,
                es_index=index_name,
                es_column=column_name,
                es_type="source" if property.enabled == False else "object",
                jx_type=OBJECT,
                last_updated=Date.now(),
                nested_path=nested_path
            ))

        if property.dynamic:
            continue
        if not property.type:
            continue

        cardinality = 0 if not (property.store or property.enabled) and name != '_id' else None

        if property.fields:
            child_columns = parse_properties(index_name, column_name, nested_path, property.fields)
            if cardinality is None:
                for cc in child_columns:
                    cc.cardinality = None
            columns.extend(child_columns)

        if property.type in es_type_to_json_type.keys():
            columns.append(Column(
                name=jx_name,
                es_index=index_name,
                es_column=column_name,
                es_type=property.type,
                jx_type=es_type_to_json_type[property.type],
                cardinality=cardinality,
                last_updated=Date.now(),
                nested_path=nested_path
            ))
            if property.index_name and name != property.index_name:
                columns.append(Column(
                    name=jx_name,
                    es_index=index_name,
                    es_column=column_name,
                    es_type=property.type,
                    jx_type=es_type_to_json_type[property.type],
                    cardinality=0 if property.store else None,
                    last_updated=Date.now(),
                    nested_path=nested_path
                ))
        elif property.enabled == None or property.enabled == False:
            columns.append(Column(
                name=jx_name,
                es_index=index_name,
                es_column=column_name,
                es_type="source" if property.enabled == False else "object",
                jx_type=OBJECT,
                cardinality=0 if property.store else None,
                last_updated=Date.now(),
                nested_path=nested_path
            ))
        else:
            Log.warning("unknown type {{type}} for property {{path}}", type=property.type, path=parent_name)

    return columns
1367043
def parse_table_properties(doc, table, prop):
    ""

    if not table:
        return

    style = prop.find(_name('{{{w}}}tblStyle'))

    if style is not None:
        table.style_id = style.attrib[_name('{{{w}}}val')]
        doc.add_style_as_used(table.style_id)
843367
def parse_ids(self, skiprecover):
        '''
        '''
        idsfile = self.idsfile
        logging.debug("Parse idsfile `{}`".format(idsfile))
        fp = open(idsfile)
        tigs = []
        for row in fp:
            if row[0] == '#':  # Header
                continue
            atoms = row.split()
            tig, size = atoms[:2]
            size = int(size)
            if skiprecover and len(atoms) == 3 and atoms[2] == 'recover':
                continue
            tigs.append((tig, size))

        # Arrange contig names and sizes
        _tigs, _sizes = zip(*tigs)
        self.contigs = set(_tigs)
        self.sizes = np.array(_sizes)
        self.tig_to_size = dict(tigs)

        # Initially all contigs are considered active
        self.active = set(_tigs)
621067
def build_headermap(headers):
    
    # TODO: what happens if some headers are circularly dependent?
    headermap = {}
    for hfile in headers:
        headermap[hfile] = None
    for hfile in headers:
        assert (hfile.startswith("c/") or
                hfile.startswith("datatable/include/"))
        inc = find_includes(hfile)
        for f in inc:
            assert f != hfile, "File %s includes itself?" % f
            assert f.startswith("c/")
            if f not in headers:
                raise ValueError("Unknown header \"%s\" included from %s"
                                 % (f, hfile))
        headermap[hfile] = set(inc)
    return headermap
1016546
def _parse_properties(response, result_class):
    '''
    
    '''

    if response is None or response.headers is None:
        return None

    props = result_class()
    for key, value in response.headers:
        info = GET_PROPERTIES_ATTRIBUTE_MAP.get(key)
        if info:
            if info[0] is None:
                setattr(props, info[1], info[2](value))
            else:
                attr = getattr(props, info[0])
                setattr(attr, info[1], info[2](value))

    return props
682167
def __parse_chemical_data():
    ''''''
    filename = get_file('chemical_data.tsv')

    with io.open(filename, 'r', encoding='cp1252') as textfile:
        next(textfile)

        for line in textfile:
            tokens = line.strip().split('\t')

            if tokens[3] == 'FORMULA':
                # Many seemingly contradictory formulae exist,
                # depending upon the source database
                chebi_id = int(tokens[1])

                if chebi_id not in __FORMULAE:
                    __FORMULAE[chebi_id] = []

                # Append formula:
                form = Formula(tokens[4], tokens[2])
                __FORMULAE[chebi_id].append(form)

            elif tokens[3] == 'MASS':
                __MASSES[int(tokens[1])] = float(tokens[4])

            elif tokens[3] == 'CHARGE':
                __CHARGES[int(tokens[1])] = int(tokens[4]
                                                if tokens[4][-1] != '-'
                                                else '-' + tokens[4][:-1])
801383
def parseTlvProperties(response):
    
    d = {
            'raw': response,
        }

    # create a new list to consume it
    tmp = list(response)
    while tmp:
        tag = tmp[0]
        len = tmp[1]
        data = tmp[2:2 + len]

        if PCSCv2_PART10_PROPERTY_sFirmwareID == tag:
            # convert to a string
            data = "".join([chr(c) for c in data])
        # we now suppose the value is an integer
        elif 1 == len:
            # byte
            data = data[0]
        elif 2 == len:
            # 16 bits value
            data = data[1] * 256 + data[0]
        elif 4 == len:
            # 32 bits value
            data = ((data[3] * 256 + data[2]) * 256 + data[1]) * 256 + data[0]

        # store the value in the dictionnary
        try:
            d[Properties[tag]] = data
        except KeyError:
            d["UNKNOWN"] = data

        del tmp[0:2 + len]

    return d
864705
public static List<IReaction> getAllReactions(IChemFile file) {
        List<IReaction> reactonList = new ArrayList<IReaction>();
        List<IChemModel> chemModel = getAllChemModels(file);
        for (int f = 0; f < chemModel.size(); f++) {
            for (IReaction reaction : chemModel.get(f).getReactionSet().reactions()) {
                reactonList.add(reaction);
            }
        }
        return reactonList;
    }
1282796
def load
      parsed = JSON.parse(File.read(SPECPATH))
      structs = StructureContainer.new(parsed['PropertyTypes'])

      parsed['ResourceTypes'].each do |key, spec|
        match = key.match(/\A(\w+)::(\w+)::(\w+)\z/)

        register(match[1], match[2], match[3], spec, structs.search(key))
      end
    end
389564
def parse_compound_table_file(path, f):
    

    context = FilePathContext(path)

    for i, row in enumerate(csv.DictReader(f, delimiter=str('\t'))):
        if 'id' not in row or row['id'].strip() == '':
            raise ParseError('Expected `id` column in table')

        props = {key: value for key, value in iteritems(row) if value != ''}

        if 'charge' in props:
            props['charge'] = int(props['charge'])

        mark = FileMark(context, i + 2, None)
        yield CompoundEntry(props, mark)
434095
function parse(contents, retained, parser) {
    var errors = [], data = [], lines = 0;

    // optional parser
    if (!parser) parser = JSON;

    // process each line of the file
    contents.toString().split('\n').forEach(function(line) {
        if (!line) return;
        lines++;
        try {
            data.push(parser.parse(line));
        } catch (e) {
            e.line = line;
            errors.push(e);
        }
    });

    // if no errors/data, don't return an empty array
    var ret = {};
    if (errors.length) ret.errors = errors;
    if (data.length) ret.data = data;

    // if every line failed, probably not line-delimited
    if (errors.length == lines) ret.errors = retained;

    return ret;
}
101621
def restore_site_properties(self, site_property="ff_map", filename=None):
        

        # only for pdb
        if not self.control_params["filetype"] == "pdb":
            raise ValueError()

        filename = filename or self.control_params["output"]
        bma = BabelMolAdaptor.from_file(filename, "pdb")
        pbm = pb.Molecule(bma._obmol)

        assert len(pbm.residues) == sum([x["number"]
                                         for x in self.param_list])

        packed_mol = self.convert_obatoms_to_molecule(
            pbm.residues[0].atoms, residue_name=pbm.residues[0].name,
            site_property=site_property)

        for resid in pbm.residues[1:]:
            mol = self.convert_obatoms_to_molecule(
                resid.atoms, residue_name=resid.name,
                site_property=site_property)
            for site in mol:
                packed_mol.append(site.species, site.coords,
                                  properties=site.properties)

        return packed_mol
773529
def parse_table_column_properties(doc, cell, prop):
    ""

    if not cell:
        return

    grid = prop.find(_name('{{{w}}}gridSpan'))

    if grid is not None:
        cell.grid_span = int(grid.attrib[_name('{{{w}}}val')])

    vmerge = prop.find(_name('{{{w}}}vMerge'))

    if vmerge is not None:
        if _name('{{{w}}}val') in vmerge.attrib:
            cell.vmerge = vmerge.attrib[_name('{{{w}}}val')]
        else:
            cell.vmerge = ""
566400
def _parseHeader (self, line, lineno, log):
    """"""
    if line.startswith('#') and line.find(':') > 0:
      tokens = [ t.strip().lower() for t in line[1:].split(":", 1) ]
      name   = tokens[0]
      pos    = SeqPos(line, lineno)

      if name in self.header:
        msg = 'Ignoring duplicate header parameter: %s'
        log.warning(msg % name, pos)
      else:
        for expected in ['seqid', 'version']:
          if name == expected:
            value = util.toNumber(tokens[1], None)
            if value is None:
              msg = 'Parameter "%s" value "%s" is not a number.'
              log.error(msg % (name, tokens[1]), poss)
            else:
              self.header[name] = value