def make_products(dataset, target_dir, gaf_path, products, ontology_graph): gafparser = GafParser() gafparser.config = assocparser.AssocParserConfig( ontology=ontology_graph, paint=True ) with open(gaf_path) as sg: lines = sum(1 for line in sg) product_files = { "gpad": open(os.path.join(os.path.split(gaf_path)[0], "{}.gpad".format(dataset)), "w"), "ttl": open(os.path.join(os.path.split(gaf_path)[0], "{}_cam.ttl".format(dataset)), "wb") } if not products["gpad"] and not products["ttl"]: # Bail if we have no products return [] # def write_gpi_entity(association, bridge, gpiwriter): with open(gaf_path) as gf: # gpi info: click.echo("Using {} as the gaf to build data products with".format(gaf_path)) if products["ttl"]: click.echo("Setting up {}".format(product_files["ttl"].name)) rdf_writer = assoc_rdfgen.TurtleRdfWriter(label=os.path.split(product_files["ttl"].name)[1] ) transformer = assoc_rdfgen.CamRdfTransform(writer=rdf_writer) parser_config = assocparser.AssocParserConfig(ontology=ontology_graph) if products["gpad"]: click.echo("Setting up {}".format(product_files["gpad"].name)) gpadwriter = GpadWriter(file=product_files["gpad"]) click.echo("Making products...") with click.progressbar(iterable=gafparser.association_generator(file=gf), length=lines) as associations: for association in associations: if products["ttl"]: if "header" not in association or not association["header"]: transformer.provenance() transformer.translate(association) if products["gpad"]: gpadwriter.write_assoc(association) # post ttl steps if products["ttl"]: click.echo("Writing ttl to disk") rdf_writer.serialize(destination=product_files["ttl"]) # After we run through associations for f in product_files.values(): f.close() return [product_files[prod].name for prod in sorted(product_files.keys()) if products[prod]]
def write_assocs(assocs, outfile, args): w = None fmt = args.to.lower() version = args.version if fmt is None or fmt == 'gaf': if version: w = GafWriter(file=outfile, version=args.version) else: w = GafWriter(file=outfile) elif fmt == 'gpad': if version: w = GpadWriter(file=outfile, version=args.version) else: w = GpadWriter(file=outfile) else: raise ValueError("Not supported: {}".format(fmt)) w.write(assocs)
def write_assocs(assocs, outfile, args): w = GpadWriter() fmt = args.to if fmt is None or fmt == 'gaf': w = GafWriter() elif fmt == 'gpad': w = GpadWriter() else: raise ValueError("Not supported: {}".format(fmt)) w.file = outfile w.write(assocs)
def convert_assocs(ont, file, outfile, p, args): assocs = p.parse(open(file, "r"), None) w = GpadWriter() fmt = args.to if fmt == 'gpad': w = GpadWriter() else: raise ValueError("Not supported: {}".format(fmt)) w.file = outfile w.write(assocs)
def test_convert_gaf_to_gpad(): p = GafParser() p.config.ecomap = EcoMap() w = GpadWriter() p2 = GpadParser() convert(POMBASE, p, w, p2)