Skip to content

Commit 24ca285

Browse files
authored
Merge pull request #191 from warrenmcg/patch_g2g
Emergency patch to fix #190
2 parents 8bb7aa0 + 50b35d0 commit 24ca285

File tree

5 files changed

+88
-6
lines changed

5 files changed

+88
-6
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export(design_matrix)
3131
export(enclosed_brush)
3232
export(excluded_ids)
3333
export(extract_model)
34+
export(gene_from_gene)
3435
export(get_bootstrap_summary)
3536
export(get_bootstraps)
3637
export(get_quantile)

R/matrix.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
#' @param which_df character vector of length one. Which type of data to use
2525
#' ("obs_norm" or "obs_raw")
2626
#' @param which_units character vector of length one. Which units to use ("tpm"
27-
#' or "est_counts")
28-
#' @return a matrix which contains a matrix of target_ids and transcript expression in \code{which_units}
27+
#' or "est_counts" (for transcript-level analyses) or "scaled_reads_per_base" (for gene-level analyses))
28+
#' @return a matrix which contains a matrix of target_ids and transcript (or gene) expression in \code{which_units}.
29+
#' Note this currently does not support returning raw values for gene-level counts or TPMs.
2930
#' @examples
3031
#' sleuth_matrix <- sleuth_to_matrix(sleuth_obj, 'obs_norm', 'tpm')
3132
#' head(sleuth_matrix) # look at first 5 transcripts, sorted by name

R/sleuth.R

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,52 @@ transcripts_from_gene <- function(obj, test, test_type,
11501150
table$target_id[table[, 2] == gene_name]
11511151
}
11521152

1153+
#' Get the gene ID using other gene identifiers
1154+
#'
1155+
#' Get the \code{target_id} of a gene using other gene identifiers.
1156+
#' The identifiers found under the \code{obj$gene_column} are often
1157+
#' difficult to remember (e.g. ensembl gene ID, ENSG00000111640).
1158+
#' This function allows a user to find that difficult-to-remember
1159+
#' identifier using more-easily-remembered identifiers, such as
1160+
#' gene symbol (e.g. "GAPDH").
1161+
#'
1162+
#' @param obj a \code{sleuth} object
1163+
#' @param gene_colname the name of the column containing 'gene_name'.
1164+
#' This parameter refers to the name of the column that the gene you are searching for appears in.
1165+
#' Check the column names using \code{colnames(obj$target_mapping)}.
1166+
#' @param gene_name a string containing the name of the gene you are interested in.
1167+
#' @return a character vector containing the \code{target_id} of the gene, found under
1168+
#' \code{obj$gene_column} within \code{obj$target_mapping}.
1169+
#' If the column name provided is the same as \code{obj$gene_column}, and the
1170+
#' gene_name used is found, that gene_name will be returned.
1171+
#' @examples
1172+
#' \dontrun{gene_from_gene(obj, "gene_symbol", "GAPDH")}
1173+
#' @export
1174+
gene_from_gene <- function(obj, gene_colname, gene_name) {
1175+
1176+
if (!obj$gene_mode) {
1177+
stop("this sleuth object is in transcript mode. Please use 'transcripts_from_gene' instead.")
1178+
}
1179+
1180+
table <- as.data.frame(obj$target_mapping)
1181+
if (gene_colname == obj$gene_column) {
1182+
if (!(gene_name %in% table[, eval(parse(text = obj$gene_column))])) {
1183+
stop("Couldn't find gene ", gene_name)
1184+
} else {
1185+
return(gene_name)
1186+
}
1187+
}
1188+
1189+
table <- unique(dplyr::select_(table, obj$gene_column, gene_colname))
1190+
if (!(gene_name %in% table[, 2])) {
1191+
stop("Couldn't find gene ", gene_name)
1192+
}
1193+
hits <- unique(table[table[,2] == gene_name, 1])
1194+
if (length(hits) > 1) {
1195+
warning("there was more than one gene ID that matched this identifier; taking the first one")
1196+
}
1197+
hits[1]
1198+
}
11531199

11541200
#' Change sleuth transform counts function
11551201
#'

man/gene_from_gene.Rd

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/sleuth_to_matrix.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)