Module: Quorum::JobSerializer

Defined in:
app/models/quorum/job_serializer.rb

Class Method Summary collapse

Class Method Details

.as_gff(job) ⇒ Object

Convert jobs to GFF.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
# File 'app/models/quorum/job_serializer.rb', line 44

def self.as_gff(job)
  pragma = "##gff-version 3\n"
  source = "."
  type   = "match"
  phase  = "."
  txt    = ""
  job.each do |j|
    if j.results
      # Add sequence-region.
      unless pragma.include?(j.hit_display_id)
        pragma << "##sequence-region #{j.hit_display_id} 1 #{j.hit_len}\n"
      end

      start, stop = j.hit_from, j.hit_to

      # Set the strand based on the original start, stop.
      start > stop ? strand = "-" : strand = "+"
      # Format the start, stop for GFF.
      start, stop = format_hit_start_stop(start, stop)

      values = [
        j.hit_display_id,
        source,
        type,
        start,
        stop,
        j.evalue,
        strand,
        phase
      ]

      txt << values.join("\t") << "\tTarget=#{j.query} " <<
        "#{j.query_from} #{j.query_to};Name=#{j.query};" <<
        "identity=#{j.pct_identity};rawscore=#{j.score};" <<
        "significance=#{j.evalue}\n"
    end
  end
  txt.insert(0, pragma)
end

.as_json(job) ⇒ Object

Convert jobs to json. Uses Rails default.



7
8
9
10
11
12
13
# File 'app/models/quorum/job_serializer.rb', line 7

def self.as_json(job)
  if job.respond_to?(:errors) && job.errors.present?
    { errors: job.errors.full_messages }
  else
    job.as_json(root: false)
  end
end

.as_txt(job) ⇒ Object

Convert jobs to tab delimited output.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/quorum/job_serializer.rb', line 18

def self.as_txt(job)
  txt = ""
  values = [
    "query",
    "hit_display_id",
    "pct_identity",
    "align_len",
    "mismatch",
    "gaps",
    "query_from",
    "query_to",
    "hit_from",
    "hit_to",
    "evalue",
    "bit_score"
  ]

  job.each do |j|
    txt << j.attributes.values_at(*values).join("\t") << "\n"
  end
  txt
end

.format_hit_start_stop(start, stop) ⇒ Object

Start must be <= to stop.



87
88
89
90
91
92
93
# File 'app/models/quorum/job_serializer.rb', line 87

def self.format_hit_start_stop(start, stop)
  tmp_start, tmp_stop = start, stop
  if start > stop
    tmp_start, tmp_stop = stop, start
  end
  return tmp_start, tmp_stop
end