mygfa: A Basic GFA Data Model¶
This library parses, represents, and emits pangenomic variation graphs in the GFA format. Basic use looks like this:
import mygfa
import sys
graph = mygfa.Graph.parse(sys.stdin)
seg_depths = {name: 0 for name in graph.segments}
for path in graph.paths.values():
for step in path.segments:
seg_depths[step.name] += 1
The mygfa.Graph
class represents an entire GFA file.
You can work down the object hierarchy from there to see everything that the
file contains.
mygfa is on PyPI, so you can install it with pip install mygfa
.
API Reference¶
Simple GFA parsing, printing, and pre-processing in Python.
- class mygfa.Graph(headers: List[Header], segments: Dict[str, Segment], links: List[Link], paths: Dict[str, Path])¶
An entire GFA file.
- headers: List[Header]¶
Header (H) lines in the GFA file.
- emit(outfile: TextIO, showlinks: bool = True) None ¶
Emit a GFA file.
- class mygfa.Segment(name: str, seq: Strand)¶
A GFA segment is nucleotide sequence.
- name: str¶
The segment’s name as declared in the GFA file.
- class mygfa.Link(from_: Handle, to_: Handle, overlap: Alignment)¶
A GFA link is an edge connecting two handles.
- class mygfa.Path(name: str, segments: List[Handle], olaps: List[Alignment] | None)¶
A GFA path is a walk through the graph.
- name: str¶
“The path’s name as declared in the GFA file.
- classmethod parse_inner(name: str, seq: str, overlaps: str) Path ¶
Parse a GFA path, assuming that the name, sequence and overlaps have already been extracted.
- class mygfa.Handle(name: str, ori: bool)¶
A specific orientation for a segment, referenced by name.
- name: str¶
A segment’s name.
- ori: bool¶
The orientation: True for forward (+), False for backward (-).
- linkstr() str ¶
This is how a link wants handles to be string-ified.
- class mygfa.Strand¶
A strand is a string that contains only A, T, G, C, or N.
- class mygfa.Alignment(ops: List[Tuple[int, AlignOp]])¶
CIGAR representation of a sequence alignment.
- class mygfa.AlignOp(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)¶
An operator in an Alignment.