Module: RGFA::Lines

Included in:
RGFA
Defined in:
lib/rgfa/lines.rb

Overview

Methods for the RGFA class, which allow to handle lines of multiple types.

Instance Method Summary collapse

Instance Method Details

#<<(gfa_line_string) ⇒ RGFA #<<(gfa_line) ⇒ RGFA

Add a line to a RGFA

Overloads:

  • #<<(gfa_line_string) ⇒ RGFA

    Parameters:

    • gfa_line_string (String)

      representation of a RGFA line

  • #<<(gfa_line) ⇒ RGFA

    Parameters:

    • gfa_line (RGFA::Line)

      instance of a subclass of RGFA::Line

Returns:

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rgfa/lines.rb', line 17

def <<(gfa_line)
  gfa_line = gfa_line.to_rgfa_line(validate: @validate)
  rt = gfa_line.record_type
  case rt
  when :H
    add_header(gfa_line)
  when :S
    add_segment(gfa_line)
  when :L
    add_link(gfa_line)
  when :C
    add_containment(gfa_line)
  when :P
    add_path(gfa_line)
  when :"#"
    add_comment(gfa_line)
  else
    raise # this never happens, as already catched by gfa_line init
  end
  return self
end

#rename(old_name, new_name) ⇒ RGFA

Rename a segment or a path

@raise

if +new_name+ is already a segment or path name

Parameters:

  • old_name (String)

    the name of the segment or path to rename

  • new_name (String)

    the new name for the segment or path

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rgfa/lines.rb', line 118

def rename(old_name, new_name)
  old_name = old_name.to_sym
  new_name = new_name.to_sym
  s = segment(old_name)
  pt = nil
  if s.nil?
    pt = path(old_name)
    if pt.nil?
      raise RGFA::LineMissingError,
        "#{old_name} is not a path or segment name"
    end
  end
  if segment(new_name) or path(new_name)
    raise RGFA::DuplicatedLabelError,
      "#{new_name} is already a path or segment name"
  end
  if s
    s.name = new_name
    @segments.delete(old_name)
    @segments[new_name] = s
  else
    pt.path_name = new_name
    @paths.delete(old_name)
    @paths[new_name] = pt
  end
  self
end

#rm(segment) ⇒ RGFA #rm(path) ⇒ RGFA #rm(link) ⇒ RGFA #rm(containment) ⇒ RGFA #rm(: headers) ⇒ RGFA #rm(array) ⇒ RGFA #rm(method_name, *args) ⇒ RGFA

Delete elements from the RGFA graph

Overloads:

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rgfa/lines.rb', line 58

def rm(x, *args)
  if x.kind_of?(RGFA::Line)
    raise ArgumentError,
      "One argument required if first RGFA::Line" if !args.empty?
    case x.record_type
    when :H then raise ArgumentError, "Cannot remove single header lines"
    when :S then delete_segment(x)
    when :P then delete_path(x)
    when :L then delete_link(x)
    when :C then delete_containment(x)
    when :"#" then delete_comment(x)
    end
  elsif x.kind_of?(Symbol)
    if @segments.has_key?(x)
      if !args.empty?
        raise ArgumentError, "One arguments required if first segment name"
      end
      delete_segment(x)
    elsif @paths.has_key?(x)
      if !args.empty?
        raise ArgumentError, "One argument required if first path name"
      end
      delete_path(x)
    elsif x == :headers
      if !args.empty?
        raise ArgumentError, "One argument required if first :headers"
      end
      delete_headers
    elsif x == :comments
      if !args.empty?
        raise ArgumentError, "One argument required if first :comments"
      end
      delete_comments
    else
      if respond_to?(x)
        rm(send(x, *args))
      else
        raise ArgumentError, "Cannot remove #{x.inspect}"
      end
    end
  elsif x.kind_of?(String)
    rm(x.to_sym, *args)
  elsif x.kind_of?(Array)
    x.each {|elem| rm(elem, *args)}
  elsif x.nil?
    return self
  else
    raise ArgumentError, "Cannot remove #{x.inspect}"
  end
  return self
end