import sys import json sys.path.append("../lib") import odgi # invoke with $python3 jsoner.py [file name without suffix] file_name = sys.argv[1] json_file = open(file_name + ".json") dat = json.load(json_file) gr = odgi.graph() handles = dict() for node in dat['node']: id = node['id'] seq = node['sequence'] handles[id] = gr.create_handle(seq) for edge in dat['edge']: fr = edge['from'] to = edge['to'] gr.create_edge(handles[fr], handles[to]) for path in dat['path']: name = path['name'] path['mapping'].sort(key=lambda x: x['rank']) path_handle = gr.create_path_handle(name) for mapping in path['mapping']: id = mapping['position']['node_id'] gr.append_step(path_handle, handles[id])
import sys sys.path.append('/home/flavia/Lab/odgi/lib') import odgi g = odgi.graph() g.load("/home/flavia/Desktop/gfa2vcf/q3.odgi") def process_step(s): h = g.get_handle_of_step(s) # gets the handle (both node and orientation) of the step is_rev = g.get_is_reverse(h) id = g.get_id(h) return str(id) + ("+" if not is_rev else "-") path_to_steps_dict = {} def create_into_dict(path, step): #dizionario nodo id come chiave e come valore un altro dizionario che ha come chiave il nome del path path_name = g.get_path_name(path) if path_name not in path_to_steps_dict: path_to_steps_dict[path_name] = [] path_to_steps_dict[path_name].append(process_step(step)) g.for_each_path_handle( lambda p: g.for_each_step_in_path(p, lambda s: create_into_dict(p, s)) ) node_id_to_path_and_pos_dict = {} for path_name, steps_list in path_to_steps_dict.items(): #print(path_name) pos = 0 for nodeId_isRev in steps_list:
def open(self, odgi_file, create=False): og = odgi.graph() ogf = og.load(odgi_file) self.odgi_graph = og self.odgi_graph.for_each_path_handle( CollectPaths(self.knownPaths, self.odgi_graph, self.base))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # this shows some examples of how to use the python bindings to odgi import sys if len(sys.argv) is 1: print("usage: PYTHONPATH=../lib", sys.argv[0], "graph.og") print("displays information about the graph, and iterates over it") print( "to build the input graph, use `odgi build -g graph.gfa -o graph.og`") exit(1) import odgi g = odgi.graph() g.load(sys.argv[1]) # the number of nodes and edges is given print("node count:", g.get_node_count()) print("path count:", g.get_path_count()) # iterate over the nodes and sum the sequence length # we have to use a counter object to count # because in python you can't assign inside lambdas 🤦 # and there are no true closures over local variables 😠class counter: total = 0 def add(self, l):
def open(self, odgifile, create=False): og = odgi.graph() ogf = og.load(odgifile) self.odgi = og