Module: ViralSeq::Recency
- Defined in:
- lib/viral_seq/recency.rb
Overview
recency prediction function based on HIV MPID-NGS
Class Method Summary collapse
-
.define(tcs_RT: nil, tcs_V1V3: nil, pi_RT: nil, dist20_RT: nil, pi_V1V3: nil, dist20_V1V3: nil) ⇒ String
Determination of the recency.
-
.dpi(pi_rt, pi_v1v3) ⇒ Array
function for predict Days Post Infection.
-
.possible_dual_infection(recency, dpi) ⇒ String
given ‘recency` and `dpi` predict if possible dual infection exists.
Class Method Details
.define(tcs_RT: nil, tcs_V1V3: nil, pi_RT: nil, dist20_RT: nil, pi_V1V3: nil, dist20_V1V3: nil) ⇒ String
Returns determination of the recency.
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 |
# File 'lib/viral_seq/recency.rb', line 16 def self.define(tcs_RT: nil, tcs_V1V3: nil, pi_RT: nil, dist20_RT: nil, pi_V1V3: nil, dist20_V1V3: nil) tcs_RT ||= 0 tcs_V1V3 ||= 0 if (tcs_RT >= 3 && pi_RT) and (tcs_V1V3 >= 3 && pi_V1V3) if (pi_RT + pi_V1V3) < 0.0103 recency = "recent" elsif (pi_RT + pi_V1V3) >= 0.0103 and (dist20_RT + dist20_V1V3) >= 0.006 recency = "chronic" else recency = "indeterminant" end elsif (tcs_RT >= 3 && pi_RT) and tcs_V1V3 < 3 if pi_RT < 0.0021 recency = "recent" elsif pi_RT >= 0.0021 and dist20_RT >= 0.001 recency = "chronic" else recency = "indeterminant" end elsif (tcs_V1V3 >= 3 && pi_V1V3) if pi_V1V3 >= 0.0103 and dist20_V1V3 >= 0.006 recency = "chronic" else recency = "insufficient data" end else recency = "insufficient data" end return recency end |
.dpi(pi_rt, pi_v1v3) ⇒ Array
function for predict Days Post Infection
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 |
# File 'lib/viral_seq/recency.rb', line 56 def self.dpi(pi_rt, pi_v1v3) if pi_rt.is_a? Numeric and pi_v1v3.is_a? Numeric pi = pi_rt*100 + pi_v1v3*100 model_file = "rt_v1v3_fit.Rdata" var = "combined_perc" elsif pi_rt.is_a? Numeric pi = pi_rt*100 model_file = "rt_only_fit.Rdata" var = "rtperc" elsif pi_v1v3.is_a? Numeric pi = pi_v1v3*100 model_file = "v1v3_only_fit.Rdata" var = "v1v3perc" else return ["NA", "NA", "NA"] end path = File.join( ViralSeq.root, "viral_seq", "util", "recency_model", model_file) data_str = `Rscript -e 'fit = readRDS("#{path}"); test = data.frame(#{var} = #{pi}); pre= predict(fit, test, interval = "prediction", level = 0.9); cat(pre)'` dpi_array = data_str.split("\s") dpi = dpi_array[0].to_f.round(1) lwr = dpi_array[1].to_f.round(1) upr = dpi_array[2].to_f.round(1) if lwr < 0 return [dpi, 0.0, upr] else return [dpi, lwr, upr] end end |
.possible_dual_infection(recency, dpi) ⇒ String
given ‘recency` and `dpi` predict if possible dual infection exists
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/viral_seq/recency.rb', line 91 def self.possible_dual_infection(recency, dpi) if ["recent", "chronic", "indeterminant"].include? recency and dpi[0].is_a? Numeric if recency == "indeterminant" and dpi[0] > 730 "Yes" else "No" end else "insufficient data" end end |