@@ -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# '
0 commit comments