Class: RGFA::Line::Segment
- Inherits:
-
RGFA::Line
- Object
- RGFA::Line
- RGFA::Line::Segment
- Defined in:
- lib/rgfa/line/segment.rb,
lib/rgfa/field_writer.rb,
lib/rgfa/field_validator.rb
Overview
A segment line of a RGFA file
Defined Under Namespace
Classes: InconsistentLengthError, UndefinedLengthError
Constant Summary collapse
- RECORD_TYPE =
:S
- REQFIELDS =
[:name, :sequence]
- PREDEFINED_OPTFIELDS =
[:LN, :RC, :FC, :KC, :SH, :UR]
- DATATYPE =
{ :name => :lbl, :sequence => :seq, :LN => :i, :RC => :i, :FC => :i, :KC => :i, :SH => :H, :UR => :Z }
Constants inherited from RGFA::Line
DELAYED_PARSING_DATATYPES, DIRECTION, FIELD_DATATYPE, OPTFIELD_DATATYPE, ORIENTATION, RECORD_TYPES, RECORD_TYPE_LABELS, REQFIELD_DATATYPE, SEPARATOR
Instance Attribute Summary collapse
-
#containments ⇒ Hash{RGFA::Line::DIRECTION => Hash{RGFA::Line::ORIENTATION => Array<RGFA::Line::Containment>}}
References to the containments in which the segment is involved.
-
#links ⇒ Hash{RGFA::Line::DIRECTION => Hash{RGFA::Line::ORIENTATION => Array<RGFA::Line::Link>}}
References to the links in which the segment is involved.
-
#paths ⇒ Hash{RGFA::Line::ORIENTATION => Array<RGFA::Line::Path>}
References to the containments in which the segment is involved.
Instance Method Summary collapse
-
#all_connections ⇒ Object
All links and containments where the segment is involved.
-
#all_containments ⇒ Object
All containments where a segment is involved.
-
#all_links ⇒ Object
All links where the segment is involved.
-
#all_paths ⇒ Object
All paths where the segment is involved.
-
#all_references ⇒ Object
All paths, links and containments where the segment is involved.
-
#coverage(count_tag: :RC, unit_length: 1) ⇒ Integer?
The coverage computed from a count_tag.
-
#coverage!(count_tag: :RC, unit_length: 1) ⇒ Integer
The coverage computed from a count_tag.
- #length ⇒ Integer?
- #length! ⇒ Integer
-
#to_gfa_field(datatype: nil) ⇒ String
private
Representation of the data for GFA fields; this method does not (in general) validate the string.
-
#to_s(without_sequence: false) ⇒ Object
String representation of the segment.
-
#to_sym ⇒ Symbol
Name of the segment as symbol.
-
#validate_gfa_field!(datatype, fieldname = nil) ⇒ void
private
Validates the object according to the provided datatype.
- #validate_length! ⇒ Object
Methods inherited from RGFA::Line
#==, #clone, #delete, #field_to_s, #fieldnames, #get, #get!, #get_datatype, #initialize, #method_missing, #optional_fieldnames, #real!, #record_type, #required_fieldnames, #respond_to?, #set, #set_datatype, subclass, #tags, #to_a, #to_rgfa_line, #validate!, #validate_field!, #virtual?
Constructor Details
This class inherits a constructor from RGFA::Line
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RGFA::Line
Instance Attribute Details
#containments ⇒ Hash{RGFA::Line::DIRECTION => Hash{RGFA::Line::ORIENTATION => Array<RGFA::Line::Containment>}}
References to the containments in which the segment is involved. The references are in four arrays which are accessed from a nested hash table. The first key is the direction (from or to), the second is the orientation (+ or -).
47 48 49 50 51 |
# File 'lib/rgfa/line/segment.rb', line 47 def containments @containments ||= {:from => {:+ => [], :- => []}, :to => {:+ => [], :- => []}} @containments end |
#links ⇒ Hash{RGFA::Line::DIRECTION => Hash{RGFA::Line::ORIENTATION => Array<RGFA::Line::Link>}}
References to the links in which the segment is involved.
The references are in four arrays which are accessed from a nested hash table. The first key is the direction (from or to), the second is the orientation (+ or -).
34 35 36 37 38 |
# File 'lib/rgfa/line/segment.rb', line 34 def links @links ||= {:from => {:+ => [], :- => []}, :to => {:+ => [], :- => []}} @links end |
#paths ⇒ Hash{RGFA::Line::ORIENTATION => Array<RGFA::Line::Path>}
References to the containments in which the segment is involved.
The references are in two arrays which are accessed from a hash table. The key is the orientation (+ or -).
63 64 65 66 |
# File 'lib/rgfa/line/segment.rb', line 63 def paths @paths ||= {:+ => [], :- => []} @paths end |
Instance Method Details
#all_connections ⇒ Object
the list shall be considered read-only, as this is a copy of the original arrays of references, concatenated to each other.
All links and containments where the segment is involved.
87 88 89 |
# File 'lib/rgfa/line/segment.rb', line 87 def all_connections all_links + all_containments end |
#all_containments ⇒ Object
the list shall be considered read-only, as this is a copy of the original arrays of references, concatenated to each other.
All containments where a segment is involved.
73 74 75 76 |
# File 'lib/rgfa/line/segment.rb', line 73 def all_containments l = self.containments l[:from][:+] + l[:from][:-] + l[:to][:+] + l[:to][:-] end |
#all_links ⇒ Object
the list shall be considered read-only, as this is a copy of the original arrays of references, concatenated to each other.
All links where the segment is involved.
80 81 82 83 |
# File 'lib/rgfa/line/segment.rb', line 80 def all_links l = self.links l[:from][:+] + l[:from][:-] + l[:to][:+] + l[:to][:-] end |
#all_paths ⇒ Object
the list shall be considered read-only, as this is a copy of the original arrays of references, concatenated to each other.
All paths where the segment is involved.
93 94 95 96 |
# File 'lib/rgfa/line/segment.rb', line 93 def all_paths pt = self.paths pt[:+] + pt[:-] end |
#all_references ⇒ Object
the list shall be considered read-only, as this is a copy of the original arrays of references, concatenated to each other.
All paths, links and containments where the segment is involved.
100 101 102 |
# File 'lib/rgfa/line/segment.rb', line 100 def all_references all_connections + all_paths end |
#coverage(count_tag: :RC, unit_length: 1) ⇒ Integer?
The coverage computed from a count_tag. If unit_length is provided then: count/(length-unit_length+1), otherwise: count/length. The latter is a good approximation if length >>> unit_length.
155 156 157 158 159 160 161 |
# File 'lib/rgfa/line/segment.rb', line 155 def coverage(count_tag: :RC, unit_length: 1) if optional_fieldnames.include?(count_tag) and self.length return (self.get(count_tag).to_f)/(self.length-unit_length+1) else return nil end end |
#coverage!(count_tag: :RC, unit_length: 1) ⇒ Integer
The coverage computed from a count_tag. If unit_length is provided then: count/(length-unit_length+1), otherwise: count/length. The latter is a good approximation if length >>> unit_length.
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/rgfa/line/segment.rb', line 167 def coverage!(count_tag: :RC, unit_length: 1) c = coverage(count_tag: count_tag, unit_length: unit_length) if c.nil? self.length! raise RGFA::Line::TagMissingError, "Tag #{count_tag} undefined for segment #{name}" else return c end end |
#length ⇒ Integer?
121 122 123 124 125 126 127 128 129 |
# File 'lib/rgfa/line/segment.rb', line 121 def length if self.LN self.LN elsif sequence != "*" sequence.length else nil end end |
#length! ⇒ Integer
136 137 138 139 140 141 |
# File 'lib/rgfa/line/segment.rb', line 136 def length! l = self.length() raise RGFA::Line::Segment::UndefinedLengthError, "No length information available" if l.nil? return l end |
#to_gfa_field(datatype: nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Representation of the data for GFA fields; this method does not (in general) validate the string. The method can be overwritten for a given class, and may take the #default_gfa_datatype into consideration.
107 |
# File 'lib/rgfa/field_writer.rb', line 107 def to_gfa_field(datatype: nil); to_sym.to_s; end |
#to_s(without_sequence: false) ⇒ Object
Returns string representation of the segment.
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/rgfa/line/segment.rb', line 180 def to_s(without_sequence: false) if !without_sequence return super() else saved = self.sequence self.sequence = "*" retval = super() self.sequence = saved return retval end end |
#to_sym ⇒ Symbol
Returns name of the segment as symbol.
193 194 195 |
# File 'lib/rgfa/line/segment.rb', line 193 def to_sym name.to_sym end |
#validate_gfa_field!(datatype, fieldname = nil) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Validates the object according to the provided datatype
247 248 249 250 251 252 253 254 |
# File 'lib/rgfa/field_validator.rb', line 247 def validate_gfa_field!(datatype, fieldname=nil) if datatype != :lbl raise RGFA::FieldParser::FormatError, "Wrong type (#{self.class}) for field #{fieldname}\n"+ "Content: <RGFA::Segment:#{self.to_s}>\n"+ "Datatype: #{datatype}" end end |
#validate_length! ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/rgfa/line/segment.rb', line 106 def validate_length! if sequence != "*" and optional_fieldnames.include?(:LN) if self.LN != sequence.length raise RGFA::Line::Segment::InconsistentLengthError, "Length in LN tag (#{self.LN}) "+ "is different from length of sequence field (#{sequence.length})" end end end |