#!/usr/bin/env python
from __future__ import division

from csv import DictReader
from collections import defaultdict

class MetadataTable(object):
    OntologyDelimiter = ':'

    def __init__(self, metadata_f, delimiter='\t'):
        reader = DictReader(metadata_f, delimiter=delimiter)
        self.FieldNames = reader.fieldnames
        self._table = [row for row in reader]

    def candidateOntologyColumns(self):
        ont_cols = defaultdict(set)

        for row in self._table:
            for field, value in row.items():
                split_val = value.split(self.OntologyDelimiter, 1)

                if len(split_val) > 1:
                    ont_cols[field].add(split_val[0])

        return ont_cols

@@ -110,16 +110,83 @@
 aultdict
+%0Afrom glob import glob%0Afrom os.path import basename, join, splitext
 %0A%0Aclass 
@@ -478,16 +478,28 @@
 mns(self
+, vocab=None
 ):%0A     
@@ -742,59 +742,762 @@
 ont_
-cols%5Bfield%5D.add(split_val%5B0%5D)%0A%0A        return ont_cols
+id = split_val%5B0%5D%0A%0A                    if vocab is None or ont_id in vocab:%0A                        ont_cols%5Bfield%5D.add(ont_id)%0A%0A        return ont_cols%0A%0Aclass VocabularySet(object):%0A    Wildcard = '*.txt'%0A%0A    def __init__(self, vocab_dir):%0A        self._vocabs = %7B%7D%0A%0A        for fp in glob(join(vocab_dir, self.Wildcard)):%0A            vocab_id = splitext(basename(fp))%5B0%5D%0A            vocab = set()%0A%0A            with open(fp, 'U') as f:%0A                for line in f:%0A                    line = line.strip()%0A%0A                    if line:%0A                        vocab.add(line)%0A%0A            self._vocabs%5Bvocab_id%5D = vocab%0A%0A    def __contains__(self, key):%0A        return key in self._vocabs%0A%0A    def __getitem__(self, key):%0A        return self._vocabs%5Bkey%5D
 %0A

Add VocabularySet class