def _parse_study(self, fname, node_types):
if not os.path.exists(os.path.join(self._dir, fname)):<EOL><INDENT>return None<EOL><DEDENT>nodes = {}<EOL>with open(os.path.join(self._dir, fname), "<STR_LIT>") as in_handle:<EOL><INDENT>reader = csv.reader(in_handle, dialect="<STR_LIT>")<EOL>header = self._swap_synonyms(next(reader))<EOL>hgroups = self._collapse_header(header)<EOL>htypes = self._characterize_header(header, hgroups)<EOL>for node_type in node_types:<EOL><INDENT>try:<EOL><INDENT>name_index = header.index(node_type)<EOL><DEDENT>except ValueError:<EOL><INDENT>name_index = None<EOL><DEDENT>if name_index is None:<EOL><INDENT>continue<EOL><DEDENT>in_handle.seek(<NUM_LIT:0>, <NUM_LIT:0>)<EOL>for line in reader:<EOL><INDENT>name = line[name_index]<EOL>node_index = self._build_node_index(node_type,name)<EOL>if name in header:<EOL><INDENT>continue<EOL><DEDENT>if (not name):<EOL><INDENT>continue<EOL><DEDENT>try:<EOL><INDENT>node = nodes[node_index]<EOL><DEDENT>except KeyError:<EOL><INDENT>node = NodeRecord(name, node_type)<EOL>node.metadata = collections.defaultdict(set)<EOL>nodes[node_index] = node<EOL>attrs = self._line_keyvals(line, header, hgroups, htypes, node.metadata)<EOL>nodes[node_index].metadata = attrs<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return dict([(k, self._finalize_metadata(v)) for k, v in nodes.items()])<EOL>
Parse study or assay row oriented file around the supplied base node.