class InvalidNodeError(Exception):
class Node:
def is_node(obj):
    def __init__(self, node_id, sequence, length, opt_fields={}):
    def nid(self):
    def sequence(self):
    def slen(self):
    def opt_fields(self):
    def from_line(cls, segment_line):
    def __eq__(self, other):
    def __neq__(self, other):
    def __str__(self): # pragma: no cover class InvalidEdgeError(Exception):
class Edge:
def is_edge(obj):
    def __init__(self, \
                  edge_id, \
                  from_node, from_orn, \
                  to_node, to_orn, \
                  from_positions, \
                  to_positions, \
                  alignment, \
                  distance=None, \
                  variance=None, \
                  opt_fields={}, \
                  is_dovetail=False):
    def eid(self):
    def from_node(self):
    def from_orn(self):
    def to_orn(self):
    def to_node(self):
    def from_positions(self):
    def to_positions(self):
    def alignment(self):
    def distance(self):
    def variance(self):
    def opt_fields(self):
    def is_dovetail(self):
    def from_segment_end(self):
    def to_segment_end(self):
    def _set_segments_end(self):
    def _set_segments_end_link(self):
    def _set_segments_end_edge(self):
    def from_line(cls, line_):
    def __eq__(self, other):
    def __neq__(self, other):
    def __str__(self): # pragma: no cover class InvalidSubgraphError(Exception): pass
class Subgraph:
def is_subgraph(obj):
    def __init__(self, graph_id, elements, opt_fields={}):
    def is_path(self):
    def sub_id(self):
    def elements(self):
    def opt_fields(self):
    def from_line(cls, line_):
    def as_dict(self):
    def __eq__(self, other):
    def __neq__(self, other):
    def __str__(self): # pragma: no cover class Header(line.Line):
    PREDEFINED_OPTFIELDS = \
      { \
        'VN' : fv.TYPE_Z, \
        'TS' : fv.TYPE_i \
      }
    def __init__(self):
    def from_string(cls, string): def is_segmentv1(line_repr):
def is_segmentv2(line_repr):
    def __init__(self):
    def from_string(cls, string):
    def __init__(self):
    def from_string(cls, string):
class SegmentV1(line.Line):
class SegmentV2(line.Line):
    REQUIRED_FIELDS = { \
    'name' : fv.GFA1_NAME, \
    'sequence' : fv.GFA1_SEQUENCE \
    }
    PREDEFINED_OPTFIELDS = { \
    'LN' : fv.TYPE_i, \
    'RC' : fv.TYPE_i, \
    'FC' : fv.TYPE_i, \
    'KC' : fv.TYPE_i, \
    'SH' : fv.HEX_BYTE_ARRAY, \
    'UR' : fv.TYPE_Z \
    }
    REQUIRED_FIELDS = { \
    'sid' : fv.GFA2_ID, \
    'slen' : fv.GFA2_INT, \
    'sequence' : fv.GFA2_SEQUENCE \
    } class Link(line.Line):
    def __init__(self):
    def from_string(cls, string):
    REQUIRED_FIELDS = { \
    'from' : fv.GFA1_NAME, \
    'from_orn' : fv.GFA1_ORIENTATION, \
    'to': fv.GFA1_NAME, \
    'to_orn' : fv.GFA1_ORIENTATION, \
    'overlap' : fv.GFA1_CIGAR \
    }
    PREDEFINED_OPTFIELDS = { \
    'MQ' : fv.TYPE_i, \
    'NM' : fv.TYPE_i, \
    'RC' : fv.TYPE_i, \
    'FC' : fv.TYPE_i, \
    'KC' : fv.TYPE_i, \
    'ID' : fv.TYPE_Z \
    } class Path(line.Line):
    def __init__(self):
    def from_string(cls, string):
    REQUIRED_FIELDS = { \
    'path_name' : fv.GFA1_NAME, \
    'seqs_names' : fv.GFA1_NAMES, \
    'overlaps': fv.GFA1_CIGARS \
    }
    PREDEFINED_OPTFIELDS = {} class Containment(line.Line):
    def __init__(self):
    def from_string(cls, string):
    REQUIRED_FIELDS = { \
    'from' : fv.GFA1_NAME, \
    'from_orn' : fv.GFA1_ORIENTATION, \
    'to': fv.GFA1_NAME, \
    'to_orn' : fv.GFA1_ORIENTATION, \
    'pos' : fv.GFA1_INT, \
    'overlap' : fv.GFA1_CIGAR \
    }
    PREDEFINED_OPTFIELDS = { \
    'NM' : fv.TYPE_i, \
    'RC' : fv.TYPE_i, \
    'ID' : fv.TYPE_Z \
    } class Fragment(line.Line):
    def __init__(self):
    def from_string(cls, string):
    REQUIRED_FIELDS = { \
    'sid' : fv.GFA2_ID, \
    'external' : fv.GFA2_REFERENCE, \
    'sbeg' : fv.GFA2_POSITION, \
    'send' : fv.GFA2_POSITION, \
    'fbeg' : fv.GFA2_POSITION, \
    'fend' : fv.GFA2_POSITION, \
    'alignment' : fv.GFA2_ALIGNMENT \
    } class Edge(line.Line):
    def __init__(self):
    def from_string(cls, string):
    REQUIRED_FIELDS = { \
    'eid' : fv.GFA2_OPTIONAL_ID, \
    'sid1' : fv.GFA2_REFERENCE, \
    'sid2' : fv.GFA2_REFERENCE, \
    'beg1' : fv.GFA2_POSITION, \
    'end1' : fv.GFA2_POSITION, \
    'beg2' : fv.GFA2_POSITION, \
    'end2' : fv.GFA2_POSITION, \
    'alignment' : fv.GFA2_ALIGNMENT \
    } class Gap(line.Line):
    def __init__(self):
    def from_string(cls, string):
    REQUIRED_FIELDS = { \
    'gid' : fv.GFA2_OPTIONAL_ID, \
    'sid1' : fv.GFA2_REFERENCE, \
    'sid2' : fv.GFA2_REFERENCE, \
    'distance' : fv.GFA2_INT, \
    'variance' : fv.GFA2_OPTIONAL_INT \
    } class OGroup(line.Line):
