Skip to content

Commit

Permalink
docs(vignette): Integrate MSstats workflow into vignette and test data
Browse files Browse the repository at this point in the history
  • Loading branch information
tonywu1999 committed Aug 27, 2024
1 parent 8c5e873 commit a09b9bd
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 23 deletions.
2 changes: 1 addition & 1 deletion R/getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#'
#' @examples
#' input <- data.table::fread(system.file(
#' "processed_data/groupComparisonModel.csv",
#' "extdata/groupComparisonModel.csv",
#' package = "MSstatsBioNet"
#' ))
#' # subnetwork = getSubnetworkFromIndra(input, pvalue_cutoff = 0.05)
Expand Down
2 changes: 1 addition & 1 deletion R/visualizeNetworks.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#'
#' @examples
#' input <- data.table::fread(system.file(
#' "processed_data/groupComparisonModel.csv",
#' "extdata/groupComparisonModel.csv",
#' package = "MSstatsBioNet"
#' ))
#' # subnetwork = getSubnetworkFromIndra(input)
Expand Down
8 changes: 8 additions & 0 deletions inst/extdata/groupComparisonModel.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"Protein","Label","log2FC","SE","Tvalue","DF","pvalue","adj.pvalue","issue","MissingPercentage","ImputationPercentage","HgncId"
"B9A064","neg vs pos",0.289168813227902,0.0290298430266267,9.96108773177556,2,0.00992843836713075,0.0694990685699153,NA,0,0,"38476"
"O00391","neg vs pos",0.61514367352039,0.607915303579319,1.01189042272585,1,0.496237573382871,0.496237573382871,NA,0.25,0,"9756"
"O14818","neg vs pos",-0.351724166825181,0.180293183487185,-1.95084561724532,2,0.190360070677825,0.333130123686193,NA,0.208333333333333,0.208333333333333,"9536"
"O43598","neg vs pos",0.444322024324174,0.222001037180599,2.00144120931613,2,0.18330743657428,0.333130123686193,NA,0.1875,0.1875,"21218"
"O43707","neg vs pos",-0.678628567390453,0.196242424527707,-3.45811344832135,2,0.0744090385980984,0.260431635093345,NA,0.140625,0.140625,"166"
"P16050","neg vs pos",0.239036560821488,0.213802694760769,1.11802407864388,2,0.379829709925256,0.443134661579466,NA,0.134615384615385,0.134615384615385,"11390"
"P84243","neg vs pos",-1.03311234546861,0.833093604461367,-1.24009155746258,2,0.3406963949584,0.443134661579466,NA,0.125,0.125,"4765"
Binary file added inst/extdata/indraResponse.rds
Binary file not shown.
File renamed without changes.
5 changes: 0 additions & 5 deletions inst/processed_data/groupComparisonModel.csv

This file was deleted.

Binary file removed inst/processed_data/indraResponse.rds
Binary file not shown.
31 changes: 31 additions & 0 deletions inst/script/groupComparisonModel.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Script to create groupComparisonModel.csv in extdata folder
library(MSstatsConvert)
input = system.file("tinytest/raw_data/Metamorpheus/AllQuantifiedPeaks.tsv",
package = "MSstatsConvert")
input = data.table::fread(input)
annot = system.file("tinytest/raw_data/Metamorpheus/Annotation.tsv",
package = "MSstatsConvert")
annot = data.table::fread(annot)
msstats_imported = MetamorpheusToMSstatsFormat(input, annotation = annot)
head(msstats_imported)

library(MSstats)
QuantData = dataProcess(msstats_imported, use_log_file = FALSE)
groupComparisonResult = groupComparison(contrast.matrix="pairwise",
data=QuantData,
use_log_file = FALSE)

uniprot_to_hgnc_mapping = c(
"B9A064" = "38476",
"O00391" = "9756",
"O14818" = "9536",
"O43598" = "21218",
"O43707" = "166",
"P16050" = "11390",
"P84243" = "4765"
)
groupComparisonResult$ComparisonResult$HgncId = uniprot_to_hgnc_mapping[
groupComparisonResult$ComparisonResult$Protein
]

