Skip to content

Graph methods

Jambler edited this page Jun 3, 2019 · 6 revisions

Methods available for GenGraph genome graph objects

All methods available to NetworkX MultiDiGraph are also available.

To import a genome graph in python:

graph_obj = import_gg_graph(<path_to_GG_xml_file>)

To retrieve a list fo the sequences in the GenGraph object

gg_object.ids()

Example use:

>>> graph_obj = import_gg_graph('./3Genomes.xml')
>>> print(graph_obj.ids())
['H37Rv', 'H37Ra', 'W-148']

To retrieve a sequence string from the graph

gg_object.get_sequence(region_start, region_stop, seq_name)

Example use:

Where mtb_gg_object is a GenGraph object containing multiple genomes including H37Rv, and the carB gene sequence is found in MTB isolate H37Rv at position 1557101 - 1560448.

>>> carB_sequence = mtb_gg_object.get_sequence(1557101, 1560448, 'H37Rv')
>>> print(carB_sequence)
GTGCCCCGTCGCACCG...GGGGCGTCGAGCGGTGA

To extract a subgraph

gg_object.get_region_subgraph(region_start, region_stop, seq_name)

Example use:

Extract the subgraph representing the MTB carB gene.

>>> carB_subgraph = mtb_gg_object.get_region_subgraph(1557101, 1560448, 'H37Rv')
Clone this wiki locally