Class: RGFA::Line::Containment

Inherits:
RGFA::Line show all
Defined in:
lib/rgfa/line/containment.rb

Overview

A containment line of a RGFA file

Constant Summary collapse

RECORD_TYPE =
:C
REQFIELDS =
[:from, :from_orient, :to, :to_orient, :pos, :overlap]
PREDEFINED_OPTFIELDS =
[:MQ, :NM]
DATATYPE =
{
   :from => :lbl,
   :from_orient => :orn,
   :to => :lbl,
   :to_orient => :orn,
   :pos => :pos,
   :overlap => :cig,
   :MQ => :i,
   :NM => :i,
}

Constants inherited from RGFA::Line

DELAYED_PARSING_DATATYPES, DIRECTION, FIELD_DATATYPE, OPTFIELD_DATATYPE, ORIENTATION, RECORD_TYPES, RECORD_TYPE_LABELS, REQFIELD_DATATYPE, SEPARATOR

Instance Method Summary collapse

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, #to_s, #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 Method Details

#canonical?Boolean

Returns true if the containment is canonical, false otherwise

Definition of canonical containment

A containment is canonical if the from orientation is +

Details

Each containment has an equivalent complement containment. Consider a containment of B (length:8) in A (length:100) at position 9 of A with a cigar 1M1I2M3D4M (i.e. rpos = 19).

A+ B+ 1M1I2M3D4M 9 == A- B- 4M3D2M1I1M 80
A+ B- 1M1I2M3D4M 9 == A- B+ 4M3D2M1I1M 80
A- B+ 1M1I2M3D4M 9 == A+ B- 4M3D2M1I1M 80
A- B- 1M1I2M3D4M 9 == A+ B+ 4M3D2M1I1M 80

Pos in the complement is equal to the length of A minus the right pos of B before reversing.

We require here that A != B as A == B makes no sense for containments. Thus it is always possible to express the containment using a positive from orientation.

For this reason the canon is simply defined as + from orientation.

Returns:

  • (Boolean)


87
88
89
# File 'lib/rgfa/line/containment.rb', line 87

def canonical?
  from_orient == :+
end

#from_nameSymbol

The from segment name, in both cases where from is a segment name (Symbol) or a segment (RGFA::Line::Segment)

Returns:



35
36
37
# File 'lib/rgfa/line/containment.rb', line 35

def from_name
  from.to_sym
end

#oriented_fromRGFA::OrientedSegment

Returns the oriented segment represented by the from/from_orient fields.

Returns:



22
23
24
# File 'lib/rgfa/line/containment.rb', line 22

def oriented_from
  [from, from_orient].to_oriented_segment
end

#oriented_toRGFA::OrientedSegment

Returns the oriented segment represented by the to/to_orient fields.

Returns:



28
29
30
# File 'lib/rgfa/line/containment.rb', line 28

def oriented_to
  [to, to_orient].to_oriented_segment
end

#rposInteger?

Returns the rightmost 0-based coordinate of the contained sequence in the container; nil if the overlap is unspecified.

Returns:

  • (Integer, nil)

    the rightmost 0-based coordinate of the contained sequence in the container; nil if the overlap is unspecified



48
49
50
51
52
53
54
55
56
57
# File 'lib/rgfa/line/containment.rb', line 48

def rpos
  return nil if overlap.empty?
  rpos = pos
  overlap.each do |op|
    if [:M, :D].include?(op.code)
      rpos += op.len
    end
  end
  return rpos
end

#to_nameSymbol

The to segment name, in both cases where to is a segment name (Symbol) or a segment (RGFA::Line::Segment)

Returns:



42
43
44
# File 'lib/rgfa/line/containment.rb', line 42

def to_name
  to.to_sym
end