Module: GenomerPluginSummary::Enumerators

Included in:
Contigs, Metrics, Sequences
Defined in:
lib/genomer-plugin-summary/enumerators.rb

Instance Method Summary collapse

Instance Method Details

#enumerator_for(type, scaffold) ⇒ Object



5
6
7
# File 'lib/genomer-plugin-summary/enumerators.rb', line 5

def enumerator_for(type,scaffold)
  send('enumerator_for_' + type.to_s, scaffold)
end

#enumerator_for_all(scaffold) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/genomer-plugin-summary/enumerators.rb', line 67

def enumerator_for_all(scaffold)
  scaffold.inject([0,[]]) do |memo,entry|
    position, entries = memo

    i = {:sequence   => entry.sequence,
         :start      => position + 1,
         :stop       => position + entry.sequence.length,
         :type       => entry.entry_type,
         :id         => entry.entry_type == :sequence ? entry.source : nil}

    [position + entry.sequence.length, entries << i]
  end.last
end

#enumerator_for_contig(scaffold) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/genomer-plugin-summary/enumerators.rb', line 19

def enumerator_for_contig(scaffold)
  genome = scaffold.mapping(&:sequence).to_a.join
  regions = genome.
    gsub(/([^Nn])([Nn])/,'\1 \2').
    gsub(/([Nn])([^Nn])/,'\1 \2').
    scan(/[^\s]+/)

  regions.inject([0,1,[]]) do |memo,entry|
    position, number, entries = memo

    if entry.downcase.include? 'n'
      next [position + entry.length, number, entries]
    end

    i = {:sequence => entry,
         :start    => position + 1,
         :stop     => position + entry.length,
         :type     => :contig,
         :id       => number}

    [position + entry.length, number + 1, entries << i]
  end.last
end

#enumerator_for_gap(scaffold) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/genomer-plugin-summary/enumerators.rb', line 43

def enumerator_for_gap(scaffold)
  genome = scaffold.mapping(&:sequence).to_a.join
  regions = genome.
    gsub(/([^Nn])([Nn])/,'\1 \2').
    gsub(/([Nn])([^Nn])/,'\1 \2').
    scan(/[^\s]+/)

  regions.inject([0,1,[]]) do |memo,entry|
    position, number, entries = memo

    unless entry.downcase.include? 'n'
      next [position + entry.length, number, entries]
    end

    i = {:sequence => entry,
         :start    => position + 1,
         :stop     => position + entry.length,
         :type     => :gap,
         :id       => number}

    [position + entry.length, number + 1, entries << i]
  end.last
end

#enumerator_for_sequence(scaffold) ⇒ Object



9
10
11
12
# File 'lib/genomer-plugin-summary/enumerators.rb', line 9

def enumerator_for_sequence(scaffold)
  enumerator_for_all(scaffold).
    selecting{|i| i[:type] == :sequence}
end

#enumerator_for_unresolved(scaffold) ⇒ Object



14
15
16
17
# File 'lib/genomer-plugin-summary/enumerators.rb', line 14

def enumerator_for_unresolved(scaffold)
  enumerator_for_all(scaffold).
    selecting{|i| i[:type] == :unresolved}
end