예제 #1
0
def read_ontologies(filenames):
    global options

    ontology_by_name = {}

    for fn in filenames:
        # The way to get ontology names from .obo is a bit flaky, so use
        # the given file basename to identify the ontologies.
        bn = os.path.basename(fn)
        bn = bn.replace(".obo","")
        
        assert bn not in ontology_by_name, "Error: ontology '%s' appears multiple times!"

        try:
            with open(fn) as f:
                try:
                    all_terms, term_by_id = parse_obo(f)
                    ontology_by_name[bn] = (all_terms, term_by_id) 
                except Exception, e:
                    print >> sys.stderr, "ERROR: failed to parse %s: %s" % (fn, e)
                    print >> sys.stderr, """
########################################
#
# Warning: could not parse ontology
#     %s.
# Matches will not be performed against
# this ontology.
#
########################################""" % bn
        except IOError, e:
            print >> sys.stderr, "Error: failed to read %s: %s" % (fn, e)
            return None
예제 #2
0
def read_bridge(filename):
    # the "bridge" format is just a subset of the full OBO format;
    # read in normally

    try:
        with open(filename) as f:
            all_terms, term_by_id = parse_obo(f, include_nameless=True)
    except Exception, e:
        print >> sys.stderr, "Warning: failed to read \"bridge\" %s: %s" % (filename, e)
        print >> sys.stderr, "         Mappings will not be applied."
        return {}