Created
April 9, 2013 00:36
-
-
Save cknoxrun/5341917 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def concentration_value(c) | |
| unit = "" | |
| conc = c.conc_value | |
| mean = 0 | |
| error = 0 | |
| if (conc.nil?) | |
| return "" | |
| elsif(conc == "Detected") | |
| mean = -1 | |
| elsif(conc == "not detected" || conc == "NA" || conc == "Not Detected") | |
| return "" | |
| else | |
| conc = conc.strip | |
| end | |
| if (conc =~/^([\+\-\d\.Ee]+)$/) | |
| mean = $1.to_f | |
| error = 0 | |
| elsif (conc =~/^<?([\d\.]+)\s*\-\s*([\d\.]+)$/) | |
| mean = ($1.to_f + $2.to_f)/2 | |
| error = ($2.to_f - $1.to_f)/2 | |
| elsif (conc =~/^([\d\.]+)\s*\+\/\-\s*([\d\.]+)\s*/) | |
| mean = $1.to_f | |
| error = $2.to_f | |
| elsif (conc =~/^\>=?\s*([\d\.]+)$/) | |
| mean = $1.to_f | |
| error = 0 | |
| elsif (conc =~/^\<=?\s*([\d\.]+)$/) | |
| mean = $1.to_f/2 | |
| error = $1.to_f/2 | |
| elsif (conc =~/^([\+\-\d\.Ee]+)\s+\+\/\-\s*([\+\-\d\.Ee]+)$/) | |
| mean = $1.to_f | |
| error = $2.to_f | |
| elsif (conc =~/^([\d\.]+)\s*\(\s*([\d\.]+)\s*[^\s\d\.\+]\s*([\d\.]+)\s*\)$/) | |
| mean = $1.to_f | |
| error = ($3.to_f - $2.to_f)/2 | |
| else | |
| # puts "cannot parse concentration: '#{conc}' id: #{c.id}" | |
| # | |
| end | |
| if (c.biofluid_source == "Blood") | |
| if (c.conc_unit == "uM") | |
| else | |
| # puts "ERROR: unusually unit for blood concentration: #{c.conc_unit} id: #{c.id}" | |
| # | |
| end | |
| # puts "#{record.hmdb_id}\t#{c.patient_status}\t#{c.conc_condition}\t#{c.biofluid_source}\t#{mean}\t#{error}\t#{c.age}\t#{c.sex}\t#{c.id}" | |
| elsif (c.biofluid_source == "Urine") | |
| if (c.conc_unit == "uM") | |
| # assume this is right (i.e. = umol/mmol_creatinine) | |
| elsif (c.conc_unit == "umol/mmol_creatinine" || c.conc_unit == "umol/mmol creatinine") | |
| elsif (c.conc_unit == "nmol/mmol_creatinine" || c.conc_unit == "nmol/mmol creatinine") | |
| mean = mean * 1000 | |
| error = error * 1000 | |
| else | |
| # puts "ERROR: unusually unit for urine concentration: #{c.conc_unit} id: #{c.id}" | |
| # | |
| end | |
| # puts "#{record.hmdb_id}\t#{c.patient_status}\t#{c.conc_condition}\t#{c.biofluid_source}\t#{mean}\t#{error}\t#{c.age}\t#{c.sex}\t#{c.id}" | |
| else | |
| # | |
| end | |
| return "data-value=#{mean} data-error=#{error} data-type=#{c.biofluid_source}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment