For this tutorial, we will change old gene IDs to gene names with
SeqoutGeneNames(). We then repair gene symbols that Excel
changed into dates with SeqoutCorrectNames(). The two
functions accept the result of SeqoutMatrix() or a numeric
matrix that has one gene in each row. They do not change the expression
values or the order of the rows. They keep the feature metadata aligned,
and record the original labels and the status of each change.
We install seqout and genevintage from CRAN:
The full-data commands download GEO files and annotation tables on
first use. The examples that run here use small excerpts that seqout
includes. The excerpts are unchanged from the original files and run
offline. The source URLs and the method of extraction are in
extdata/gene-names/README.md in the installed package.
We start with GSE52529,
the Monocle study of myoblast differentiation. It became public on 23
March 2014. Its single-cell file has 47,192 gene rows and 372 cells. The
rows have the original Ensembl IDs with versions, for example
ENSG00000000003.10.
The values are FPKM, not raw counts. We select
GSE52529_fpkm_matrix.txt.gz. The truseq file
has bulk measurements.
old <- SeqoutListCounts("GSE52529") |>
SeqoutMatrix(sample = "GSE52529_fpkm_matrix.txt.gz")
dim(old$X)
head(rownames(old$X))
# automatic selection; decision recorded below
automatic <- old |> SeqoutGeneNames()
automatic$gene_annotation[[1]]$annotationThe selection is a ranked estimate. These conditions can make it incorrect:
For this file, the function selects GENCODE 17 on GRCh37. This agrees with the GEO record of the sample. We do not give the release or the assembly. All 47,192 IDs in the file agree accurately with that reference, and their version suffixes also agree.
head(SeqoutGeneReport(automatic))
stopifnot(
identical(unname(old$X), unname(automatic$X)),
identical(rownames(automatic$X), rownames(automatic$var))
)The rank of the releases does not download an annotation. It uses the full vector of the original IDs, which seqout includes as a different file from the expression excerpt. If the rank uses only the genes in the excerpt, the result can be different.
id_file <- gzfile(SeqoutExample("gene-names/GSE52529-gene-ids.txt.gz"))
old_ids <- readLines(id_file)
close(id_file)
head(genevintage::detect_release(old_ids), 3)
#> species source release assembly feasible dist n_index
#> 1 homo_sapiens gencode 17 37 TRUE 0.2023 57232
#> 2 homo_sapiens gencode 18 37 TRUE 0.2078 57396
#> 3 homo_sapiens gencode 19 37 TRUE 0.2169 57773Here we change the IDs of the first 12 genes and the first three cells with the related excerpt of GENCODE 17:
old_excerpt <- as.matrix(read.delim(
SeqoutExample("gene-names/GSE52529-excerpt.tsv.gz"),
check.names = FALSE, row.names = 1
))
gencode17 <- read.delim(SeqoutExample("gene-names/gencode17-excerpt.tsv.gz"), check.names = FALSE)
old_named <- SeqoutGeneNames(old_excerpt, mapping = gencode17)
SeqoutGeneReport(old_named)[, c("input", "name", "status")]
#> input name status
#> 1 ENSG00000000003.10 TSPAN6 mapped
#> 2 ENSG00000000005.5 TNMD mapped
#> 3 ENSG00000000419.8 DPM1 mapped
#> 4 ENSG00000000457.8 SCYL3 mapped
#> 5 ENSG00000000460.12 C1orf112 mapped
#> 6 ENSG00000000938.8 FGR mapped
#> 7 ENSG00000000971.11 CFH mapped
#> 8 ENSG00000001036.8 FUCA2 mapped
#> 9 ENSG00000001084.6 GCLC mapped
#> 10 ENSG00000001167.10 NFYA mapped
#> 11 ENSG00000001460.13 STPG1 mapped
#> 12 ENSG00000001461.12 NIPAL3 mapped
stopifnot(identical(as.vector(old_excerpt), as.vector(old_named)))The function does not use the version suffixes to find a match, but
the record of changes keeps them. For example,
ENSG00000000003.10 becomes TSPAN6.
An ID with no name in the selected annotation does not change. If two
rows have the same symbol, each row gets a different label. The
name column of the record keeps the symbol without the
suffix. The function does not add rows together.
We next read GSE101942,
which has gene names that Excel changed. The original file
GSE101942_IPSC_rawCounts.txt.gz has 56,637 rows and six
samples. Five are summary rows from the count tool. The row labels
include 1-Mar, 9-Sep, and
15-Sep.
We give the name of the raw-count file to
SeqoutMatrix(). The study also has tables of differential
expression results, which are not count matrices.
damaged <- SeqoutListCounts("GSE101942") |>
SeqoutMatrix(sample = "GSE101942_IPSC_rawCounts.txt.gz")
# explicit target, not automatic
repaired <- damaged |> SeqoutCorrectNames(species = "human", release = 116)
report <- SeqoutGeneReport(repaired)
report[report$status != "unchanged", c("input", "name", "status")]
stopifnot(identical(unname(damaged$X), unname(repaired$X)))With Ensembl 116, the function repairs 25 labels. 15-Sep
stays unresolved, because this annotation has no candidate for it.
The excerpt in seqout has all the 26 damaged labels and
TP53 as a control that does not change. It has the six
original sample columns and their counts. The annotation excerpt has all
the candidates in the reference that relate to month names.
excel_excerpt <- as.matrix(read.delim(
SeqoutExample("gene-names/GSE101942-excerpt.tsv.gz"),
check.names = FALSE, row.names = 1
))
human116 <- read.delim(SeqoutExample("gene-names/ensembl116-excel.tsv.gz"), check.names = FALSE)
excel_fixed <- SeqoutCorrectNames(excel_excerpt, mapping = human116, quiet = TRUE)
excel_report <- SeqoutGeneReport(excel_fixed)
excel_report[
excel_report$input %in% c("1-Mar", "9-Sep", "15-Sep", "TP53"),
c("input", "name", "status")
]
#> input name status
#> 2 1-Mar MARCHF1 corrected
#> 13 15-Sep 15-Sep unresolved
#> 26 9-Sep SEPTIN9 corrected
#> 27 TP53 TP53 unchanged
table(excel_report$status)
#>
#> corrected unchanged unresolved
#> 25 1 1
stopifnot(identical(as.vector(excel_excerpt), as.vector(excel_fixed)))Human Ensembl 95 and Ensembl 116 give different results for the same damaged labels. Here we compare the two references. The comparison does not find the release that GSE101942 used.
human95 <- read.delim(SeqoutExample("gene-names/ensembl95-excel.tsv.gz"), check.names = FALSE)
excel_old <- SeqoutCorrectNames(excel_excerpt, mapping = human95, quiet = TRUE)
old_report <- SeqoutGeneReport(excel_old)
show <- excel_report$input %in% c("1-Mar", "9-Sep")
data.frame(
deposited = excel_report$input[show],
ensembl95 = old_report$name[show],
ensembl116 = excel_report$name[show]
)
#> deposited ensembl95 ensembl116
#> 1 1-Mar MARCH1 MARCHF1
#> 2 9-Sep SEPT9 SEPTIN91-Mar becomes MARCH1 with Ensembl 95 and
MARCHF1 with Ensembl 116. 9-Sep becomes
SEPT9 with Ensembl 95 and SEPTIN9 with Ensembl
116.
If the damaged symbols are in the feature metadata, you can give that
column with the ids argument:
The function keeps the original var$symbol column. The
repaired labels become the row names of X and of
var. Each call adds its record of changes to
gene_annotation. To keep this record after you change the
data to a Seurat or SingleCellExperiment object, save the corrected
seqout_matrix.