def create_from_file(self, file=None, fmt='gaf', skim=True, **args): """ Creates from a file. Arguments --------- file : str or file input file or filename format : str name of format e.g. gaf """ p = None if fmt == 'gaf': p = GafParser() elif fmt == 'gpad': p = GpadParser() elif fmt == 'hpoa': p = HpoaParser() else: logging.error("Format not recognized: {}".format(fmt)) logging.info("Parsing {} with {}/{}".format(file, fmt, p)) if skim: results = p.skim(file) return self.create_from_tuples(results, **args) else: assocs = p.parse(file, skipheader=True) return self.create_from_assocs(assocs, **args)
def create_from_remote_file(self, group, snapshot=True, **args): """ Creates from remote GAF """ import requests url = "http://snapshot.geneontology.org/annotations/{}.gaf.gz".format(group) r = requests.get(url, stream=True, headers={'User-Agent': get_user_agent(modules=[requests], caller_name=__name__)}) p = GafParser() results = p.skim(r.raw) return self.create_from_tuples(results, **args)
def test_skim_gaf(): p = GafParser() p.config.ecomap = EcoMap() results = p.skim(open(POMBASE, "r")) assert len(results) == 370 for r in results: print(str(r)) (s, sn, o) = r assert o.startswith('GO:') assert s.startswith('PomBase:')
def test_skim_gaf_qualifiers(): p = GafParser() p.config.ecomap = EcoMap() p.config.remove_double_prefixes = True results = p.skim(open(QGAF, "r")) for r in results: print(str(r)) (s, sn, o) = r assert o.startswith('GO:') assert s.startswith('MGI:') or s.startswith('PomBase') assert len(results) == 5 # ensure NOTs are skipped p.config.exclude_relations = ['contributes_to', 'colocalizes_with'] results = p.skim(open(QGAF, "r")) for r in results: (s, sn, o) = r assert o.startswith('GO:') assert s.startswith('MGI:') or s.startswith('PomBase') assert len(results) == 3 # ensure NOTs and excludes relations skipped
def create_from_remote_file(self, group, snapshot=True, **args): """ Creates from remote GAF """ import requests url = "http://snapshot.geneontology.org/annotations/{}.gaf.gz".format(group) r = requests.get(url, stream=True) p = GafParser() results = p.skim(r.raw) return self.create_from_tuples(results, **args)