Skip to content
Merged
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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
S3method(print,topicHierarchy)
export(INDRA_DATABASE_SOURCES)
export(INDRA_TEXT_MINED_SOURCES)
export(add_entity_values)
export(annotateProteinInfoFromIndra)
export(backend_capabilities)
export(bootstrapTopicModels)
Expand All @@ -16,6 +17,7 @@ export(deleteEdgeFromNetwork)
export(exportNetworkToHTML)
export(filterSubnetworkByContext)
export(filter_by_curation)
export(filter_by_ptm_site)
export(getSubnetworkFromIndra)
export(get_curations)
export(get_entity_properties)
Expand Down
38 changes: 36 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ metabolites:
* `prepare_entities()` builds an entity table with one row per analyte,
its entity type (`"protein"`, `"ptm_site"`, `"metabolite"`, ...),
identifier system, organism, and statistics. It copies `log2FC`,
`log10FC`, or `logFC` to `logFC`, parses PTM sites, and stops when the
`log10FC`, or `logFC` to `logFC`, parses PTM sites (with the parent
protein from `GlobalProtein`, except where MSstatsPTM wrote
`"missing"`), and stops when the
input has several comparisons in `Label` unless `label` names one.
* `indra_backend()` creates the INDRA backend, and
`backend_capabilities()` lists what a backend supports.
* `convert_ids()` grounds the entity table (CoGEx for UniProt IDs and
mnemonics, Gilda for gene symbols and chemical names), and
`get_entity_properties()` adds `is_transcription_factor`, `is_kinase`,
and `is_phosphatase`.
and `is_phosphatase`. UniProt IDs may be FASTA headers, as FragPipe
writes them (`sp|P32004|L1CAM_HUMAN`, or `sp|P32004|L1CAM_HUMAN_S1194`
for a site): `id` keeps the header and the accession is converted.
* `select_entities()` flags the rows that pass the cutoffs, and drops
none, so that nodes in the input are recognized even when they fail
the cutoffs.
Expand Down Expand Up @@ -72,6 +76,23 @@ metabolites:
`getSubnetworkFromIndra(sources_filter =)`, gives a warning that
suggests the internal name where there is one (e.g. `"psp"` for
`"phosphosite"`).
* `filter_by_ptm_site(network)` keeps the edges whose `site` is a PTM
site of their target in the network, checking each edge on its own,
and drops the nodes left without edges; it stops when no edges remain.
Unlike `getSubnetworkFromIndra(filter_by_ptm_site = TRUE)`, which is
unchanged, it doesn't keep an edge for an unmeasured site because
another statement between the same two nodes hits a measured one,
splits node sites of protein groups on `;`, and keeps isolated nodes
and `provenance`.
* `add_entity_values(network, entities, overwrite = FALSE)` copies the
`logFC` and `adj.pvalue` of a grounded entity table onto the matching
nodes of a network, without a query: for example, global profiling
results (MSstatsPTM's `PROTEIN.Model`) onto a network built from PTM
results. Nodes match by `id` and `site`, then by grounding, so a node
named by the backend (e.g. a kinase added with `include_entities`)
matches too. A protein with only PTM site rows gets a protein-level
row, so its node is colored by the global result. Nodes that already
have values stop the call unless `overwrite = TRUE`.
* The S4 classes `NetworkBackend`, `IndraBackend`, `NetworkQuery`, and
`SubnetworkQuery` are exported, so other packages can add backends.
* New function `validate_network()` checks a `list(nodes, edges)` network
Expand All @@ -95,6 +116,11 @@ evidence comes from the backend named in its `backend_database` column, so a
network subset or rebuilt with `list(nodes =, edges =)` still works. Pass
`backend` to use one built with non-default settings, such as
`indra_backend(cogex_url = )`.
* The PTM-Analysis vignette is rewritten for the new API, with a CPTAC
clear cell renal cell carcinoma dataset that has both a phosphoproteomics
and a global profiling experiment (`extdata/cptac-ccrcc-ptm-adjusted.csv`,
`extdata/cptac-ccrcc-protein.csv`). `extdata/garrido-2024.csv`, used only
by the old vignette, is removed.

## Breaking changes

Expand Down Expand Up @@ -177,6 +203,14 @@ pass the cutoffs, since only those are sent to INDRA.
`entity_name`, `namespace`, `entity_id`, `measured`, `included_in_query`,
and `node_role`.

## Bug fixes

* `annotateProteinInfoFromIndra()` grounds PTM sites whose `GlobalProtein`
is `"missing"`, MSstatsPTM's value in `ADJUSTED.Model` for sites whose
protein has no global profiling result. They were left ungrounded, and so
were missing from the network of `getSubnetworkFromIndra()`. Their
`GlobalProtein` is now the protein without its site.

## Deprecated

* `cytoscapeNetwork(displayLabelType = "entityName")` (and the same argument
Expand Down
29 changes: 26 additions & 3 deletions R/annotateProteinInfoFromIndra.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ annotateProteinInfoFromIndra <- function(df, proteinIdType) {
x))
}