write.csv(groupComparisonResult$ComparisonResult, "groupComparison.csv", row.names = FALSE)
2 changes: 1 addition & 1 deletion man/getSubnetworkFromIndra.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/visualizeNetworks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions tests/testthat/test-getSubnetworkFromIndra.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
test_that("getSubnetworkFromIndra works correctly", {
input <- data.table::fread(
system.file("processed_data/groupComparisonModel.csv", package = "MSstatsBioNet")
system.file("extdata/groupComparisonModel.csv", package = "MSstatsBioNet")
)
local_mocked_bindings(.callIndraCogexApi = function(x) {
return(readRDS(system.file("processed_data/indraResponse.rds", package = "MSstatsBioNet")))
return(readRDS(system.file("extdata/indraResponse.rds", package = "MSstatsBioNet")))
})
subnetwork <- getSubnetworkFromIndra(input)
expect_equal(nrow(subnetwork$nodes), 4)
expect_equal(nrow(subnetwork$edges), 16)
expect_equal(nrow(subnetwork$nodes), 7)
expect_equal(nrow(subnetwork$edges), 2)
})

test_that("getSubnetworkFromIndra with pvalue filter works correctly", {
input <- data.table::fread(
system.file("processed_data/groupComparisonModel.csv", package = "MSstatsBioNet")
system.file("extdata/groupComparisonModel.csv", package = "MSstatsBioNet")
)
local_mocked_bindings(.callIndraCogexApi = function(x) {
return(readRDS(system.file("processed_data/indraResponse.rds", package = "MSstatsBioNet")))
return(readRDS(system.file("extdata/indraResponse.rds", package = "MSstatsBioNet")))
})
subnetwork <- getSubnetworkFromIndra(input, pvalue_cutoff = 0.05)
expect_equal(nrow(subnetwork$nodes), 3)
expect_equal(nrow(subnetwork$edges), 16)
subnetwork <- getSubnetworkFromIndra(input, pvalue_cutoff = 0.45)
expect_equal(nrow(subnetwork$nodes), 6)
expect_equal(nrow(subnetwork$edges), 2)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-visualizeNetworks.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
test_that("visualizeNetworks works correctly", {
input <- readRDS(system.file("processed_data/subnetwork.rds",
input <- readRDS(system.file("extdata/subnetwork.rds",
package = "MSstatsBioNet"
))

Expand Down Expand Up @@ -33,7 +33,7 @@ test_that("visualizeNetworks works correctly", {


test_that("visualizeNetworks with p-value and logFC constraints works", {
input <- readRDS(system.file("processed_data/subnetwork.rds",
input <- readRDS(system.file("extdata/subnetwork.rds",
package = "MSstatsBioNet"
))

Expand Down
10 changes: 7 additions & 3 deletions vignettes/MSstatsBioNet.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ input = data.table::fread(input)
annot = system.file("tinytest/raw_data/Metamorpheus/Annotation.tsv",
package = "MSstatsConvert")
annot = data.table::fread(annot)
msstats_imported = MetamorpheusToMSstatsFormat(input, annotation = annot)
msstats_imported = MetamorpheusToMSstatsFormat(input, annotation = annot,
use_log_file = FALSE)
head(msstats_imported)
```

# MSstats Process and GroupComparison

```{r}
library(MSstatsConvert)
library(MSstats)
QuantData = dataProcess(msstats_imported, use_log_file = FALSE)
groupComparisonResult = groupComparison(contrast.matrix="pairwise",
data=QuantData,
Expand All @@ -60,6 +61,9 @@ containing HGNC IDs. We can use the following mapping to convert from Uniprot
to HGNC ID. This mapping was obtained from this
[Python uniprot client](https://indra.readthedocs.io/en/docstrings/modules/databases/index.html#indra.databases.hgnc_client.get_hgnc_id)

In the future, this uniprot client will be added as a separate function to allow
users to perform this conversion in R in a streamlined way.

```{r}
uniprot_to_hgnc_mapping = c(
"B9A064" = "38476",
Expand Down Expand Up @@ -91,7 +95,7 @@ This package is distributed under the [Artistic-2.0](https://opensource.org/lice

## Visualize Networks

```{r proteinNetworkDiscovery, eval=FALSE}
```{r visualizeNetwork, eval=FALSE}
visualizeNetworks(subnetwork$nodes, subnetwork$edges)
```

Expand Down

0 comments on commit a09b9bd

Please sign in to comment.