Class: ViralSeq::RecencyReport

Inherits:
Object
  • Object
show all
Defined in:
lib/viral_seq/recency_report.rb

Overview

class to generate recency report

Class Method Summary collapse

Class Method Details

.generate(log, outfile) ⇒ NilClass

to generate the recency report in .pdf format.

Parameters:

  • log (Hash)

    Hash from the json summary string of the SDRM report

  • outfile (String)

    path to the output file

Returns:

  • (NilClass)

    .pdf file generated by the method. Return nil.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
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
109
110
111
112
113
114
115
116
117
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/viral_seq/recency_report.rb', line 12

def self.generate(log, outfile)

  recency_color = {
    "recent" => "d42828",
    "chronic" => "0666bf",
    "indeterminant"=> "f78914",
    "insufficient data" => "7d7b79"
  }

  dual_infection_color = {
    "Yes" => "ffcc00",
    "No" => "339900",
    "insufficient data" => "7d7b79"
  }

  Prawn::Document.generate(outfile, margin: 75) do

    def text_format(text1, text2)
      [
        { text: text1 + "\s" * (30 - text1.size), styles: [:bold], size: 14, font: "Courier"},
        { text: text2, size: 14, styles: [:underline]}
      ]
    end

    def text_format2(text1, text2, text3, text4)
        text1 = text1.to_s
        text2 = text2.to_s
        text3 = text3.to_s
        text4 = text4.to_s

        [
          { text: "\s\s\s" + text1 + "\s"*(11-text1.size) +
        text2 + "\s"*(19-text2.size) +
        text3 + "\s"*(11-text3.size) + text4,
          size: 14,
          font: "Courier"
          }
        ]
    end

    text("Quantitative Recency Report by MPID-NGS",
    size: 18,
    align: :center,
    style: :bold
    )

    move_down 20

    formatted_text(
      text_format("Library ID:", log[:sample_id])
    )

    move_down 10

    formatted_text(
      text_format("ViralSeq Version:", ViralSeq::VERSION.to_s)

    )

    formatted_text(
      text_format("TCS Version:", ViralSeq::TCS_VERSION.to_s)
    )

    formatted_text(
      text_format("Processed Date", Time.now.strftime("%Y-%b-%d %H:%M"))
    )

    move_down 30

    text("Summary of parameters",
    size: 16,
    style: :bold
    )

    move_down 20

    formatted_text(
      [
        { text: "REGION" + "\s"*5 + "AVG. DIVERSITY" + "\s"*5 + "DIST20" + "\s"*5 + "DEPTH",
          styles: [:bold],
          size: 14,
          font: "Courier"
        },
      ]
    )

    move_down 5

    formatted_text(
      text_format2("RT", log[:pi_RT], log[:dist20_RT], log[:tcs_RT])
    )

    formatted_text(
      text_format2("V1V3", log[:pi_V1V3], log[:dist20_V1V3], log[:tcs_V1V3])
    )

    formatted_text(
      text_format2("P17", log[:pi_P17], log[:dist20_P17], log[:tcs_P17])
    )

    move_down 30

    formatted_text(
      [
        { text: "Prediction: ",
          styles: [:bold],
          size: 16,
        },

        { text: log[:recency].capitalize + " Infection",
          styles: [:bold],
          size: 16,
          color: recency_color[log[:recency]]
        },

        { text: " (9-month cutoff)",
          size: 14,
        },
      ]
    )

    move_down 20

    formatted_text(
      [
        {
          text: "Estimated Day Post Infection: ",
          styles: [:bold],
          size: 16
        },

        {
          text: log[:dpi].to_s +
          " (" + log[:dpi_lwr].to_s + "-" + log[:dpi_upr].to_s + ") Days",
          styles: [:bold],
          size: 16,
          color: recency_color[log[:recency]]
        }
      ]
    )

    move_down 20

    formatted_text(
      [
        {
          text: "Possible multivariant Infection: ",
          styles: [:bold],
          size: 16,
        },

        {
          text: log[:possible_dual_infection],
          styles: [:bold],
          size: 16,
          color: dual_infection_color[log[:possible_dual_infection]]
        }
      ]
    )

    move_down 10

    if log[:possible_dual_infection] == "Yes"

      formatted_text(
        [
          {
            text: "Warning: Days Post Infection prediction not reliable!",
            styles: [:bold],
            size: 14,
            color: "ffcc00"
          }
        ]
      )
    end
  end

end