class UGroup(line.Line):
    def __init__(self):
    def from_string(cls, string):
    def __init__(self):
    def from_string(cls, string):
    REQUIRED_FIELDS = { \
    'oid' : fv.GFA2_OPTIONAL_ID, \
    'references' : fv.GFA2_REFERENCES \
    }
    REQUIRED_FIELDS = { \
    'uid' : fv.GFA2_OPTIONAL_ID, \
    'ids' : fv.GFA2_IDS \
    } class InvalidLineError(Exception):
class Line:
class Field:
class OptField(Field):
def is_field(field):
def is_optfield(field):
    def __init__(self, line_type=None):
    def is_valid(cls, line_):
    def get_static_fields(cls):
    def type(self):
    def fields(self):
    def add_field(self, field):
    def remove_field(self, field):
    def from_string(cls, string): # pragma: no cover
    def __eq__(self, other):
    def __neq__(self, other):
    def __str__(self): # pragma: no cover
    def __init__(self, name, value):
    def name(self):
    def value(self):
    def __eq__(self, other):
    def __neq__(self, other):
    def __str__(self): # pragma: no cover
    def __init__(self, name, value, field_type):
    def type(self):
    def from_string(cls, string):
    def __eq__(self, other):
    def __neq__(self, other):
    def __str__(self): # pragma: no cover
    REQUIRED_FIELDS = {}
    PREDEFINED_OPTFIELDS = {}
