forked from vladpetyuk/vp.misc
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init read_FragPipe_LFQ and read_FragPipe_TMT
- Loading branch information
Showing
7 changed files
with
200 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#' Reading MSFragger-generated LFQ-based MSstats from a file path as MSnSet object | ||
#' | ||
#' @description Function has only been tested with label-free intensity-based | ||
#' quantification data. MSstats.csv is | ||
#' an optional output file which needs to be specified in FP settings. | ||
#' | ||
#' @param path character; File path to the FragPipe-generated MSstats.csv file | ||
#' | ||
#' @return (MSnSet) MSnSet object of MSFragger LFQ results | ||
#' | ||
#' @importFrom MSnbase MSnSet | ||
#' @importFrom data.table fread | ||
#' @importFrom tidyr pivot_wider | ||
#' @importFrom tibble column_to_rownames | ||
#' @importFrom dplyr %>% select filter distinct relocate everything mutate | ||
#' | ||
#' @examples | ||
#' file_path <- "C:/Users/fakeusr222/Desktop/MSF_LFQ_job/MSstats.csv" | ||
#' msnset <- read_FragPipe_LFQ(file_path) | ||
#' show(msnset) | ||
#' | ||
#' @export read_FragPipe_LFQ | ||
|
||
|
||
read_FragPipe_LFQ <- function(path = NULL) | ||
{ | ||
path_to_file <- path | ||
|
||
if (!file.exists(path_to_file)) { | ||
stop(sprintf("MSstats.csv file not found in folder: %s", dirname(path_to_file))) | ||
} | ||
|
||
df <- fread(file = path_to_file, showProgress = FALSE, data.table = FALSE) %>% | ||
filter(!is.na(Intensity)) %>% | ||
# May add charge col later | ||
select(ProteinName, PeptideSequence, Run, Intensity) %>% | ||
mutate(featureName = paste0(ProteinName, "@", PeptideSequence)) %>% | ||
relocate(featureName, .before = everything()) | ||
|
||
# Will sum intensity of unique features. | ||
x_data <- df %>% | ||
pivot_wider(id_cols = "featureName", | ||
names_from = "Run", | ||
values_from = "Intensity", | ||
values_fn = sum) %>% | ||
as.data.frame() %>% | ||
column_to_rownames(var = "featureName") %>% | ||
as.matrix() | ||
|
||
f_data <- df %>% | ||
distinct(featureName, ProteinName, PeptideSequence) %>% | ||
`rownames<-`(.[["featureName"]]) | ||
|
||
p_data <- df %>% | ||
distinct(Run) %>% | ||
`rownames<-`(.[["Run"]]) | ||
|
||
x_data <- x_data[rownames(f_data), rownames(p_data)] | ||
|
||
m <- MSnSet(exprs = x_data, fData = f_data, pData = p_data) | ||
|
||
return(m) | ||
} | ||
|
||
|
||
|
||
|
||
utils::globalVariables( | ||
c("ProteinName", "PeptideSequence", "Run", "Intensity", ".", "featureName") | ||
) | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#' Reading MSFragger-generated tmt-report files from a file path as MSnSet object | ||
#' | ||
#' @description Function has only been tested with TMT intensity-based | ||
#' quantification data. Desired tmt-report output files (e.g., "ratio_multi-site_MD.tsv") | ||
#' must be properly selected in the FP settings. | ||
#' | ||
#' @param path character; File path to the desired FragPipe-generated tmt-report file. | ||
#' Any tmt-report file may be used. | ||
#' | ||
#' @return (MSnSet) MSnSet object of MSFragger TMT results | ||
#' | ||
#' @importFrom MSnbase MSnSet | ||
#' @importFrom data.table fread | ||
#' @importFrom tibble column_to_rownames | ||
#' @importFrom dplyr %>% select mutate | ||
#' | ||
#' @examples | ||
#' file_path <- "C:/Users/fakeusr222/Desktop/MSF_TMT_job/ratio_multi-site_MD.tsv" | ||
#' msnset <- read_FragPipe_TMT(file_path) | ||
#' show(msnset) | ||
#' | ||
#' @export read_FragPipe_TMT | ||
|
||
read_FragPipe_TMT <- function(path = NULL) | ||
{ | ||
|
||
path_to_file <- path | ||
|
||
if (!file.exists(path_to_file)) { | ||
stop(sprintf("file not found in folder: %s", dirname(path_to_file))) | ||
} | ||
|
||
df <- fread(file = path_to_file, showProgress = FALSE, data.table = FALSE) | ||
|
||
|
||
# make featureNames | ||
if (grepl("multi-site|single-site|peptide", basename(path_to_file))) { | ||
df <- df %>% | ||
mutate(rowname = paste(Gene, ProteinID, Peptide, sep = "|")) | ||
} else if (grepl("gene", basename(path_to_file))) { | ||
df <- df %>% | ||
mutate(rowname = paste(Index, ProteinID, sep = "|")) | ||
} else if (grepl("protein", basename(path_to_file))) { | ||
df <- df %>% | ||
mutate(rowname = paste(Gene, Index, sep = "|")) | ||
} | ||
|
||
df <- df %>% | ||
mutate(featureName = rowname, .before = colnames(.)[[1]]) %>% | ||
column_to_rownames(var = "rowname") | ||
|
||
x_data <- df %>% | ||
select(-c(colnames(.)[[1]]:ReferenceIntensity)) %>% | ||
as.matrix() | ||
|
||
f_data <- df %>% | ||
select(c(colnames(.)[[1]]:ReferenceIntensity)) | ||
|
||
m <- MSnSet(exprs = x_data, fData = f_data) | ||
|
||
return(m) | ||
} | ||
|
||
|
||
|
||
|
||
utils::globalVariables( | ||
c(".", "featureName") | ||
) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.