Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding PerseusR support to MedianVar #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions MedianVar/MedianVarPerseus.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#devtools::install_github("cox-labs/PerseusR")
library(PerseusR)
args = commandArgs(trailingOnly=TRUE)
if (length(args) != 2) {stop(paste("This script is for calculating the median of normalized variance from a Perseus matrix table.
How to run:
args[1] - Perseus matrix table of proteinGroup table
args[2] - Row number of the annotation for sample groups
args[3] - Row number of the annotation of Type which shows E, N, C and T
args[4] - Row number of the first row of intensity values
EX: Rscript MedianVar.R proteinGroup_Perseus.txt 4 1 5\n" ,sep="\n"), call.=FALSE)}
cat("Running now...\n")
inFile <- args[1]
outFile <- args[2]
#inFile<-"C:/Users/animeshs/GD/tools/MedianVar/proteinGroup_Perseus.txt"
mdata <- read.perseus(inFile)
Samples<-mdata@annotRows$Samples
celltypes <- as.character(unique(Samples))
Type<-mdata@annotRows$Experiments
Channel<-mdata@annotRows$Channels
Uniprot<-paste(mdata@annotCols$Protein.IDs)
counts<- main(mdata)
counts<-counts[complete.cases(counts), ]
#countz<-counts
colnames(counts)<-Samples
vars<-c()
a<-1
for (cell in celltypes){
counts2 <- counts[,grepl(cell, names(counts))]
nor_vars_c <- c()
l<-1
for(j in seq(1, nrow(counts2))) {
nor_vars_c[l] <- var(unlist(counts2[j,]), na.rm=TRUE)/var(unlist(counts[j,]), na.rm=TRUE)
l<-l+1
}
vars[a]<-median(nor_vars_c,na.rm = T)
a<-a+1
}
#countz2<-counts2
df <- data.frame(matrix(unlist(vars), nrow=length(vars), byrow=T))
colnames(df)<-c("median of normalized variances")
#print(df)
outMdata <- matrixData(main=df,annotCols=as.data.frame(matrix(unlist(celltypes), nrow=length(vars), byrow=T)))
#outFile<-"C:/Users/animeshs/GD/tools/MedianVar/proteinGroup_Perseus.txt.out.txt"
write.perseus(outMdata,annotCols=celltypes, outFile)
cat("Done...\n")
Binary file added MedianVar/session1.sps
Binary file not shown.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# tools

## MedianVar.R
This script is for calculating the median of normalized variance from a Perseus matrix table.

Expand All @@ -8,3 +9,24 @@ args[2] - Row number of the annotation for sample groups<br/>
args[3] - Row number of the annotation of Type which shows E, N, C and T<br/>
args[4] - Row number of the first row of intensity values<br/>
EX: Rscript MedianVar.R proteinGroup_Perseus.txt 4 1 5<br/>

## MedianVarPerseus.R
This script is for calculating same the above using [External:Matrix=>R](https://github.com/cox-labs/PluginInterop) [PerseusR](https://github.com/cox-labs/PerseusR) to call directly from [Perseus](https://maxquant.net/download_asset/perseus/1.6.15.0) after installing R:
```
devtools::install_github("cox-labs/PerseusR")
```

Test:

```
File Generic-matrix-upload proteinGroup_Perseus.txt into Perseus
Invoke External:Matrix=>R and provide script&R location like following respectively:
script: <full-path-to>MedianVarPerseus.R
R: <full-path-to>Rscript.exe
```
As shown in session1.sps.

PS: on windows if "Error in utils::download.file(url, path, method = method, quiet = quiet, :cannot open URL 'https://api.github.com/repos/cox-labs/PerseusR/tarball/HEAD'" run "options(download.file.method = "wininet")" before installing:

## aovPerseusR\proteinGroupsANOVA.r
R script callable via https://github.com/cox-labs/PerseusR as above that can reproduce the ANOVA p&q-values(using Benjamini/Hochberg) from [Multiple-sample tests in Perseus](http://coxdocs.org/doku.php?id=perseus:user:activities:MatrixProcessing:Tests:MultipleSampleTestProcessing): It also provides the mean-difference with posthoc/TukeyHSD corrected p-values for each group comparison as shown in the attached Perseus session. Need to be mindful that NAs are being imputed as 0 so better to take care of NAs in Perseus beforehand! 
20 changes: 20 additions & 0 deletions aovPerseusR/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2021- @animesh .

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 changes: 41 additions & 0 deletions aovPerseusR/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## proteinGroupsANOVA.r
R script callable via https://github.com/cox-labs/PerseusR that can reproduce the ANOVA p&q-values(using Benjamini/Hochberg) from [Multiple-sample tests in Perseus](http://coxdocs.org/doku.php?id=perseus:user:activities:MatrixProcessing:Tests:MultipleSampleTestProcessing): It also provides the mean-difference with posthoc/TukeyHSD corrected p-values for each group comparison as shown in the attached Perseus session. Need to be mindful that NAs are being imputed as 0 so better to take care of NAs in Perseus beforehand! 

## pre-requisites
[R](https://cloud.r-project.org/), [devtools](https://www.r-project.org/nosvn/pandoc/devtools.html) and [PerseusR](https://github.com/cox-labs/PerseusR) , note on windows if
`"Error in utils::download.file(url, path, method = method, quiet = quiet, :cannot open URL 'https://api.github.com/repos/cox-labs/PerseusR/tarball/HEAD'"
`use
`options(download.file.method = "wininet")`
followed by install
`devtools::install_github("cox-labs/PerseusR")` within R session

## usage
Download [Perseus](https://maxquant.net/download_asset/perseus/latest) and invoke [External:Matrix=>R](https://github.com/cox-labs/PluginInterop) with following parameters:
script: <full path to>\proteinGroupsANOVA.r
R: <full path to>\Rscript.exe

## test
```
aovt<-anova(lm(c(-0.267558, -1.34843, -0.736034, -0.950788, -0.631172, -1.35648, -0.338978, 0.179467, -1.38368, -0.374963, -0.0118891, 0.583722, 0.646115, 2.28853, -0.117149)~c(rep("g1",5),rep("g2",5),rep("g3",5))))
summary.lm(aovt)
aovt<-aov(c(-0.267558, -1.34843, -0.736034, -0.950788, -0.631172, -1.35648, -0.338978, 0.179467, -1.38368, -0.374963, -0.0118891, 0.583722, 0.646115, 2.28853, -0.117149)~c(rep("g1",5),rep("g2",5),rep("g3",5))) #0.0134
summary(aovt)[[1]][["Pr(>F)"]][[1]]
postHoc<-TukeyHSD(aovt,ordered = TRUE)
names(postHoc)<-"compare"
postHoc<-data.frame(postHoc$compare)
diff<-t(postHoc["diff"])
plot(TukeyHSD(aovt))
padj<-sapply(postHoc["p.adj"],as.numeric)
-log10(padj)
p.adj
[1,] 0.019911
[2,] 1.720245
[3,] 1.495404
```

comparison to Perseus session session.sps file:
```
Group1 Group2 Group3 C: ANOVA Significant N: ANOVA p value N: ANOVA q-value T: Name T: Significant pairs
-1.72025 -1.49541 1.72025 0.0134469 0.644 Row 12 Group3_Group1;Group3_Group2
```
but note that first values/-1.72025 in Perseus is -(thirdvalue)/1.72025 though Group3 could very well be -Group2 i.e. log10(g3-g2) =>  -1.4954 which is log10(0.0319592) from R. Probably it was decided to base G3 from g3-g1 and not g3-g3 because of the fact that 0.0190439 < 0.0319592 ? Unfortunately, the [Source code: not public](http://coxdocs.org/doku.php?id=perseus:user:activities:MatrixProcessing:Tests:MultipleSampleTestProcessing), hope it soon is https://github.com/cox-labs @JurgenCox
Loading