pygfa.graph_element.parser package

Submodules

pygfa.graph_element.parser.containment module

class pygfa.graph_element.parser.containment.Containment[source]

Bases: pygfa.graph_element.parser.line.Line

PREDEFINED_OPTFIELDS = {'ID': 'Z', 'RC': 'i', 'NM': 'i'}
REQUIRED_FIELDS = {'overlap': 'cig', 'from': 'lbl', 'from_orn': 'orn', 'to': 'lbl', 'to_orn': 'orn', 'pos': 'pos'}
classmethod from_string(string)[source]

Extract the containment fields from the string.

The string can contains the C character at the begin or can only contains the fields of the containment directly.

pygfa.graph_element.parser.edge module

class pygfa.graph_element.parser.edge.Edge[source]

Bases: pygfa.graph_element.parser.line.Line

REQUIRED_FIELDS = {'eid': 'oid', 'beg2': 'pos2', 'sid2': 'ref', 'end2': 'pos2', 'sid1': 'ref', 'beg1': 'pos2', 'end1': 'pos2', 'alignment': 'aln'}
classmethod from_string(string)[source]

Extract the Edge fields from the string.

The string can contains the E character at the begin or can only contains the fields of the Edge directly.

pygfa.graph_element.parser.field_validator module

Field validation module to check each field string against GFA1 and GFA2 specification.

exception pygfa.graph_element.parser.field_validator.FormatError[source]

Bases: Exception

Exception raised when a wrong type of object is given to the validator.

exception pygfa.graph_element.parser.field_validator.InvalidFieldError[source]

Bases: Exception

Exception raised when an invalid field is provided.

exception pygfa.graph_element.parser.field_validator.UnknownDataTypeError[source]

Bases: Exception

Exception raised when the datatype provided is not in the DATASTRING_VALIDATION_REGEXP dictionary.

pygfa.graph_element.parser.field_validator.is_dazzler_trace(string)[source]
pygfa.graph_element.parser.field_validator.is_gfa1_cigar(string)[source]

Check if the given string is a valid CIGAR string as defined in the GFA1 specification.

pygfa.graph_element.parser.field_validator.is_gfa2_cigar(string)[source]

Check if the given string is a valid CIGAR string as defined in the GFA2 specification.

pygfa.graph_element.parser.field_validator.is_valid(string, datatype)[source]

Check if the string respects the datatype.

Parameters:

datatype – The type of data corresponding to the string.

Returns:

True if the string respect the type defined by the datatype.

Raises:
  • UnknownDataTypeError – If the datatype is not presents in DATASTRING_VALIDATION_REGEXP.
  • UnknownFormatError – If string is not python string.
TODO:

Fix exception reference in the documentation.

pygfa.graph_element.parser.field_validator.validate(string, datatype)[source]

Return a value from the given string with the type closer to the one it’s represented.

pygfa.graph_element.parser.fragment module

class pygfa.graph_element.parser.fragment.Fragment[source]

Bases: pygfa.graph_element.parser.line.Line

REQUIRED_FIELDS = {'fbeg': 'pos2', 'fend': 'pos2', 'sid': 'id', 'sbeg': 'pos2', 'external': 'ref', 'send': 'pos2', 'alignment': 'aln'}
classmethod from_string(string)[source]

Extract the fragment fields from the string.

The string can contains the F character at the begin or can only contains the fields of the fragment directly.

pygfa.graph_element.parser.gap module

class pygfa.graph_element.parser.gap.Gap[source]

Bases: pygfa.graph_element.parser.line.Line

REQUIRED_FIELDS = {'gid': 'oid', 'variance': 'oint', 'distance': 'int', 'sid2': 'ref', 'sid1': 'ref'}
classmethod from_string(string)[source]

Extract the Gap fields from the string.

The string can contains the G character at the begin or can only contains the fields of the Gap directly.

pygfa.graph_element.parser.group module

class pygfa.graph_element.parser.group.OGroup[source]

Bases: pygfa.graph_element.parser.line.Line

REQUIRED_FIELDS = {'references': 'rfs', 'oid': 'oid'}
classmethod from_string(string)[source]

Extract the OGroup fields from the string.

The string can contains the O character at the begin or can just contains the fields of the OGroup directly.

class pygfa.graph_element.parser.group.UGroup[source]

Bases: pygfa.graph_element.parser.line.Line

REQUIRED_FIELDS = {'ids': 'ids', 'uid': 'oid'}
classmethod from_string(string)[source]

Extract the UGroup fields from the string.

The string can contains the U character at the begin or can only contains the fields of the UGroup directly.

pygfa.graph_element.parser.header module