import sys
import unittest
import copy
import re
from pygfa.graph_element import node, edge as graph_edge, subgraph
from pygfa.graph_element.parser import header, segment, link, path, containment
from pygfa.graph_element.parser import fragment, edge, gap, group
from pygfa.graph_element.parser import line
        self.assertTrue (node_.sequence == seg.fields['sequence'].value)
        self.assertTrue (node_.opt_fields['RC'].value == seg.fields['RC'].value)

        
    def test_edge_from_link (self):
        line = link.Link.from_string ("L\t3\t+\t65\t-\t47M\tui:Z:test\tab:Z:another_test")
        ed = graph_edge.Edge.from_line (line)
        self.assertTrue (ed.eid == "*")
        self.assertTrue (ed.from_node == line.fields['from'].value)
        self.assertTrue (ed.from_orn == line.fields['from_orn'].value)
        self.assertTrue (ed.to_node == line.fields['to'].value)
        self.assertTrue (ed.to_orn == line.fields['to_orn'].value)
        self.assertTrue (ed.from_positions == (None, None))
        self.assertTrue (ed.to_positions == (None, None))
        self.assertTrue (ed.alignment == line.fields['overlap'].value)
        self.assertTrue (len (ed.opt_fields) == 2)
        self.assertTrue (ed.opt_fields['ui'] == line.fields['ui'])
        self.assertTrue (ed.opt_fields['ui'].value == "test")
        self.assertTrue (ed.opt_fields['ab'].value == "another_test")

        line = link.Link.from_string ("L\t3\t+\t65\t-\t47M\tui:Z:test\tab:Z:another_test\tID:Z:3_to_65")
        ed = graph_edge.Edge.from_line (line)
        self.assertTrue (ed.eid == "3_to_65")


    def test_edge_from_containment (self):
        line = containment.Containment.from_string ("C\ta\t+\tb\t-\t10\t*\tui:Z:test\tab:Z:another_test")
        ed = graph_edge.Edge.from_line (line)
        self.assertTrue (ed.eid == "*")
        self.assertTrue (ed.from_node == line.fields['from'].value)
        self.assertTrue (ed.from_orn == line.fields['from_orn'].value)
        self.assertTrue (ed.to_node == line.fields['to'].value)
        self.assertTrue (ed.to_orn == line.fields['to_orn'].value)
        self.assertTrue (ed.from_positions == (None, None))
        self.assertTrue (ed.to_positions == (None, None))
        self.assertTrue (ed.alignment == line.fields['overlap'].value)
        self.assertTrue (len (ed.opt_fields) == 3)
        self.assertTrue (ed.opt_fields['pos'] == line.fields['pos'])
        self.assertTrue (ed.opt_fields['ui'] == line.fields['ui'])
        self.assertTrue (ed.opt_fields['ui'].value == "test")
        self.assertTrue (ed.opt_fields['ab'].value == "another_test")

        line = containment.Containment.from_string ("C\ta\t+\tb\t-\t10\t*\tui:Z:test\tab:Z:another_test\tID:Z:a_to_b")
        ed = graph_edge.Edge.from_line (line)
        self.assertTrue (ed.eid == "a_to_b")
        
        
    def test_edge_from_fragment (self):
        line = fragment.Fragment.from_string ("F\t12\t2-\t0\t140$\t0\t140\t11M\tui:Z:test\tab:Z:another_test")
        ed = graph_edge.Edge.from_line (line)

        self.assertTrue (ed.eid == None)
        self.assertTrue (ed.from_node == line.fields['sid'].value)
        self.assertTrue (ed.from_orn == None)
        self.assertTrue (ed.to_node == line.fields['external'].value[0:-1])
        self.assertTrue (ed.to_orn == line.fields['external'].value[-1:])
        self.assertTrue (ed.from_positions == (line.fields['sbeg'].value, line.fields['send'].value))
        self.assertTrue (ed.to_positions == (line.fields['fbeg'].value, line.fields['fend'].value))
        self.assertTrue (ed.alignment == line.fields['alignment'].value)
        self.assertTrue (len (ed.opt_fields) == 2)
        self.assertTrue (ed.opt_fields['ui'] == line.fields['ui'])
        self.assertTrue (ed.opt_fields['ui'].value == "test")
        self.assertTrue (ed.opt_fields['ab'].value == "another_test")


    def test_edge_from_edge (self):
        line = edge.Edge.from_string ("E\t*\t23-\t16+\t0\t11\t0\t11\t11M\tui:Z:test\tab:Z:another_test")
        ed = graph_edge.Edge.from_line (line)

        self.assertTrue (ed.eid == line.fields['eid'].value)
        self.assertTrue (ed.from_node == line.fields['sid1'].value[0:-1])
        self.assertTrue (ed.from_orn == line.fields['sid1'].value[-1:])
        self.assertTrue (ed.to_node == line.fields['sid2'].value[0:-1])
        self.assertTrue (ed.to_orn == line.fields['sid2'].value[-1:])
        self.assertTrue (ed.from_positions == (line.fields['beg1'].value, line.fields['end1'].value))
        self.assertTrue (ed.to_positions == (line.fields['beg2'].value, line.fields['end2'].value))
        self.assertTrue (ed.alignment == line.fields['alignment'].value)
        self.assertTrue (len (ed.opt_fields) == 2)
        self.assertTrue (ed.opt_fields['ui'] == line.fields['ui'])
        self.assertTrue (ed.opt_fields['ui'].value == "test")
        self.assertTrue (ed.opt_fields['ab'].value == "another_test")

        
    def test_edge_from_gap (self):
        line = gap.Gap.from_string ("G\tg\tA+\tB-\t1000\t*\tui:Z:test\tab:Z:another_test")
        ed = graph_edge.Edge.from_line (line)

        self.assertTrue (ed.eid == line.fields['gid'].value)
        self.assertTrue (ed.from_node == line.fields['sid1'].value[0:-1])
        self.assertTrue (ed.from_orn == line.fields['sid1'].value[-1:])
        self.assertTrue (ed.to_node == line.fields['sid2'].value[0:-1])
        self.assertTrue (ed.to_orn == line.fields['sid2'].value[-1:])
        self.assertTrue (len (ed.opt_fields) == 2)

        self.assertTrue (ed.distance == 1000)
        self.assertTrue (ed.variance == "*")
                             
        self.assertTrue (ed.opt_fields['ui'].value == "test")
        self.assertTrue (ed.opt_fields['ab'].value == "another_test")


    def test_subgraph_from_path (self):
        line = path.Path.from_string ("P\t14\t11+,12+\t122M\tui:Z:test\tab:Z:another_test")
        sb = subgraph.Subgraph.from_line (line)

        self.assertTrue (sb.sub_id == line.fields['path_name'].value)
        self.assertTrue ([u+v for u,v in sb.elements.items()] == line.fields['seqs_names'].value)
        self.assertTrue (sb.opt_fields['overlaps'].value == line.fields['overlaps'].value)


    def test_subgraph_from_ogroup (self):
        line = group.OGroup.from_string ("O\t15\t11+ 11_to_13+ 13+\txx:i:-1")
        sb = subgraph.Subgraph.from_line (line)

        self.assertTrue (sb.sub_id == line.fields['oid'].value)
        self.assertTrue ([u+v for u,v in sb.elements.items()] == line.fields['references'].value)
        self.assertTrue (sb.opt_fields['xx'].value == line.fields['xx'].value)

        
    def test_subgraph_from_ugroup (self):

        line = group.UGroup.from_string ("U\t16sub\t2 3\txx:i:-1")