Comments

GFA lines starting with a # symbol are considered comments. In Gfapy comments are represented by instances of the class gfapy.line.Comment. They have a similar interface to other line instances, with some differences, e.g. they do not support tags.

The comments collection

The comments of a Gfa object are accessed using the Gfa.comments property. This is a list of comment line instances. The single elements can be modified, but the list itself is read-only. To remove a comment from the Gfa, you need to find the instance in the list, and call disconnect() on it. To add a comment to a Gfa instance is done similarly to other lines, by using the Gfa.add_line(line) method.

>>> g.add_line("# this is a comment") 
>>> [str(c) for c in g.comments]
['# this is a comment']
>>> g.comments[0].disconnect()
>>> g.comments
[]

Accessing the comment content

The content of the comment line, excluding the initial # and eventual initial spacing characters, is included in the content field. The initial spacing characters can be read/changed using the spacer field. The default value is a single space.

>>> g.add_line("# this is a comment") 
>>> c = g.comments[-1]
>>> c.content
'this is a comment'
>>> c.spacer
' '
>>> c.spacer = '___'
>>> str(c)
'#___this is a comment'

Tags are not supported by comment lines. If the line contains tags, these are nor parsed, but included in the content field. Trying to set tags raises exceptions.

>>> c = gfapy.Line("# this is not a tag\txx:i:1")
>>> c.content
'this is not a tag\txx:i:1'
>>> c.xx
>>> c.xx = 1
Traceback (most recent call last):
...
gfapy.error.RuntimeError: Tags of comment lines cannot be set