class pygfa.graph_element.parser.header.Header[source]

Bases: pygfa.graph_element.parser.line.Line

PREDEFINED_OPTFIELDS = {'VN': 'Z', 'TS': 'i'}
classmethod from_string(string)[source]

Extract the header fields from the string.

The string can contains the H character at the begin or can only contains the fields of the header directly.

pygfa.graph_element.parser.line module

class pygfa.graph_element.parser.line.Field(name, value)[source]

Bases: object

This class represent any required field.

The type of field is bound to the field name.

name
value
exception pygfa.graph_element.parser.line.InvalidLineError[source]

Bases: Exception

Exception raised when making a Line object from a string. The number of fields gained by splittin the string must be equal to or great than the number of required field ecluding the optional first field indicating the type of the line.

class pygfa.graph_element.parser.line.Line(line_type=None)[source]

Bases: object

A generic Line, it’s unlikely that it will be directly instantiated (but could be done so). Its subclasses should be used instead.

It’s possible to instatiate a Line to save a custom line in a gfa file.

PREDEFINED_OPTFIELDS = {}
REQUIRED_FIELDS = {}
add_field(field)[source]

Add a field to the line.

It’s possible to add a Field if an only if its name is in the REQUIRED_FIELDS dictionary. Otherwise the field will be considered as an optional field and an InvalidFieldError will be raised.

Parameters:field – The field to add to the line
Raises:InvalidFieldError – If a ‘name’ and a ‘value’ attributes are not found or the field has already been added.
Note:If you want to add a Field for a custom Line object be sure to add its name to the REQUIRED_FIELDS dictionary for that particular Line subclass.
fields
classmethod from_string(string)[source]
classmethod get_static_fields()[source]
classmethod is_valid(line_)[source]

Check if the line is valid.

Defining the method here allows to have automatically validated all the line of the specifications.

remove_field(field)[source]

If the field is contained in the line it gets removed. Otherwise it does nothing, without raising any exception.

type
class pygfa.graph_element.parser.line.OptField(name, value, field_type)[source]

Bases: pygfa.graph_element.parser.line.Field

An Optional field of the form TAG:TYPE:VALUE, where: TAG match [A-Za-z0-9][A-Za-z0-9] TYPE match [AiZfJHB]

classmethod from_string(string)[source]

Create an OptField with a given string.

type
pygfa.graph_element.parser.line.is_field(field)[source]

Check if the given object is a valid field

A field is valid if it has at least a name and a value attribute/property.

pygfa.graph_element.parser.line.is_optfield(field)[source]

Check if the given object is an optfield

A field is an optfield if it’s a field with name that match a given expression and its type is defined.

pygfa.graph_element.parser.path module

class pygfa.graph_element.parser.path.Path[source]

Bases: pygfa.graph_element.parser.line.Line

PREDEFINED_OPTFIELDS = {}
REQUIRED_FIELDS = {'overlaps': 'cgs', 'path_name': 'lbl', 'seqs_names': 'lbs'}
classmethod from_string(string)[source]

Extract the path fields from the string.

The string can contains the P character at the begin or can just contains the fields of the path directly.

pygfa.graph_element.parser.segment module

class pygfa.graph_element.parser.segment.SegmentV1[source]

Bases: pygfa.graph_element.parser.line.Line

A GFA1 Segment line.

PREDEFINED_OPTFIELDS = {'LN': 'i', 'FC': 'i', 'RC': 'i', 'UR': 'Z', 'SH': 'H', 'KC': 'i'}
REQUIRED_FIELDS = {'sequence': 'seq', 'name': 'lbl'}
classmethod from_string(string)[source]

Extract the segment fields from the string.

The string can contains the S character at the begin or can only contains the fields of the segment directly.

class pygfa.graph_element.parser.segment.SegmentV2[source]

Bases: pygfa.graph_element.parser.line.Line

A GFA2 Segment line.

REQUIRED_FIELDS = {'slen': 'int', 'sid': 'id', 'sequence': 'seq2'}
classmethod from_string(string)[source]

Extract the segment fields from the string.

The string can contains the S character at the begin or can only contains the fields of the segment directly.

pygfa.graph_element.parser.segment.is_segmentv1(line_repr)[source]

Check wether a given gfa line string probably belongs to a Segment of the first GFA version.

Parameters:line_repr – A string or a Line that is supposed to represent an S line.
pygfa.graph_element.parser.segment.is_segmentv2(line_repr)[source]

Check wether a given string or line belongs to a Segment of the second GFA version.

Parameters:line_repr – A string or a Line that is supposed to represent an S line.

Module contents