#' Strip the PTM site suffix from each member of protein groups
#'
#' Splits each identifier into its \code{;}-separated members, strips each
#' member with \code{.stripPtmSite()}, and joins the unique parents, so
#' that \code{"P13747_S148;P23132_T20"} gives \code{"P13747;P23132"}.
#'
#' @param x A character vector of identifiers.
#' @return The character vector with site suffixes removed.
#' @keywords internal
#' @noRd
.stripPtmSiteFromGroups <- function(x) {
return(vapply(as.character(x), function(protein) {
members <- .splitProteinGroup(protein)
.joinProteinGroup(unique(.stripPtmSite(members)))
}, character(1), USE.NAMES = FALSE))
}

#' Populate Uniprot IDs in Data Frame
#'
#'
Expand All @@ -102,11 +119,17 @@ annotateProteinInfoFromIndra <- function(df, proteinIdType) {
.populateUniprotIdsInDataFrame <- function(df, proteinIdType) {
if (!("GlobalProtein" %in% colnames(df))) {
df$Protein = as.character(df$Protein)
df$GlobalProtein = vapply(df$Protein, function(protein) {
.stripPtmSite(protein)
}, character(1), USE.NAMES = FALSE)
df$GlobalProtein = .stripPtmSiteFromGroups(df$Protein)
}
df$GlobalProtein = as.character(df$GlobalProtein)
# MSstatsPTM writes "missing" for sites whose protein has no global
# profiling result
no_global <- is.na(df$GlobalProtein) | !nzchar(df$GlobalProtein) |
df$GlobalProtein == "missing"
if (any(no_global)) {
df$GlobalProtein[no_global] <- .stripPtmSiteFromGroups(
as.character(df$Protein[no_global]))
}
groupMembers <- lapply(df$GlobalProtein, .splitProteinGroup)
protein_ids = unique(unlist(groupMembers, use.names = FALSE))
df$UniprotId <- NA
Expand Down
10 changes: 9 additions & 1 deletion R/backend-indra.R
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,10 @@ setMethod("get_entity_properties", "IndraBackend",
}

#' The identifiers to ground for each entity row
#'
#' Members in UniProt FASTA header form (\code{sp|P32004|L1CAM_HUMAN}) are
#' reduced to the accession, or to the mnemonic for
#' \code{id_type = "uniprot_mnemonic"}.
#' @param entities entity table
#' @return list with one character vector per row: the members of
#' \code{id}, or of \code{parent_id} for \code{ptm_site} rows
Expand All @@ -878,7 +882,11 @@ setMethod("get_entity_properties", "IndraBackend",
!is.na(entities$parent_id)
inputs[use_parent] <- entities$parent_id[use_parent]
}
lapply(inputs, .splitProteinGroup)
members <- lapply(inputs, .splitProteinGroup)
is_uniprot <- entities$id_type %in% c("uniprot", "uniprot_mnemonic")
members[is_uniprot] <- Map(.parse_uniprot_headers, members[is_uniprot],
entities$id_type[is_uniprot])
members
}

#' Map UniProt mnemonics to UniProt IDs through CoGEx
Expand Down
39 changes: 36 additions & 3 deletions R/entities.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ LOGFC_COLUMNS <- c("log2FC", "log10FC", "logFC")
#' @noRd
MSSTATS_PTM_SITE_PATTERN <- "^(.*?)((?:_[A-Z][0-9]+)+)$"

#' Pattern for UniProt FASTA headers, as FragPipe writes protein IDs
#'
#' Matches e.g. \code{sp|P32004|L1CAM_HUMAN}: the database (\code{sp} or
#' \code{tr}), then the accession (first capture group) and the mnemonic
#' (second).
#' @keywords internal
#' @noRd
UNIPROT_HEADER_PATTERN <- "^(?:sp|tr)\\|([^|]+)\\|([^|]+)$"

#' Reduce UniProt FASTA headers to an accession or mnemonic
#' @param ids character vector; values not in header form are returned
#' unchanged
#' @param id_type \code{"uniprot"} for the accession,
#' \code{"uniprot_mnemonic"} for the mnemonic
#' @return character vector
#' @keywords internal
#' @noRd
.parse_uniprot_headers <- function(ids, id_type) {
part <- if (id_type == "uniprot_mnemonic") "\\2" else "\\1"
is_header <- grepl(UNIPROT_HEADER_PATTERN, ids, perl = TRUE)
ids[is_header] <- sub(UNIPROT_HEADER_PATTERN, part, ids[is_header],
perl = TRUE)
ids
}

#' Required entity columns and their types
#' @keywords internal
#' @noRd
Expand All @@ -53,7 +78,8 @@ REQUIRED_ENTITY_COLUMNS <- c(
#' from the end of each identifier, e.g. \code{"P00533_S1039_S1042"} gives
#' parent \code{"P00533"} and site \code{"S1039_S1042"}. A
#' \code{GlobalProtein} column, as MSstatsPTM writes, overrides the parsed
#' parent.
#' parent, except where it is \code{"missing"} (MSstatsPTM's value for
#' sites whose protein has no global profiling result).
#'
#' @param df output of \code{groupComparison()}'s \code{ComparisonResult}
#' table, or any table with one row per analyte.
Expand All @@ -70,7 +96,11 @@ REQUIRED_ENTITY_COLUMNS <- c(
#' \code{"chebi"}, \code{"chembl"}), or the name of a column of \code{df}
#' holding one per row. Which of them a backend can convert is listed by
#' \code{backend_capabilities(backend)$id_conversions}. For PTM sites, the identifier system of the parent
#' protein. \code{"chemical_name"} is a metabolite, lipid, or drug name,
#' protein. \code{"uniprot"} and \code{"uniprot_mnemonic"} identifiers may
#' also be UniProt FASTA headers, as FragPipe writes them
#' (\code{"sp|P32004|L1CAM_HUMAN"}, or \code{"sp|P32004|L1CAM_HUMAN_S1194"}
#' for a site): \code{id} keeps the header, and \code{\link{convert_ids}()}
#' uses its accession or mnemonic. \code{"chemical_name"} is a metabolite, lipid, or drug name,
#' common or IUPAC (e.g. \code{"glucose"}), grounded by text matching.
#' @param organism NCBI taxon ID, as a string.
#' @param label the comparison to keep, when \code{df} has a \code{Label}
Expand Down Expand Up @@ -154,7 +184,10 @@ prepare_entities <- function(df, id_column = "Protein", entity_type, id_type,
entities$parent_id[is_ptm] <- sites$parent_id
if ("GlobalProtein" %in% colnames(df)) {
global <- as.character(df$GlobalProtein[is_ptm])
has_global <- !is.na(global) & nzchar(global)
# MSstatsPTM writes "missing" for sites whose protein has no
# global profiling result (Adjusted = FALSE)
has_global <- !is.na(global) & nzchar(global) &
global != "missing"
entities$parent_id[is_ptm][has_global] <- global[has_global]
}
no_site <- is.na(entities$site[is_ptm])
Expand Down
Loading
Loading