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 = {} class InvalidFieldError(Exception):
class UnknownDataTypeError(Exception):
class FormatError(Exception):
TYPE_A = 'A'
TYPE_Z = 'Z'
JSON = 'J'
HEX_BYTE_ARRAY = 'H'
DEC_ARRAY = 'B'
GFA1_NAME = 'lbl'
GFA1_NAMES = 'lbs'
GFA1_ORIENTATION = 'orn'
GFA1_SEQUENCE = 'seq'
GFA1_CIGAR = 'cig'
GFA1_CIGARS = 'cgs'
GFA1_INT = 'pos'
GFA2_ID = 'id'
GFA2_IDS = 'ids'
GFA2_REFERENCE = 'ref'
GFA2_REFERENCES = 'rfs'
GFA2_INT = 'int'
GFA2_TRACE = 'trc'
GFA2_ALIGNMENT = 'aln'
GFA2_POSITION = 'pos2'
GFA2_CIGAR = 'cig2'
GFA2_SEQUENCE = 'seq2'
GFA2_OPTIONAL_INT = 'oint'
GFA2_OPTIONAL_ID = 'oid'
DATASTRING_VALIDATION_REGEXP = \
  {\
  TYPE_A : "^[!-~]", \
  # any printable character
  #
  TYPE_i : "^[-+]?[0-9]+$", \
  # Signed integer
  #
  TYPE_f : "^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$", \
  # Single-precision floating number
  #
  TYPE_Z : "^[ !-~]+$", \
  # Printable string, including space
  #
  JSON : "^[ !-~]+$",  \
  # JSON, excluding new-line and tab characters
  #
  HEX_BYTE_ARRAY : "^[0-9A-F]+$", \
  # Byte array in the Hex format
  #
  DEC_ARRAY : "^[cCsSiIf](,[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)+$", \
  # Integer or numeric array
  #
  GFA1_NAME : "^[!-)+-<>-~][!-~]*$", \
  # segment/path label(segment name)
  #
  GFA1_ORIENTATION : "^\+|-$", \
  #segment orientation
  #
  ###
  #'lbs' : "^[!-)+-<>-~][!-~]*[+-](,[!-)+-<>-~][!-~]*[+-])+$",
  # multiple labels with orientations, comma-sep
  #
  # Changed according to issue 59, since the comma is accepted by [!-~],
  # it's not possible to make a clear regexp for an array of labels,
  # so the implementation has been modified to reflect
  # this behaviour, splitting the labels and checking them one by one
  # with the new lbs regexp beyond.
  #
  GFA1_NAMES : "^[!-)+-<>-~][!-~]*[+-]$", \
  GFA1_SEQUENCE : "^\*$|^[A-Za-z=.]+$", \
  # nucleotide sequence(segment sequence)
  #
  GFA1_INT : "^[0-9]*$", \
  # positive integer(CLAIM ISSUE HERE, MOVE TO -> int)
  #
  GFA1_CIGAR : "^(\*|(([0-9]+[MIDNSHPX=])+))$", # CIGAR string \
  GFA1_CIGARS : "^(\*|(([0-9]+[MIDNSHPX=])+))(,(\*|(([0-9]+[MIDNSHPX=])+)))*$", \
  # multiple CIGARs, comma-sep \
  #
  'cmt' : ".*", \
  # content of comment line, everything is allowed
  #
  GFA2_ID : "^[!-~]+$", \
  # it's the lbl for GFA2
  #
  GFA2_IDS : "^[!-~]+([ ][!-~]+)*$", \
  # it's the lbs for GFA2
  #
  GFA2_REFERENCE : "^[!-~]+[+-]$", \
  GFA2_REFERENCES : "^[!-~]+[+-]([ ][!-~]+[+-])*$", \
  # array of references
  #
  GFA2_INT : "^[0-9]+$", \
  # GFA1 has pos to describe any positive integer,
  # but pos accept the empty string, while 'int' doesn't
  #
  GFA2_TRACE : "^[0-9]+(,[0-9]+)*$", \
  GFA2_ALIGNMENT : "^\*$|^[0-9]+(,[0-9]+)*$|^([0-9]+[MDIP])+$", \
  GFA2_POSITION : "^[0-9]+\$?$", \
  # pos2 represent a position in GFA2, it's similar in NO WAY
  # to pos which represent a positive integer in GFA1
  #
  GFA2_CIGAR : "^([0-9]+[MDIP])+$", \
  # CIGAR string for GFA2
  #
  GFA2_SEQUENCE : "^\*$|^[!-~]+$", # seq2 is a GFA2 sequence,
  # it's more flexible than GFA1 seq
  #
  GFA2_OPTIONAL_ID : "^\*$|^[!-~]+$", \
  # optional id  for GFA2
  #
  GFA2_OPTIONAL_INT : "^\*$|^[0-9]+$" \
  # optional int
  #
  }
def is_valid(string, datatype):
def is_dazzler_trace(string):
def is_gfa1_cigar(string):
def is_gfa2_cigar(string):
def validate(string, datatype): 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 GFA1SerializationError(Exception): pass
DEFAULT_IDENTIFIER = "no identifier given."
SEGMENT_FIELDS = [fv.GFA1_NAME, fv.GFA1_SEQUENCE]
LINK_FIELDS = [\
    fv.GFA1_NAME, \
    fv.GFA1_ORIENTATION, \
    fv.GFA1_NAME, \
    fv.GFA1_ORIENTATION, \
    fv.GFA1_CIGAR]
CONTAINMENT_FIELDS = [\
    fv.GFA1_NAME, \
    fv.GFA1_ORIENTATION, \
    fv.GFA1_NAME, \
    fv.GFA1_ORIENTATION, \
    fv.GFA1_INT, \
    fv.GFA1_CIGAR]
PATH_FIELDS = [\
    fv.GFA1_NAME, \
    fv.GFA1_NAMES, \
    fv.GFA1_CIGARS]
def serialize_node(node_, identifier=DEFAULT_IDENTIFIER):
def serialize_edge(edge_, identifier=DEFAULT_IDENTIFIER):
def _serialize_to_containment(containment_, identifier=DEFAULT_IDENTIFIER):
def _serialize_to_link(link_, identifier=DEFAULT_IDENTIFIER):
def point_to_node(gfa_, node_id):
def _serialize_subgraph_elements(subgraph_elements, gfa_=None):
def serialize_subgraph(subgraph_, identifier=DEFAULT_IDENTIFIER, gfa_=None):
def serialize_graph(graph, write_header=True):
def serialize_gfa(gfa_): class GFA2SerializationError(Exception): pass
DEFAULT_IDENTIFIER = "no identifier given."
SEGMENT_FIELDS = [\
    fv.GFA2_ID, \
    fv.GFA2_INT, \
    fv.GFA2_SEQUENCE]
EDGE_FIELDS = [\
    fv.GFA2_OPTIONAL_ID, \
    fv.GFA2_REFERENCE, \
    fv.GFA2_REFERENCE, \
    fv.GFA2_POSITION, \
    fv.GFA2_POSITION, \
    fv.GFA2_POSITION, \
    fv.GFA2_POSITION, \
    fv.GFA2_ALIGNMENT]
FRAGMENT_FIELDS = [\
    fv.GFA2_ID, \
    fv.GFA2_REFERENCE, \
    fv.GFA2_POSITION, \
    fv.GFA2_POSITION, \
    fv.GFA2_POSITION, \
    fv.GFA2_POSITION, \
    fv.GFA2_ALIGNMENT]
GAP_FIELDS = [\
    fv.GFA2_OPTIONAL_ID, \
    fv.GFA2_REFERENCE, \
    fv.GFA2_REFERENCE, \
    fv.GFA2_INT, \
    fv.GFA2_OPTIONAL_INT]
