1

I am currently using R to assign mutation significance values to proteins in yeast.

I have a data frame that looks like this:

             Genes q_values
1             HNT1 4.836462e-01
2            EMP47 6.792469e-01
3             QDR2 6.357284e-01
4             TMS1 9.781394e-01
5             TMS1 8.672664e-01
...

However, on occasion there will be a q_value significantly lower than the others:

...
35            HHF1 5.565396e-01
36            RGA2 2.323061e-12
37           CDC24 8.174687e-01
...

# Notice how value for row 36 is very low

I want to rescale these q_values onto a 1-10000 scale. However, I need the highest original q_value (i.e. ~9.85e-01) to be the lowest on the new scale (e.i. a value of 1). Inversely, the lowest original q_value (i.e. ~1.36e-13) needs to be the highest on the new scale (e.i. a value of 10000).

I have tried making a variation of the equation proposed here: https://stats.stackexchange.com/questions/25894/changing-the-scale-of-a-variable-to-0-100. However I did not manage to get the results I am looking far.

What would be the best way to go about doing this?

Biochem
  • 311
  • 1
  • 4
  • 13
  • Please show the code you tried. Also, it's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Sample data with "..." lines isn't helpful because we can't copy/paste that into R for testing. – MrFlick Sep 13 '20 at 21:22

1 Answers1

1

Maybe you can try the code below for rescaling the q values

within(df, rescaled_q_values <- 1e5*(max(new_q_values)-new_q_values)/diff(range(new_q_values)))

which gives

   new_yeast_genes new_q_values rescaled_q_values
1             HNT1 4.836462e-01          50554.47
2            EMP47 6.792469e-01          30557.25
3             QDR2 6.357284e-01          35006.36
4             TMS1 9.781394e-01              0.00
5             TMS1 8.672664e-01          11335.09
35            HHF1 5.565396e-01          43102.22
36            RGA2 2.323061e-12         100000.00
37           CDC24 8.174687e-01          16426.16

Data

df <- structure(list(new_yeast_genes = c("HNT1", "EMP47", "QDR2", "TMS1",
"TMS1", "HHF1", "RGA2", "CDC24"), new_q_values = c(0.4836462, 
0.6792469, 0.6357284, 0.9781394, 0.8672664, 0.5565396, 2.323061e-12,
0.8174687)), class = "data.frame", row.names = c("1", "2", "3",
"4", "5", "35", "36", "37"))
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81