Skip to content

Commit

Permalink
init read_FragPipe_LFQ and read_FragPipe_TMT
Browse files Browse the repository at this point in the history
  • Loading branch information
skelly001 committed Feb 27, 2024
1 parent b4a58a7 commit f54b2ad
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ Remotes:
github::cran/FField,
github::PNNL-Comp-Mass-Spec/MSnID@pnnl-master
VignetteBuilder: knitr
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export(readMaxQuantPeptides)
export(readMaxQuantProtGroups)
export(readMaxQuantSummary)
export(readSkyLinePRR)
export(read_FragPipe_LFQ)
export(read_FragPipe_TMT)
export(remove_batch_effect)
export(remove_covariate)
export(rf_modeling)
Expand Down Expand Up @@ -106,6 +108,7 @@ importFrom(ROCR,prediction)
importFrom(WGCNA,empiricalBayesLM)
importFrom(car,Anova)
importFrom(circlize,colorRamp2)
importFrom(data.table,fread)
importFrom(data.table,rbindlist)
importFrom(data.table,setDT)
importFrom(doParallel,registerDoParallel)
Expand All @@ -118,6 +121,7 @@ importFrom(dplyr,case_when)
importFrom(dplyr,desc)
importFrom(dplyr,distinct)
importFrom(dplyr,do)
importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
Expand Down Expand Up @@ -305,6 +309,7 @@ importFrom(stringr,str_locate_all)
importFrom(stringr,str_replace_all)
importFrom(stringr,str_sub)
importFrom(sva,ComBat)
importFrom(tibble,column_to_rownames)
importFrom(tibble,enframe)
importFrom(tibble,rownames_to_column)
importFrom(tidyr,fill)
Expand Down
71 changes: 71 additions & 0 deletions R/read_FragPipe_LFQ.R
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")
)

70 changes: 70 additions & 0 deletions R/read_FragPipe_TMT.R
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")
)

3 changes: 2 additions & 1 deletion man/complex_heatmap.Rd

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

25 changes: 25 additions & 0 deletions man/read_FragPipe_LFQ.Rd

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

26 changes: 26 additions & 0 deletions man/read_FragPipe_TMT.Rd

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

0 comments on commit f54b2ad

Please sign in to comment.