UGROUP_FIELDS = [fv.GFA2_OPTIONAL_ID, fv.GFA2_IDS]
OGROUP_FIELDS = [fv.GFA2_OPTIONAL_ID, fv.GFA2_REFERENCES]
def serialize_node(node_, identifier=DEFAULT_IDENTIFIER):
def serialize_edge(edge_, identifier=DEFAULT_IDENTIFIER):
def _serialize_to_fragment(fragment_, identifier=DEFAULT_IDENTIFIER):
def _serialize_to_gap(gap_, identifier=DEFAULT_IDENTIFIER):
def _serialize_to_edge(edge_, identifier=DEFAULT_IDENTIFIER):
def are_elements_oriented(subgraph_elements):
def _serialize_subgraph_elements(subgraph_elements, gfa_=None):
def serialize_subgraph(subgraph_, identifier=DEFAULT_IDENTIFIER, gfa_=None):
def serialize_graph(graph, write_header=True):
def serialize_gfa(gfa_): GRAPH_LOGGER = logging.getLogger(__name__)
    NODE = 0
    EDGE = 1
    SUBGRAPH = 2
        H = self._graph.__class__()
        FOLDER, _ = os.path.split(__file__)
class InvalidSearchParameters(Exception):
class InvalidElementError(Exception):
class GFAError(Exception):
class Element:
class GFA(DovetailIterator):
def _index(obj, other):
    def __init__(self, base_graph=None, is_rGFA = None):
    def __contains__(self, id_):
    def clear(self):
    def _get_virtual_id(self, increment=True):
    def _find_max_virtual_id(self):
    def nodes(self, data=False, with_sequence=False, identifier=None):
    def edges(self,identifier = None, adj_dict = False, **kwargs):
    def subgraphs(self, identifier=None):
    def _search_edge_by_key(self, edge_key):
    def _search_edge_by_nodes(self, nodes):
    def _get_edge_end_nodes(self, edge_key):
    def get(self, key):
    def as_graph_element(self, key):
    def add_graph_element(self, element):
    def add_node(self, new_node, safe=False):
    def remove_node(self, nid):
    def nodes_iter(self, data=False, with_sequence=False):
    def nbunch_iter(self, nbunch=None):
    def add_edge(self, new_edge, safe=False):
    def max_SR(self, from_node, to_node):
    def check_rGFA(self, force = False):
    def check_rGFA_nodes(self, nodes):
    def check_rGFA_node(self,node):
    def check_rGFA_edges(self, edges):
    def check_rGFA_edge(self, edge):
    def remove_edge(self, identifier):
    def remove_edges(self, from_node, to_node):
    def edges_iter(self, nbunch=None, data=False, keys=False, default=None):
    def add_subgraph(self, subgraph, safe=False):
    def remove_subgraph(self, subgraph_id):
    def subgraphs_iter(self, data=False):
    def get_subgraph(self, sub_key):
    def subgraph(self, nbunch, copy=True):
    def dovetails_subgraph(self, nbunch=None, copy=True):
    def neighbors(self, nid):
    def search(self, \
               comparator, \
               limit_type=None):
    def search_on_nodes(self, comparator):
    def search_on_edges(self, comparator):
    def search_on_subgraph(self, comparator):
    def from_string(self, string):
    def from_file(cls, filepath, is_rGFA = None): # pragma: no cover
    def pprint(self): # pragma: no cover
    def dump(self, gfa_version=1, out=None):
    def _make_edge_lut(self):
    def _make_edge_table(self):
    def _look_for_edge(self, key, edge_table):
    def __eq__(self, other):
    def __neq__(self, other):
    def compression(self, type_compression='by_nodes'):
    def overlap_consistency(self, external_file=None):
    def subgraphs_extractor(self, n_source, distance):
import copy
import sys
import logging
import networkx as nx
import unittest
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, field_validator as fv
from pygfa.graph_element import node, edge as ge, subgraph as sg
from pygfa.serializer import gfa1_serializer as gs1, gfa2_serializer as gs2
from pygfa import gfa
sys.path.insert(0, '../')



logging.basicConfig(level=logging.DEBUG)

class TestLine (unittest.TestCase):
    """The main approach is the same, to test the serialization either
    with dictionaries and with objects.

    The dictionaries are taken directly after adding the element to the
    GFA graph, this way it's possible to test the effective goal of the
    serializer.

    For dictionaries, it's tricky to test the opt_field they
    could contain due to the fact that order is not
    guaranteed. So, at least in case of dictionaries, a limit
    of 1 opt_field is taken.

    :Note:
        Especially with the serializer, 100% coverage cannot be expected
        due to the large amount of possible configurations. A general
        coverage either from dictionary and from objects will be the
        main goal.
    """

    graph = gfa.GFA()