Did the stuff on this morning’s TODO which came out of this morning’s meeting: do a PCA without the oddball strains (already done in the worksheet), highlight reference strains, and add L.major IDs and Descriptions (done by appending a collapsed version of the ortholog data to the all_lp_annot data).
Fixed human IDs for the macrophage data.
Changed input metadata sheets: primarily because I only remembered yesterday to finish the SL search for samples >TMRC20095. They are running now and will be added momentarily (I will have to redownload the sheet).
Setting up to make a hclust/phylogenetic tree of strains, use these are reference: 2168(2.3), 2272(2.2), for other 2.x choose arbitrarily (lower numbers are better).
Added another sanitize columns call for Antimony vs. antimony and None vs. none in the TMRC2 macrophage samples.
This document is intended to create the data structures used to evaluate our TMRC2 samples. In some cases, this includes only those samples starting in 2019; in other instances I am including our previous (2015-2016) samples.
In all cases the processing performed was:
I am thinking that this meeting will bring Maria Adelaida fully back into the analyses of the parasite data, and therefore may focus primarily on the goals rather than the analyses?
In a couple of important ways the TMRC2 data is much more complex than the TMRC3:
Our shared online sample sheet is nearly static at the time of this writing (202209), I expect at this point the only likely updates will be to annotate some strains as more or less susceptible to drug treatment.
sample_sheet <- "sample_sheets/ClinicalStrains_TMRC2.xlsx"
macrophage_sheet <- "sample_sheets/tmrc2_macrophage_samples.xlsx"The following block provides an example invocation of how I automatically extract things like percent reads mapped/trimmed/etc from the logs produced by trimomatic/cutadapt/hisat/salmon/etc. The caveat is that this container only has a small portion of the material available in the main working tree, as a result the new columns added to the sample sheet are relatively sparse compared to what I get on my computer.
In addition, because these samples have gone through ~ 3 different versions of my pipeline, and the code which extracts the numbers explicitly assumes only the most recent version (because it is the best!), it does not get out the data for all the samples.
## Checking the state of the condition column.
## Checking the state of the batch column.
## Checking the condition factor.
## preprocessing/TMRC20001/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20002/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20065/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20004/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20005/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20066/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20039/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20037/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20038/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20067/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20068/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20041/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20015/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20009/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20010/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20016/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20011/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20012/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20013/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20017/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20014/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20018/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20019/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20070/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20020/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20021/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20022/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20024/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20036/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20069/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20033/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20026/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20031/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20076/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20073/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20055/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20079/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20071/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20078/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20094/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20042/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20058/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20072/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20059/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20048/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20057/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20088/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20056/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20060/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20077/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20074/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20063/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20053/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20052/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20064/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20075/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20051/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20050/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20049/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20062/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20110/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20080/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20043/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20083/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20054/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20085/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20046/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20093/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20089/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20047/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20090/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20044/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20045/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20105/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20108/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20109/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20098/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20096/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20101/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20092/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20082/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20102/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20099/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20100/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20091/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20084/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20087/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20103/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20104/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20086/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20107/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20081/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## preprocessing/TMRC20095/outputs/*hisat*_lpanamensis_v36/lpanamensis_v36_*genome*_gene_ID_fcounts.csv.xz
## Writing new metadata to: sample_sheets/ClinicalStrains_TMRC2_modified.xlsx
Everything which follows depends on the Existing TriTrypDB annotations revision 46, circa 2019. The following block loads a database of these annotations and turns it into a matrix where the rows are genes and columns are all the annotation types provided by TriTrypDB.
The same database was used to create a matrix of orthologous genes between L.panamensis and all of the other species in the TriTrypDB.
The same database of annotations also provides mappings to the set of annotated GO categories for the L.panamensis genome along with gene lengths.
The following block assumes one has access to tritrypdb.org, which is no currently guaranteed. Thus I bundled a pre-generated copy of the genome, Txdb, and annotations.
## meta <- download_eupath_metadata(webservice = "tritrypdb", eu_version = "v46")
meta <- download_eupath_metadata(webservice = "tritrypdb")
panamensis_entry <- get_eupath_entry("MHOM", metadata = meta[["valid"]])
panamensis_db <- make_eupath_orgdb(panamensis_entry)
panamensis_pkg <- panamensis_db[["pkgname"]]
package_name <- panamensis_db[["pkgname"]]
if (is.null(panamensis_pkg)) {
panamensis_pkg <- panamensis_db[["orgdb_name"]]
package_name <- panamensis_pkg
}
tt <- library(panamensis_pkg, character.only = TRUE)
panamensis_pkg <- get0(panamensis_pkg)
all_fields <- columns(panamensis_pkg)
all_lp_annot <- sm(load_orgdb_annotations(panamensis_pkg, keytype = "gid"))
lp_go <- load_orgdb_go(package_name)
lp_go <- lp_go[, c("GID", "GO")]
lp_lengths <- all_lp_annot[, c("gid", "annot_cds_length")]
colnames(lp_lengths) <- c("ID", "length")
all_lp_annot[["annot_gene_product"]] <- tolower(all_lp_annot[["annot_gene_product"]])
orthos <- sm(extract_eupath_orthologs(db = panamensis_pkg))
data_structures <- c(data_structures, "lp_lengths", "lp_go", "all_lp_annot", "meta")all_installed <- rownames(installed.packages())
candidates <- grepl(pattern = "^org.Lpanamensis.MHOM.*v68.eg.db", x = all_installed)
orgdb_pkg_name <- all_installed[candidates]
tt <- library(orgdb_pkg_name, character.only = TRUE)## Loading required package: AnnotationDbi
## Loading required package: stats4
## Loading required package: Biobase
## Welcome to Bioconductor
##
## Vignettes contain introductory material; view with
## 'browseVignettes()'. To cite Bioconductor, see
## 'citation("Biobase")', and for packages 'citation("pkgname")'.
## Loading required package: IRanges
## Loading required package: S4Vectors
##
## Attaching package: 'S4Vectors'
## The following objects are masked from 'package:dplyr':
##
## first, rename
## The following object is masked from 'package:utils':
##
## findMatches
## The following objects are masked from 'package:base':
##
## I, expand.grid, unname
##
## Attaching package: 'IRanges'
## The following object is masked from 'package:glue':
##
## trim
## The following objects are masked from 'package:dplyr':
##
## collapse, desc, slice
##
## Attaching package: 'AnnotationDbi'
## The following object is masked from 'package:dplyr':
##
## select
##
panamensis_pkg <- get0(orgdb_pkg_name)
all_fields <- columns(panamensis_pkg)
all_lp_annot <- sm(load_orgdb_annotations(panamensis_pkg, keytype = "gid"))$genes
lp_go <- load_orgdb_go(panamensis_pkg)## The chosen keytype was not available. Using 'GID'.
## This is an orgdb, good.
## 'select()' returned 1:many mapping between keys and columns
## 'select()' returned 1:many mapping between keys and columns
## Error in `[.data.frame`(all_lp_annot, , c("gid", "annot_cds_length")): undefined columns selected
## Error: object 'lp_lengths' not found
## Error in `[[<-.data.frame`(`*tmp*`, "annot_gene_product", value = character(0)): replacement has 0 rows, data has 8778
Recently there was a request to include the Leishmania major gene IDs and descriptions. Thus I will extract them along with the orthologs and append that to the annotations used.
Having spent the time to run the following code, I realized that the orthologs data structure above actually already has the gene IDs and descriptions.
Thus I will leave my query in place to extract the major annotations, but follow it up with a collapse of the major orthologs and appending of that to the panamensis annotations.
orgdb <- "org.Lmajor.Friedlin.v49.eg.db"
tt <- sm(library(orgdb, character.only = TRUE))
major_db <- org.Lmajor.Friedlin.v49.eg.db
all_fields <- columns(pan_db)
all_lm_annot <- sm(load_orgdb_annotations(
major_db,
keytype = "gid",
fields = c("annot_gene_entrez_id", "annot_gene_name",
"annot_strand", "annot_chromosome", "annot_cds_length",
"annot_gene_product")))$genes
wanted_orthos_idx <- orthos[["ORTHOLOGS_SPECIES"]] == "Leishmania major strain Friedlin"
sum(wanted_orthos_idx)
wanted_orthos <- orthos[wanted_orthos_idx, ]
wanted_orthos <- wanted_orthos[, c("GID", "ORTHOLOGS_ID", "ORTHOLOGS_NAME")]
collapsed_orthos <- wanted_orthos %>%
group_by(GID) %>%
summarise(collapsed_id = stringr::str_c(ORTHOLOGS_ID, collapse = " ; "),
collapsed_name = stringr::str_c(ORTHOLOGS_NAME, collapse = " ; "))
all_lp_annot <- merge(all_lp_annot, collapsed_orthos, by.x = "row.names",
by.y = "GID", all.x = TRUE)
rownames(all_lp_annot) <- all_lp_annot[["Row.names"]]
all_lp_annot[["Row.names"]] <- NULL
data_structures <- c(data_structures, "lp_lengths", "lp_go", "all_lp_annot")The following block loads the full genome sequence for panamensis. We may use this later to attempt to estimate PCR primers to discern strains.
I am not sure how to increase the number of open files in a container, as a result this does not work.
## testing_panamensis <- make_eupath_bsgenome(entry = panamensis_entry, eu_version = "v46")
pkg_candidates <- grepl(x = all_installed, pattern = "BSGenome\\.Leishmania\\.panamensis.*")
pkg_name <- all_installed[pkg_candidates][1]
library(as.character(pkg_name), character.only = TRUE)## Loading required package: GenomeInfoDb
## Loading required package: BSgenome
## Loading required package: GenomicRanges
## Loading required package: Biostrings
## Loading required package: XVector
##
## Attaching package: 'Biostrings'
## The following object is masked from 'package:base':
##
## strsplit
## Loading required package: BiocIO
## Loading required package: rtracklayer
The process of sample estimation takes two primary inputs:
An expressionSet(or summarizedExperiment) is a data structure used in R to examine RNASeq data. It is comprised of annotations, metadata, and expression data. In the case of our processing pipeline, the location of the expression data is provided by the filenames in the metadata.
The following samples are much lower coverage:
There is a set of strains which acquired resistance in vitro. These are included in the dataset, but there are not likely enough of them to query that question explicitly.
The following list contains the colors we have chosen to use when plotting the various ways of discerning the data.
color_choices <- list(
"strain" = list(
## "z1.0" = "#333333", ## Changed this to 'braz' to make it easier to find them.
"z2.0" = "#555555",
"z3.0" = "#777777",
"z2.1" = "#874400",
"z2.2" = "#0000cc",
"z2.3" = "#cc0000",
"z2.4" = "#df7000",
"z3.2" = "#888888",
"z1.0" = "#cc00cc",
"z1.5" = "#cc00cc",
"b2904" = "#cc00cc",
"unknown" = "#cbcbcb"),
## "null" = "#000000"),
"zymo" = list(
"z22" = "#0000cc",
"z23" = "#cc0000"),
"cf" = list(
"cure" = "#006f00",
"fail" = "#9dffa0",
"unknown" = "#cbcbcb",
"notapplicable" = "#000000"),
"susceptibility" = list(
"resistant" = "#8563a7",
"sensitive" = "#8d0000",
"ambiguous" = "#cbcbcb",
"unknown" = "#555555"))
data_structures <- c(data_structures, "color_choices")The data structure ‘lp_se’ contains the data for all samples which have hisat2 count tables, and which pass a few initial quality tests (e.g. they must have more than 8550 genes with >0 counts and >5e6 reads which mapped to a gene); genes which are annotated with a few key redundant categories (leishmanolysin for example) are also culled.
There are a few metadata columns which we really want to make certain are standardized.
Note: I changed this to print both the number of reads and genes for removed samples.
202510: Commenting out the semantic filter and will either not apply it or move it to somewhere after the visualization of the data.
sanitize_columns <- c("passagenumber", "clinicalresponse", "clinicalcategorical",
"zymodemecategorical", "included")
lp_se <- create_se(sample_sheet,
gene_info = all_lp_annot,
annotation_name = orgdb_pkg_name,
savefile = glue("rda/tmrc2_lp_se_all_raw-v{ver}.rda"),
id_column = "hpglidentifier",
file_column = "lpanamensisv36hisatfile") %>%
set_conditions(fact = "zymodemecategorical", colors = color_choices[["strain"]]) %>%
## semantic_filter(semantic = c("amastin", "gp63", "leishmanolysin"),
## semantic_column = "annot_gene_product") %>%
sanitize_metadata(columns = sanitize_columns) %>%
subset_se(subset = "included=='yes'") %>%
set_factors(columns = sanitize_columns, class = "factor")## Reading the sample metadata.
## Did not find the column: hpglidentifier.
## Setting the ID column to the first column.
## Checking the state of the condition column.
## Checking the state of the batch column.
## Checking the condition factor.
## The sample definitions comprises: 93 rows(samples) and 74 columns(metadata fields).
## Matched 8778 annotations and counts.
## The final summarized experiment has 8778 rows and 74 columns.
## The numbers of samples by condition are:
##
## z2.1 z2.2 z2.3 z2.4
## 7 43 41 2
## Warning in set_se_colors(new_se, colors = colors): Colors for the following
## categories are not being used: z2.0, z3.0, z3.2, z1.0, z1.5, b2904, unknown.
## Recasting the data.frame to DataFrame.
## rownames sampleid tubelabelorigin included
## Length:93 Length:93 Length:93 yes:93
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## sourcelab expperson pathogen pathogenstrain
## Length:93 Length:93 Length:93 Length:93
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## host parasitestage phase passagenumber
## Length:93 Length:93 Length:93 2:89
## Class :character Class :character Class :character 3: 3
## Mode :character Mode :character Mode :character 4: 1
##
##
##
##
## parasitenumber clinicalresponse clinicalcategorical zymodemeanalysis
## Length:93 cure :41 cure :41 Length:93
## Class :character failure:34 fail :34 Class :character
## Mode :character nd :18 unknown:18 Mode :character
##
##
##
##
## zymodemecategorical phenotypiccharacteristics
## z21: 7 Min. :2.10
## z22:43 1st Qu.:2.20
## z23:41 Median :2.20
## z24: 2 Mean :2.24
## 3rd Qu.:2.30
## Max. :2.40
##
## susceptibilityinfectionreduction32ugmlsbvhistoricaldata
## Length:93
## Class :character
## Mode :character
##
##
##
##
## susceptibilityinfectionreduction32ugmlsbvcurrentdata
## Length:93
## Class :character
## Mode :character
##
##
##
##
## qualitativeclassificationofdrugsusceptibility rnapreservation
## Length:93 Length:93
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## rnaextractiondate rnaqctesteddate rnangul rnaqcpassed
## Min. :20181024 Min. :20181024 Length:93 Length:93
## 1st Qu.:20200918 1st Qu.:20200921 Class :character Class :character
## Median :20210211 Median :20210217 Mode :character Mode :character
## Mean :20202867 Mean :20204528
## 3rd Qu.:20210913 3rd Qu.:20210914
## Max. :20211112 Max. :20211116
## NA's :1
## rnangul1 x260280 x260230 rnavolumeul
## Length:93 Length:93 Length:93 Min. :24.1
## Class :character Class :character Class :character 1st Qu.:30.0
## Mode :character Mode :character Mode :character Median :30.0
## Mean :29.8
## 3rd Qu.:30.0
## Max. :30.0
## NA's :8
## rnaavailableul libraryconstdate libraryqcdate
## Min. :17.1 Min. :20181025 Min. :20181029
## 1st Qu.:26.2 1st Qu.:20200922 1st Qu.:20200564
## Median :27.4 Median :20210303 Median :20201223
## Mean :26.6 Mean :20204976 Mean :20203133
## 3rd Qu.:27.7 3rd Qu.:20210923 3rd Qu.:20210317
## Max. :28.5 Max. :20211223 Max. :20211223
## NA's :8 NA's :22
## rnausedtoconstructlibrariesul rnausedtoconstructlibrariesug libqcpassed
## Min. :0.410 Length:93 Length:93
## 1st Qu.:0.797 Class :character Class :character
## Median :1.060 Mode :character Mode :character
## Mean :1.614
## 3rd Qu.:2.318
## Max. :8.010
## NA's :9
## index indexsequence libraryvolumeul
## Min. : 1.0 Length:93 Min. :27.0
## 1st Qu.: 7.0 Class :character 1st Qu.:28.0
## Median :12.0 Mode :character Median :28.0
## Mean :13.3 Mean :27.9
## 3rd Qu.:20.0 3rd Qu.:28.0
## Max. :27.0 Max. :28.0
##
## libraryvolumesenttonajibu00b4slabul shipmentu00a0date descriptonandremarks
## Min. :15.0 Min. :20200217 Length:93
## 1st Qu.:15.0 1st Qu.:20210104 Class :character
## Median :15.0 Median :20210427 Mode :character
## Mean :15.1 Mean :20209109
## 3rd Qu.:15.0 3rd Qu.:20211012
## Max. :28.0 Max. :20220103
## NA's :8
## librarybioanalyzerprofileelsayedlabfilenamewelllane libraryconcnm
## Length:93 Min. : 1.7
## Class :character 1st Qu.:25.4
## Mode :character Median :36.6
## Mean :38.8
## 3rd Qu.:54.1
## Max. :82.9
## NA's :50
## samplefor100ul2or4nmsequencing waterfor100ul2nmsequencing sequencingorderno
## Min. : 2.51 Min. :-1.76 Length:93
## 1st Qu.: 3.56 1st Qu.:89.33 Class :character
## Median : 7.34 Median :92.55 Mode :character
## Mean : 8.93 Mean :84.40
## 3rd Qu.:10.38 3rd Qu.:95.77
## Max. :41.67 Max. :97.49
## NA's :66 NA's :66
## seqorderdate seqcompletedate totalreads trimmedreads
## Min. :20191107 Length:93 Min. :1.76e+06 Min. :1.44e+06
## 1st Qu.:20191107 Class :character 1st Qu.:2.63e+07 1st Qu.:2.13e+07
## Median :20210427 Mode :character Median :3.13e+07 Median :2.64e+07
## Mean :20201840 Mean :4.25e+07 Mean :3.59e+07
## 3rd Qu.:20210427 3rd Qu.:4.59e+07 3rd Qu.:3.59e+07
## Max. :20210427 Max. :1.60e+08 Max. :1.47e+08
## NA's :84 NA's :22 NA's :22
## percentkept lpanamensisv36salmonfile lpanamensisv36hisatfile
## Min. :0.588 Length:93 Length:93
## 1st Qu.:0.796 Class :character Class :character
## Median :0.854 Mode :character Mode :character
## Mean :0.834
## 3rd Qu.:0.902
## Max. :0.932
## NA's :25
## hisatsinglemappedconcordant hisatmultimappedconcordant
## Min. :1.85e+05 Min. : 19166
## 1st Qu.:1.82e+07 1st Qu.:1080740
## Median :2.22e+07 Median :1354729
## Mean :3.02e+07 Mean :1936290
## 3rd Qu.:3.05e+07 3rd Qu.:2092224
## Max. :1.21e+08 Max. :7648225
## NA's :22 NA's :22
## hisatconcordantmappingrate hisatdiscordantsingle hisatdiscordantmulti
## Min. :0.00659 Min. : 319672 Min. : 47820
## 1st Qu.:0.88420 1st Qu.: 558865 1st Qu.: 67872
## Median :0.90733 Median : 788489 Median : 76361
## Mean :0.89400 Mean : 4281951 Mean : 963850
## 3rd Qu.:0.92829 3rd Qu.: 850646 3rd Qu.: 102498
## Max. :0.97614 Max. :22441366 Max. :5406308
## NA's :22 NA's :87 NA's :87
## hisattotalrate bcftable freebayessummary r1slforward
## Min. :0.9 Length:93 Length:93 Min. : 0.0
## 1st Qu.:0.9 Class :character Class :character 1st Qu.: 13.0
## Median :0.9 Mode :character Mode :character Median : 24.0
## Mean :0.9 Mean : 29.2
## 3rd Qu.:0.9 3rd Qu.: 37.0
## Max. :0.9 Max. :111.0
## NA's :92 NA's :32
## r1slrevcomp r2slforward r2slrevcomp zymodemereference
## Min. : 38 Min. : 101616 Min. : 0.0 Length:93
## 1st Qu.: 226 1st Qu.: 237498 1st Qu.: 2.0 Class :character
## Median : 479 Median : 328730 Median : 4.5 Mode :character
## Mean : 4168 Mean : 453401 Mean : 907.5
## 3rd Qu.: 1360 3rd Qu.: 552578 3rd Qu.: 9.0
## Max. :51878 Max. :1450388 Max. :47191.0
## NA's :32 NA's :39 NA's :39
## knnv2classification knnv2notes hclustclade hclustnotes
## Length:93 Length:93 Length:93 Length:93
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## knnhclusttogethercall condition batch
## Length:93 Length:93 undefined:93
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
data_structures <- c(data_structures, "lp_se")
save(list = "lp_se", file = glue("rda/tmrc2_lp_se_all_sanitized-v{ver}.rda"))
table(colData(lp_se)[["zymodemecategorical"]])##
## z21 z22 z23 z24
## 7 43 41 2
##
## cure failure nd
## 41 34 18
##
## cure fail unknown
## 41 34 18
## [1] 93
## [1] "TMRC20002" "TMRC20004" "TMRC20067" "TMRC20068" "TMRC20041" "TMRC20015"
## [7] "TMRC20009" "TMRC20016" "TMRC20011" "TMRC20017" "TMRC20019" "TMRC20024"
## [13] "TMRC20036" "TMRC20069" "TMRC20033" "TMRC20031" "TMRC20055" "TMRC20078"
## [19] "TMRC20094" "TMRC20042" "TMRC20058" "TMRC20072" "TMRC20059" "TMRC20048"
## [25] "TMRC20057" "TMRC20088" "TMRC20056" "TMRC20043" "TMRC20046" "TMRC20093"
## [31] "TMRC20089" "TMRC20047" "TMRC20090" "TMRC20044" "TMRC20045" "TMRC20108"
## [37] "TMRC20096" "TMRC20101" "TMRC20092" "TMRC20091" "TMRC20095"
## [1] "TMRC20001" "TMRC20065" "TMRC20039" "TMRC20010" "TMRC20012" "TMRC20013"
## [7] "TMRC20014" "TMRC20018" "TMRC20070" "TMRC20020" "TMRC20021" "TMRC20022"
## [13] "TMRC20026" "TMRC20076" "TMRC20073" "TMRC20079" "TMRC20071" "TMRC20060"
## [19] "TMRC20083" "TMRC20085" "TMRC20105" "TMRC20109" "TMRC20098" "TMRC20082"
## [25] "TMRC20102" "TMRC20099" "TMRC20100" "TMRC20084" "TMRC20087" "TMRC20103"
## [31] "TMRC20104" "TMRC20086" "TMRC20107" "TMRC20081"
unknown_ids <- colData(lp_se)[["clinicalcategorical"]] == "unknown"
rownames(colData(lp_se))[unknown_ids]## [1] "TMRC20005" "TMRC20066" "TMRC20037" "TMRC20038" "TMRC20077" "TMRC20074"
## [7] "TMRC20063" "TMRC20053" "TMRC20052" "TMRC20064" "TMRC20075" "TMRC20051"
## [13] "TMRC20050" "TMRC20049" "TMRC20062" "TMRC20110" "TMRC20080" "TMRC20054"
all_sensitive_ids <- colData(lp_se)[["qualitativeclassificationofdrugsusceptibility"]] == "Sensitive"
sensitive_ids <- rownames(colData(lp_se))[all_sensitive_ids]
sensitive_ids## [1] "TMRC20002" "TMRC20004" "TMRC20005" "TMRC20039" "TMRC20041" "TMRC20009"
## [7] "TMRC20011" "TMRC20012" "TMRC20017" "TMRC20014" "TMRC20019" "TMRC20020"
## [13] "TMRC20022" "TMRC20024" "TMRC20036" "TMRC20069" "TMRC20033" "TMRC20026"
## [19] "TMRC20031" "TMRC20076" "TMRC20055" "TMRC20078" "TMRC20072" "TMRC20057"
## [25] "TMRC20056" "TMRC20060" "TMRC20077" "TMRC20074" "TMRC20063" "TMRC20053"
## [31] "TMRC20050" "TMRC20049" "TMRC20110" "TMRC20083" "TMRC20046" "TMRC20093"
## [37] "TMRC20044" "TMRC20045" "TMRC20109" "TMRC20096" "TMRC20092" "TMRC20091"
## [43] "TMRC20084" "TMRC20087" "TMRC20103" "TMRC20086" "TMRC20081"
all_resistant_ids <- colData(lp_se)[["qualitativeclassificationofdrugsusceptibility"]] == "Resistant"
resistant_ids <- rownames(colData(lp_se))[all_resistant_ids]
resistant_ids## [1] "TMRC20001" "TMRC20065" "TMRC20066" "TMRC20037" "TMRC20038" "TMRC20067"
## [7] "TMRC20068" "TMRC20015" "TMRC20010" "TMRC20016" "TMRC20013" "TMRC20018"
## [13] "TMRC20070" "TMRC20021" "TMRC20073" "TMRC20079" "TMRC20071" "TMRC20094"
## [19] "TMRC20042" "TMRC20058" "TMRC20059" "TMRC20048" "TMRC20088" "TMRC20052"
## [25] "TMRC20064" "TMRC20075" "TMRC20051" "TMRC20062" "TMRC20080" "TMRC20043"
## [31] "TMRC20054" "TMRC20085" "TMRC20089" "TMRC20047" "TMRC20090" "TMRC20105"
## [37] "TMRC20108" "TMRC20098" "TMRC20101" "TMRC20082" "TMRC20102" "TMRC20099"
## [43] "TMRC20100" "TMRC20104" "TMRC20107" "TMRC20095"
all_z23 <- colData(lp_se)[["zymodemecategorical"]] == "z23"
z23_ids <- rownames(colData(lp_se))[all_z23]
z23_ids## [1] "TMRC20001" "TMRC20065" "TMRC20066" "TMRC20037" "TMRC20038" "TMRC20067"
## [7] "TMRC20068" "TMRC20015" "TMRC20010" "TMRC20016" "TMRC20013" "TMRC20018"
## [13] "TMRC20070" "TMRC20021" "TMRC20073" "TMRC20079" "TMRC20071" "TMRC20094"
## [19] "TMRC20058" "TMRC20059" "TMRC20048" "TMRC20052" "TMRC20064" "TMRC20075"
## [25] "TMRC20051" "TMRC20062" "TMRC20080" "TMRC20043" "TMRC20054" "TMRC20085"
## [31] "TMRC20089" "TMRC20090" "TMRC20105" "TMRC20098" "TMRC20082" "TMRC20102"
## [37] "TMRC20099" "TMRC20100" "TMRC20104" "TMRC20107" "TMRC20095"
all_z22 <- colData(lp_se)[["zymodemecategorical"]] == "z22"
z22_ids <- rownames(colData(lp_se))[all_z22]
z22_ids## [1] "TMRC20002" "TMRC20004" "TMRC20005" "TMRC20039" "TMRC20041" "TMRC20009"
## [7] "TMRC20011" "TMRC20012" "TMRC20017" "TMRC20014" "TMRC20019" "TMRC20020"
## [13] "TMRC20022" "TMRC20024" "TMRC20036" "TMRC20069" "TMRC20033" "TMRC20026"
## [19] "TMRC20031" "TMRC20076" "TMRC20055" "TMRC20078" "TMRC20042" "TMRC20072"
## [25] "TMRC20088" "TMRC20060" "TMRC20077" "TMRC20074" "TMRC20063" "TMRC20053"
## [31] "TMRC20050" "TMRC20049" "TMRC20110" "TMRC20083" "TMRC20046" "TMRC20044"
## [37] "TMRC20109" "TMRC20096" "TMRC20101" "TMRC20092" "TMRC20087" "TMRC20086"
## [43] "TMRC20081"
## Mode FALSE TRUE
## logical 40 3
## [1] "TMRC20019" "TMRC20020" "TMRC20078" "TMRC20085" "TMRC20093" "TMRC20102"
## Mode FALSE
## logical 41
All the following data will derive from this starting point.
Here is a table of my current classifier’s interpretation of the strains.
##
## unknown z21 z22 z23 z24
## 2 5 43 41 2
merged_zymo <- lp_se
colData(merged_zymo)[["zymodeme"]] <- as.character(colData(merged_zymo)[["zymodemecategorical"]])
z21_idx <- colData(merged_zymo)[["zymodeme"]] == "z21"
colData(merged_zymo)[z21_idx, "zymodeme"] <- "z22"
z24_idx <- colData(merged_zymo)[["zymodeme"]] == "z24"
colData(merged_zymo)[z24_idx, "zymodeme"] <- "z23"
keepers <- colData(merged_zymo)[["zymodeme"]] == "z22" |
colData(merged_zymo)[["zymodeme"]] == "z23"
merged_zymo <- merged_zymo[, keepers] %>%
set_conditions(fact = "zymodeme", colors = color_choices[["zymo"]])## The numbers of samples by condition are:
##
## z22 z23
## 50 43
##
## cure fail unknown
## 41 34 18
unknown_ids <- colData(lp_se)[["clinicalcategorical"]] == "unknown"
rownames(colData(lp_se))[unknown_ids]## [1] "TMRC20005" "TMRC20066" "TMRC20037" "TMRC20038" "TMRC20077" "TMRC20074"
## [7] "TMRC20063" "TMRC20053" "TMRC20052" "TMRC20064" "TMRC20075" "TMRC20051"
## [13] "TMRC20050" "TMRC20049" "TMRC20062" "TMRC20110" "TMRC20080" "TMRC20054"
failed_ids <- colData(lp_se)[["clinicalcategorical"]] == "fail"
rownames(colData(lp_se))[failed_ids]## [1] "TMRC20001" "TMRC20065" "TMRC20039" "TMRC20010" "TMRC20012" "TMRC20013"
## [7] "TMRC20014" "TMRC20018" "TMRC20070" "TMRC20020" "TMRC20021" "TMRC20022"
## [13] "TMRC20026" "TMRC20076" "TMRC20073" "TMRC20079" "TMRC20071" "TMRC20060"
## [19] "TMRC20083" "TMRC20085" "TMRC20105" "TMRC20109" "TMRC20098" "TMRC20082"
## [25] "TMRC20102" "TMRC20099" "TMRC20100" "TMRC20084" "TMRC20087" "TMRC20103"
## [31] "TMRC20104" "TMRC20086" "TMRC20107" "TMRC20081"
## Warning in fortify(data, ...): Arguments in `...` must be used.
## x Problematic argument:
## * colour = colors
## i Did you misspell an argument name?
## Library sizes of 93 samples,
## ranging from 564,812 to 1.37e+08.
pdf(file = "figures/library_size_pre_filter.pdf", width = 24, height = 12)
pre_libsize$plot
dev.off()## png
## 2
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## i Please use `linewidth` instead.
## i The deprecated feature was likely used in the hpgltools package.
## Please report the issue to the authors.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## A non-zero genes plot of 93 samples.
## These samples have an average 28.6 CPM coverage and 8691 genes observed, ranging from 8452 to
## 8749.
## Warning: ggrepel: 77 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
## Warning: ggrepel: 82 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
## png
## 2
## The samples (and read coverage) removed when filtering 8550 non-zero genes are:
## TMRC20002
## 11681227
## TMRC20002
## 8452
## Samples removed: 8452
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
## A non-zero genes plot of 92 samples.
## These samples have an average 28.78 CPM coverage and 8694 genes observed, ranging from 8554 to
## 8749.
## Warning: ggrepel: 76 unlabeled data points (too many overlaps). Consider
## increasing max.overlaps
Column ‘Q’ in the sample sheet, make a categorical version of it with these parameters:
Note that these cutoffs are only valid for the historical data. The newer susceptibility data uses a cutoff of 0.78 for sensitive. I will set ambiguous to 0.5 to 0.78?
max_resist_historical <- 0.35
min_sensitive_historical <- 0.49
## 202305: Removed ambiguous category for the current set.
max_resist_current <- 0.77
min_sensitive_current <- 0.77The sanitize_percent() function seeks to make the percentage values recorded by excel more reliable. Unfortunately, sometimes excel displays the value ‘49%’ when the information recorded in the worksheet is any one of the following:
Thus, the following block will sanitize these percentage values into a single decimal number and make a categorical variable from it using pre-defined values for resistant/ambiguous/sensitive. This categorical variable will be stored in a new column: ‘sus_category_historical’.
st <- colData(lp_se)[["susceptibilityinfectionreduction32ugmlsbvhistoricaldata"]]
starting <- sanitize_percent(st)
st## [1] "0.45" "0.14" "0.99" "0.97" "0" "0.97" "0"
## [8] "0" "0.46" "0.45" "0.97" "0.56" "0.99" "0.46"
## [15] "0.7" "0.99" "0.99" "0.45" "0.98" "0.99" "0.49"
## [22] "No data" "No data" "0.99" "0.66" "0.99" "0.99" "1"
## [29] "1" "0.94" "0.94" "No data" "No data" "No data" "No data"
## [36] "No data" "No data" "No data" "No data" "No data" "No data" "No data"
## [43] "No data" "No data" "No data" "0.99" "0.99" "No data" "0.98"
## [50] "0.97" "0.96" "0.96" "0" "0" "0" "0.06"
## [57] "0.94" "0.94" "0.03" "0.94" "0" "0.25" "0.95"
## [64] "0.27" "No data" "No data" "No data" "No data" "No data" "No data"
## [71] "No data" "No data" "No data" "No data" "No data" "No data" "No data"
## [78] "No data" "No data" "No data" "No data" "No data" "No data" "No data"
## [85] "No data" "No data" "No data" "No data" "No data" "No data" "No data"
## [92] "No data"
## [1] 0.45 0.14 0.99 0.97 0.00 0.97 0.00 0.00 0.46 0.45 0.97 0.56 0.99 0.46 0.70
## [16] 0.99 0.99 0.45 0.98 0.99 0.49 NA NA 0.99 0.66 0.99 0.99 1.00 1.00 0.94
## [31] 0.94 NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [46] 0.99 0.99 NA 0.98 0.97 0.96 0.96 0.00 0.00 0.00 0.06 0.94 0.94 0.03 0.94
## [61] 0.00 0.25 0.95 0.27 NA NA NA NA NA NA NA NA NA NA NA
## [76] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
## [91] NA NA
## [1] 45
sus_categorical[na_idx] <- "unknown"
resist_idx <- starting <= max_resist_historical
sus_categorical[resist_idx] <- "resistant"
indeterminant_idx <- starting > max_resist_historical &
starting < min_sensitive_historical
sus_categorical[indeterminant_idx] <- "ambiguous"
susceptible_idx <- starting >= min_sensitive_historical
sus_categorical[susceptible_idx] <- "sensitive"
sus_categorical <- as.factor(sus_categorical)
colData(lp_se)[["sus_category_historical"]] <- sus_categorical
table(sus_categorical)## sus_categorical
## ambiguous resistant sensitive unknown
## 5 12 30 45
two_sankey <- plot_meta_sankey(
merged_zymo, factors = c("zymodeme", "clinicalcategorical", "susceptibility"),
drill_down = TRUE, color_choices = color_choices)## These columns are not in the metadata: susceptibility
## Warning: attributes are not identical across measure variables; they will be
## dropped
## Warning: The `size` argument of `element_rect()` is deprecated as of ggplot2 3.4.0.
## i Please use the `linewidth` argument instead.
## i The deprecated feature was likely used in the ggsankey package.
## Please report the issue at <https://github.com/davidsjoberg/ggsankey/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## A sankey plot describing the metadata of 93 samples,
## including 8 out of 0 nodes and traversing metadata factors:
## zymodeme, clinicalcategorical.
The same process will be repeated for the current iteration of the sensitivity assay and stored in the ‘sus_category_current’ column.
starting_current <- sanitize_percent(colData(lp_se)[["susceptibilityinfectionreduction32ugmlsbvcurrentdata"]])
sus_categorical_current <- starting_current
na_idx <- is.na(starting_current)
sum(na_idx)## [1] 0
sus_categorical_current[na_idx] <- "unknown"
## The following is only valid when we had three categories, resistant/ambiguous/sensitive
## The new cutoffs drop ambiguous.
#resist_idx <- starting_current <= max_resist_current
#sus_categorical_current[resist_idx] <- "resistant"
#indeterminant_idx <- starting_current > max_resist_current &
# starting_current < min_sensitive_current
#sus_categorical_current[indeterminant_idx] <- "ambiguous"
#susceptible_idx <- starting_current >= min_sensitive_current
#sus_categorical_current[susceptible_idx] <- "sensitive"
#sus_categorical_current <- as.factor(sus_categorical_current)
resist_idx <- starting_current <= max_resist_current
sensitive_idx <- !resist_idx
sus_categorical_current[resist_idx] <- "resistant"
sus_categorical_current[sensitive_idx] <- "sensitive"
sus_categorical_current <- as.factor(sus_categorical_current)
colData(lp_se)[["sus_category_current"]] <- sus_categorical_current
colData(lp_se)[["susceptibility"]] <- sus_categorical_current
table(sus_categorical_current)## sus_categorical_current
## resistant sensitive
## 46 46
lp_sankey <- plot_meta_sankey(
lp_se, factors = c("zymodemecategorical", "clinicalcategorical", "susceptibility"),
drill_down = TRUE, color_choices = color_choices)## Warning: attributes are not identical across measure variables; they will be
## dropped
## A sankey plot describing the metadata of 92 samples,
## including 23 out of 0 nodes and traversing metadata factors:
## zymodemecategorical, clinicalcategorical, susceptibility.
In many queries, we will seek to compare only the two primary strains, zymodeme 2.2 and 2.3. The following block will extract only those samples.
Note: IMPORTANT Maria Adelaida prefers not to use lp_two_strains. We should not at this time use the merged 2.1/2.2 and 2.4/2.3 categories.
lp_strain <- lp_se %>%
set_batches(fact = sus_categorical_current) %>%
set_colors(color_choices[["strain"]])## The number of samples by batch are:
##
## resistant sensitive
## 46 46
## Warning in set_se_colors(exp, ...): Colors for the following categories are not
## being used: z2.0, z3.0, z3.2, z1.0, z1.5, b2904, unknown.
##
## z2.1 z2.2 z2.3 z2.4
## 7 42 41 2
Clinical outcome is by far the most problematic comparison in this data, but here is the recategorization of the data using it:
lp_cf <- set_conditions(lp_se, fact = "clinicalcategorical",
colors = color_choices[["cf"]]) %>%
set_batches(fact = sus_categorical_current)## The numbers of samples by condition are:
##
## cure fail unknown
## 40 34 18
## Warning in set_se_colors(new_se, colors = colors): Colors for the following
## categories are not being used: notapplicable.
## The number of samples by batch are:
##
## resistant sensitive
## 46 46
##
## cure fail unknown
## 40 34 18
data_structures <- c(data_structures, "lp_cf")
save(list = "lp_cf", file = glue("rda/tmrc2_lp_cf-v{ver}.rda"))
lp_cf_known <- subset_se(lp_cf, subset = "condition!='unknown'")
data_structures <- c(data_structures, "lp_cf_known")
save(list = "lp_cf_known", file = glue("rda/tmrc2_lp_cf_known-v{ver}.rda"))
data_structures <- c(data_structures, "lp_cf_known")
save(list = "lp_cf_known", file = glue("rda/tmrc2_lp_cf_known-v{ver}.rda"))Use the factorized version of susceptibility to categorize the samples by the historical data.
lp_susceptibility_historical <- set_conditions(
lp_se, fact = "sus_category_historical", colors = color_choices[["susceptibility"]]) %>%
set_batches(fact = "clinicalcategorical")## The numbers of samples by condition are:
##
## ambiguous resistant sensitive unknown
## 5 12 30 45
## The number of samples by batch are:
##
## cure fail unknown
## 40 34 18
Use the factorized version of susceptibility to categorize the samples by the historical data.
This will likely be our canonical susceptibility dataset, so I will remove the suffix and just call it ‘lp_susceptibility’.
lp_susceptibility <- set_conditions(
lp_se, fact = "sus_category_current", colors = color_choices[["susceptibility"]]) %>%
set_batches(fact = "clinicalcategorical")## The numbers of samples by condition are:
##
## resistant sensitive
## 46 46
## Warning in set_se_colors(new_se, colors = colors): Colors for the following
## categories are not being used: ambiguous, unknown.
## The number of samples by batch are:
##
## cure fail unknown
## 40 34 18
I think this is redundant with a previous block, but I am leaving it until I am certain that it is not required in a following document.
Note: IMPORTANT This is the set Maria Adeliada prefers to use.
The following section will create some initial data structures of the observed variants in the parasite samples. This will include some of our 2016 samples for some classification queries.
I changed and improved the mapping and variant detection methods from what we used for the 2016 data. So some small changes will be required to merge them.
lp_previous <- create_se("sample_sheets/tmrc2_samples_20191203.xlsx",
file_column = "tophat2file",
savefile = glue("rda/lp_previous-v{ver}.rda"))
tt <- lp_previous$expressionset
rownames(tt) <- gsub(pattern = "^exon_", replacement = "", x = rownames(tt))
rownames(tt) <- gsub(pattern = "\\.1$", replacement = "", x = rownames(tt))
rownames(tt) <- gsub(pattern = "\\-1$", replacement = "", x = rownames(tt))
lp_previous$expressionset <- tt
rm(tt)
data_structures <- c(data_structures, "lp_previous")The count_se_snps() function uses our expressionset data and a metadata column in order to extract the mpileup or freebayes-based variant calls and create matrices of the likelihood that each position-per-sample is in fact a variant.
There is an important caveat here which changed on 202301: I was interpreting using the PAIRED tag, which is only used for, unsurprisingly, paired-end samples. A couple samples are not paired and so were failing silently. The QA tag looks like it is more appropriate and should work across both types. One way to find out, I am setting it here and will look to see if the results make more sense for my test samples (TMRC2001, TMRC2005, TMRC2007).
## The next line drops the samples which are missing the SNP pipeline.
lp_snp <- subset_se(lp_se, subset = "!is.na(colData(lp_se)[['freebayessummary']])")
lp_snp_sufficient <- subset_se(lp_snp, subset = "rownames!='TMRC20082'")
lp_snp_only22_23_ref <- subset_se(lp_snp, subset = "zymodemereference=='z2.2'|zymodemereference=='z2.3'") %>%
subset_se(subset = "rownames!='TMRC20082'")
lp_snp_22_23_ml <- subset_se(lp_snp, subset = "knnv2classification=='z22'|knnv2classification=='z23'") %>%
subset_se(subset = "rownames!='TMRC20082'")
new_snps_sufficient <- count_snps(lp_snp_sufficient, annot_column = "freebayessummary",
snp_column = "QA", reader = "readr")## Using the snp column: QA from the sample annotations.
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## New names:
## * `DP` -> `DP...3`
## * `RO` -> `RO...8`
## * `AO` -> `AO...9`
## * `QR` -> `QR...12`
## * `QA` -> `QA...13`
## * `DP` -> `DP...42`
## * `RO` -> `RO...43`
## * `QR` -> `QR...44`
## * `AO` -> `AO...45`
## * `QA` -> `QA...46`
new_snps_only22_23_ref_suf <- count_snps(lp_snp_only22_23_ref, annot_column = "freebayessummary",
snp_column = "QA", reader = "readr")## Using the snp column: QA from the sample annotations.
## New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:
new_snps_22_23_ml_suf <- count_snps(lp_snp_22_23_ml, annot_column = "freebayessummary",
snp_column = "QA", reader = "readr")## Using the snp column: QA from the sample annotations.
## New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:New names:
## Lets see if we get numbers which make sense.
summary(assay(new_snps_sufficient)[["TMRC20001"]]) ## My weirdo sample## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0 0.0 0.0 22.8 0.0 2217.0
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0 0 0 104 0 247568
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0 0 0 1121 0 1708458
## Now that we are reasonably confident that things make more sense, lets save and move on...
data_structures <- c(data_structures, "new_snps_sufficient", "lp_snp")
## Most of the time I just run normalize() and assume it will dispatch to normalize_se()
sufficient_norm <- normalize(new_snps_sufficient, transform = "log2")## transform_counts: Found 79143354 values equal to 0, adding 1 to the matrix.
Now let us pull in the 2016 data.
old_snps <- count_snps(lp_previous, annot_column = "bcftable", snp_column = 2)
data_structures <- c(data_structures, "old_snps")
save(list = "lp_snp", file = glue("rda/lp_snp-v{ver}.rda"))
data_structures <- c(data_structures, "lp_snp")
save(list = "new_snps", file = glue("rda/new_snps-v{ver}.rda"))
data_structures <- c(data_structures, "new_snps")
save(list = "old_snps", file = glue("rda/old_snps-v{ver}.rda"))
data_structures <- c(data_structures, "old_snps")
nonzero_snps <- assay(new_snps) != 0
colSums(nonzero_snps)As far as I can tell, freebayes and mpileup are reasonably similar in their sensitivity/specificity; so combining the two datasets like this is expected to work with minimal problems. The most likely problem is that my mpileup-based pipeline is unable to handle indels.
I am taking a heatmap from our variant data and manually identifying sample groups.
All of the above focused entire on the parasite samples, now let us pull up the macrophage infected samples. This will comprise two datasets, one of the human and one of the parasite.
The metadata for the macrophage samples contains a couple of columns for mapped human and parasite reads. We will therefore use them separately to create two expressionsets, one for each species.
## Using mart: ENSEMBL_MART_ENSEMBL from host: apr2020.archive.ensembl.org.
## Successfully connected to the hsapiens_gene_ensembl database.
## Finished downloading ensembl gene annotations.
## Finished downloading ensembl structure annotations.
## symbol columns is null, pattern matching 'symbol' and taking the first.
## Including symbols, there are 67149 vs the 249740 gene annotations.
## Not dropping haplotype chromosome annotations, set drop_haplotypes = TRUE if this is bad.
## Saving annotations to hsapiens_biomart_annotations.rda.
## Finished save().
hs_annot <- hs_annot[["annotation"]]
hs_annot[["transcript"]] <- paste0(rownames(hs_annot), ".", hs_annot[["transcript_version"]])
rownames(hs_annot) <- make.names(hs_annot[["ensembl_gene_id"]], unique = TRUE)
rownames(hs_annot) <- paste0("gene:", rownames(hs_annot))
tx_gene_map <- hs_annot[, c("transcript", "ensembl_gene_id")]
sanitize_columns <- c("drug", "macrophagetreatment", "macrophagezymodeme")
macr_annot <- hs_annot
rownames(macr_annot) <- gsub(x = rownames(macr_annot),
pattern = "^gene:",
replacement = "")
hs_macrophage <- create_se(macrophage_sheet, gene_info = macr_annot,
file_column = "hg38100hisatfile") %>%
set_conditions(fact = "macrophagetreatment") %>%
set_batches(fact = "macrophagezymodeme") %>%
sanitize_metadata(columns = sanitize_columns) %>%
subset_se(nonzero = 12000)## Reading the sample metadata.
## Did not find the column: sampleid.
## Setting the ID column to the first column.
## Did not find the condition column in the sample sheet.
## Filling it in as undefined.
## Did not find the batch column in the sample sheet.
## Filling it in as undefined.
## Checking the state of the condition column.
## Checking the state of the batch column.
## Checking the condition factor.
## The sample definitions comprises: 69 rows(samples) and 80 columns(metadata fields).
## Matched 21481 annotations and counts.
## Some annotations were lost in merging, setting them to 'undefined'.
## The final summarized experiment has 21481 rows and 80 columns.
## The numbers of samples by condition are:
##
## inf inf_sb uninf uninf_sb
## 30 29 5 5
## The number of samples by batch are:
##
## none z2.2 z2.3
## 10 30 29
## Recasting the data.frame to DataFrame.
## rownames tubelabelorigin samplename numberofvials
## Length:69 Length:69 Length:69 Min. :1
## Class :character Class :character Class :character 1st Qu.:1
## Mode :character Mode :character Mode :character Median :1
## Mean :1
## 3rd Qu.:1
## Max. :1
##
## sourcelab expperson cellssource samplecollectiondate
## Length:69 Length:69 Length:69 Min. :20190629
## Class :character Class :character Class :character 1st Qu.:20210813
## Mode :character Mode :character Mode :character Median :20220827
## Mean :20212685
## 3rd Qu.:20220827
## Max. :20220916
##
## typeofcells donor isolationmethod
## Length:69 Length:69 Length:69
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## cellspurificationmethod selectionmethod rnapreservation
## Length:69 Length:69 Length:69
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## rnaextractiondate rnavolumeul rnaavailableul rnaqctesteddate
## Length:69 Min. :30 Min. : 5.2 Min. : 42382
## Class :character 1st Qu.:30 1st Qu.:22.2 1st Qu.:20200114
## Mode :character Median :30 Median :23.3 Median :20205521
## Mean :30 Mean :23.1 Mean :19485696
## 3rd Qu.:30 3rd Qu.:25.6 3rd Qu.:20211111
## Max. :30 Max. :26.2 Max. :20211221
## NA's :41 NA's :41 NA's :41
## bioanalyzerrnangul rnaqcpassed rin nanodroprnangul
## Length:69 Length:69 Length:69 Length:69
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## x260280 x260230 rnausedtoconstructlibrariesul
## Length:69 Length:69 Min. : 2.20
## Class :character Class :character 1st Qu.: 2.80
## Mode :character Mode :character Median : 3.41
## Mean : 4.61
## 3rd Qu.: 4.83
## Max. :23.30
## NA's :41
## rnausedtoconstructlibrariesng libraryqctesteddate libqcpassed
## Min. : 0.5 Min. :20200115 Length:69
## 1st Qu.: 0.5 1st Qu.:20200115 Class :character
## Median :250.3 Median :20201221 Mode :character
## Mean :275.3 Mean :20205505
## 3rd Qu.:500.0 3rd Qu.:20211219
## Max. :800.0 Max. :20211223
## NA's :41 NA's :42
## index libraryvolumeul libraryvolumesenttonajibslabul
## Min. : 1.0 Min. :28 Min. :15
## 1st Qu.: 7.0 1st Qu.:28 1st Qu.:15
## Median :14.5 Median :28 Median :15
## Mean :13.9 Mean :28 Mean :15
## 3rd Qu.:20.2 3rd Qu.:28 3rd Qu.:15
## Max. :27.0 Max. :28 Max. :15
## NA's :41 NA's :41 NA's :41
## shipmentdate oldnew countersampleatcideimul drug
## Min. :20200217 Length:69 Min. :13 antimony:34
## 1st Qu.:20200217 Class :character 1st Qu.:13 none :35
## Median :20210558 Mode :character Median :13
## Mean :20210188 Mean :13
## 3rd Qu.:20220103 3rd Qu.:13
## Max. :20220103 Max. :13
## NA's :41 NA's :56
## descriptonandremarks observation
## Length:69 Length:69
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## librarybioanalyzerprofileelsayedlabfilenamewelllane libraryconcnm
## Length:69 Min. : 22.1
## Class :character 1st Qu.: 57.8
## Mode :character Median : 98.7
## Mean : 96.2
## 3rd Qu.:112.8
## Max. :218.0
## NA's :55
## samplefor100ul2or4nmsequencing waterfor100ul2or4nmsequencing
## Min. :0.917 Min. :92.0
## 1st Qu.:1.754 1st Qu.:96.9
## Median :1.942 Median :98.1
## Mean :2.995 Mean :97.0
## 3rd Qu.:3.082 3rd Qu.:98.2
## Max. :8.000 Max. :99.1
## NA's :56 NA's :56
## sequencingorderno seqorderdate seqcompletedate totalreads
## Length:69 Min. :20200901 Min. :20200910 Min. :12254196
## Class :character 1st Qu.:20200901 1st Qu.:20200910 1st Qu.:21496945
## Mode :character Median :20200901 Median :20200910 Median :23391483
## Mean :20202287 Mean :20202296 Mean :29119440
## 3rd Qu.:20200901 3rd Qu.:20200910 3rd Qu.:27612540
## Max. :20210601 Max. :20210610 Max. :86048061
## NA's :55 NA's :55
## trimmedreads percentkept hg38100salmonfile hg38100hisatfile
## Min. :10400801 Min. :0.735 Length:69 Length:69
## 1st Qu.:19375511 1st Qu.:0.887 Class :character Class :character
## Median :21401552 Median :0.902 Mode :character Mode :character
## Mean :26367248 Mean :0.903
## 3rd Qu.:25048428 3rd Qu.:0.940
## Max. :79775170 Max. :0.945
##
## hisatsinglemappedhg38 hisatmultimappedhg38 hisatmappingratehg38
## Min. : 501881 Min. : 328180 Min. :0.0418
## 1st Qu.:17620997 1st Qu.: 605198 1st Qu.:0.9114
## Median :18986346 Median : 682134 Median :0.9606
## Mean :23074608 Mean :1339401 Mean :0.9223
## 3rd Qu.:22472518 3rd Qu.: 830271 3rd Qu.:0.9787
## Max. :70100660 Max. :7030835 Max. :0.9885
##
## lpanamensisv36hisatfile hisatlpsinglemapped hisatlpmultimapped
## Length:69 Min. : 199 Min. : 14
## Class :character 1st Qu.: 11504 1st Qu.: 770
## Mode :character Median : 284271 Median : 17386
## Mean : 909574 Mean : 70729
## 3rd Qu.:1006681 3rd Qu.: 81008
## Max. :7086371 Max. :620799
##
## parasitemappingrate parasitehostratio x68 macrophagetreatment
## Min. :0.000011 Min. :0.000204 Length:69 inf :30
## 1st Qu.:0.000487 1st Qu.:0.003393 Class :character inf_sb :29
## Median :0.010078 Median :0.003393 Mode :character uninf : 5
## Mean :0.036938 Mean :0.010336 uninf_sb: 5
## 3rd Qu.:0.048453 3rd Qu.:0.003393
## Max. :0.292395 Max. :0.155351
##
## macrophagezymodeme strainid slr1fwd slr1rc
## none:10 Length:69 Min. : 0.00 Min. : 0
## z22 :30 Class :character 1st Qu.: 0.00 1st Qu.: 0
## z23 :29 Mode :character Median : 0.00 Median : 6
## Mean : 1.16 Mean : 31
## 3rd Qu.: 1.00 3rd Qu.: 27
## Max. :11.00 Max. :641
##
## slr2fwd slr2rc slsum slvsreads
## Min. : 2 Min. : 0.000 Min. : 2 Min. :1.03e-07
## 1st Qu.: 224 1st Qu.: 0.000 1st Qu.: 225 1st Qu.:7.81e-06
## Median : 4249 Median : 0.000 Median : 4300 Median :1.83e-04
## Mean : 17256 Mean : 0.667 Mean : 17289 Mean :6.68e-04
## 3rd Qu.: 22089 3rd Qu.: 0.000 3rd Qu.: 22188 3rd Qu.:8.17e-04
## Max. :168826 Max. :13.000 Max. :169487 Max. :6.57e-03
##
## slvshuman trimomatic_input trimomatic_output trimomatic_percent
## Min. :1.05e-07 Length:69 Length:69 Length:69
## 1st Qu.:1.06e-05 Class :character Class :character Class :character
## Median :1.87e-04 Mode :character Mode :character Mode :character
## Mean :8.21e-04
## 3rd Qu.:8.79e-04
## Max. :1.02e-02
##
## fastqc_pct_gc hisat_genome_single_concordant
## Length:69 Length:69
## Class :character Class :character
## Mode :character Mode :character
##
##
##
##
## hisat_genome_multi_concordant hisat_genome_single_all hisat_genome_multi_all
## Length:69 Length:69 Length:69
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## hisat_genome_percent hisat_count_table condition batch
## Length:69 Length:69 Length:69 Length:69
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## The samples (and read coverage) removed when filtering 12000 non-zero genes are:
## TMRC30162
## 521145
## TMRC30162
## 10208
## Samples removed: 10208
fixed_genenames <- gsub(x = rownames(assay(hs_macrophage)), pattern = "^gene:",
replacement = "")
hs_macrophage <- set_genenames(hs_macrophage, ids = fixed_genenames)
table(colData(hs_macrophage)$condition)##
## inf inf_sb uninf uninf_sb
## 29 29 5 5
## The following 3 lines were copy/pasted to datastructures and should be removed soon.
nostrain <- is.na(colData(hs_macrophage)[["strainid"]])
colData(hs_macrophage)[nostrain, "strainid"] <- "none"
colData(hs_macrophage)[["strain_zymo"]] <- paste0("s", colData(hs_macrophage)[["strainid"]],
"_", colData(hs_macrophage)[["macrophagezymodeme"]])
uninfected <- colData(hs_macrophage)[["strain_zymo"]] == "snone_none"
colData(hs_macrophage)[uninfected, "strain_zymo"] <- "uninfected"
data_structures <- c(data_structures, "hs_macrophage")Finally, split off the U937 samples.
In the previous block, we used a new invocation of ensembl-derived annotation data, this time we can just use our existing parasite gene annotations.
lp_macrophage <- create_se(macrophage_sheet, file_column = "lpanamensisv36hisatfile",
gene_info = all_lp_annot,
savefile = glue("rda/lp_macrophage-v{ver}.rda"),
annotation = "org.Lpanamensis.MHOMCOL81L13.v46.eg.db") %>%
set_conditions(fact = "macrophagezymodeme") %>%
set_batches(fact = "macrophagetreatment")## Reading the sample metadata.
## Did not find the column: sampleid.
## Setting the ID column to the first column.
## Did not find the condition column in the sample sheet.
## Filling it in as undefined.
## Did not find the batch column in the sample sheet.
## Filling it in as undefined.
## Checking the state of the condition column.
## Checking the state of the batch column.
## Checking the condition factor.
## The sample definitions comprises: 69 rows(samples) and 80 columns(metadata fields).
## Warning in create_se(macrophage_sheet, file_column = "lpanamensisv36hisatfile",
## : Some samples were removed when cross referencing the samples against the
## count data.
## Matched 8778 annotations and counts.
## The final summarized experiment has 8778 rows and 80 columns.
## The numbers of samples by condition are:
##
## none z2.2 z2.3
## 8 29 29
## The number of samples by batch are:
##
## inf inf_sb uninf uninf_sb
## 29 29 4 4
unfilt_written <- write_se(
lp_macrophage,
excel = glue("analyses/macrophage_de/{ver}/read_counts/lp_macrophage_reads_unfiltered-v{ver}.xlsx"))## Writing the first sheet, containing a legend and some summary data.
## Warning in as.data.frame.DataFrame(pData(se), strinsAsFactors = FALSE):
## arguments in '...' ignored
## The following samples have less than 5705.7 genes.
## [1] "TMRC30066" "TMRC30117" "TMRC30244" "TMRC30246" "TMRC30249" "TMRC30266"
## [7] "TMRC30268" "TMRC30326" "TMRC30323" "TMRC30319" "TMRC30325" "TMRC30327"
## [13] "TMRC30312" "TMRC30300" "TMRC30304" "TMRC30302" "TMRC30313" "TMRC30309"
## [19] "TMRC30292" "TMRC30331" "TMRC30332" "TMRC30330"
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
## Warning in fortify(data, ...): Arguments in `...` must be used.
## x Problematic argument:
## * colour = colors
## i Did you misspell an argument name?
## 175550 entries are 0. We are on a log scale, adding 1 to the data.
## Naively calculating coefficient of variation/dispersion with respect to condition.
## Finished calculating dispersion estimates.
## `geom_smooth()` using formula = 'y ~ x'This dataset does not support lmer with condition+batch
## Removing 0 low-count genes (8778 remaining).
## transform_counts: Found 175550 values equal to 0, adding 1 to the matrix.
## `geom_smooth()` using formula = 'y ~ x'The factor none has 8 rows.
## The factor z2.2 has 29 rows.
## The factor z2.3 has 29 rows.
## The samples (and read coverage) removed when filtering 2500 non-zero genes are:
## TMRC30066 TMRC30117 TMRC30244 TMRC30246 TMRC30266 TMRC30268 TMRC30326 TMRC30323
## 3080 1147 1662 2834 822 3444 375 84
## TMRC30319 TMRC30325 TMRC30327 TMRC30312 TMRC30304 TMRC30313 TMRC30309 TMRC30330
## 374 356 129 76 289 96 188 181
## TMRC30066 TMRC30117 TMRC30244 TMRC30246 TMRC30266 TMRC30268 TMRC30326 TMRC30323
## 1890 888 1135 1796 649 1915 303 74
## TMRC30319 TMRC30325 TMRC30327 TMRC30312 TMRC30304 TMRC30313 TMRC30309 TMRC30330
## 270 279 123 76 207 84 166 135
## Samples removed: 1890, 888, 1135, 1796, 649, 1915, 303, 74, 270, 279, 123, 76, 207, 84, 166, 135
## semantic_filter(semantic = c("amastin", "gp63", "leishmanolysin"),
## semantic_column = "annot_gene_product")
data_structures <- c(data_structures, "lp_macrophage", "lp_macrophage_filt")
filt_written <- write_se(lp_macrophage_filt,
excel = glue("analyses/macrophage_de/{ver}/read_counts/lp_macrophage_reads_filtered-v{ver}.xlsx"))## Writing the first sheet, containing a legend and some summary data.
## Warning in as.data.frame.DataFrame(pData(se), strinsAsFactors = FALSE):
## arguments in '...' ignored
## The following samples have less than 5705.7 genes.
## [1] "TMRC30249" "TMRC30300" "TMRC30302" "TMRC30292" "TMRC30331" "TMRC30332"
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
## Warning in fortify(data, ...): Arguments in `...` must be used.
## x Problematic argument:
## * colour = colors
## i Did you misspell an argument name?
## 45092 entries are 0. We are on a log scale, adding 1 to the data.
## Naively calculating coefficient of variation/dispersion with respect to condition.
## Finished calculating dispersion estimates.
## `geom_smooth()` using formula = 'y ~ x'Removing 0 low-count genes (8778 remaining).
## transform_counts: Found 45092 values equal to 0, adding 1 to the matrix.
## `geom_smooth()` using formula = 'y ~ x'The factor z2.2 has 21 rows.
## The factor z2.3 has 29 rows.
lp_macrophage <- lp_macrophage_filt
lp_macrophage_nosb <- subset_se(lp_macrophage, subset = "batch!='inf_sb'")
lp_nosb_write <- write_se(
lp_macrophage_nosb,
excel = glue("analyses/macrophage_de/{ver}/read_counts/lp_macrophage_nosb_reads-v{ver}.xlsx"))## Writing the first sheet, containing a legend and some summary data.
## Warning in as.data.frame.DataFrame(pData(se), strinsAsFactors = FALSE):
## arguments in '...' ignored
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.
## Scale for fill is already present.
## Adding another scale for fill, which will replace the existing scale.
## Warning in fortify(data, ...): Arguments in `...` must be used.
## x Problematic argument:
## * colour = colors
## i Did you misspell an argument name?
## 6545 entries are 0. We are on a log scale, adding 1 to the data.
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## i Please use tidy evaluation idioms with `aes()`.
## i See also `vignette("ggplot2-in-packages")` for more information.
## i The deprecated feature was likely used in the directlabels package.
## Please report the issue at <https://github.com/tdhock/directlabels/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## Naively calculating coefficient of variation/dispersion with respect to condition.
## Finished calculating dispersion estimates.
## `geom_smooth()` using formula = 'y ~ x'The dataset has a minimal or missing set of conditions/batches.
## Removing 120 low-count genes (8658 remaining).
## transform_counts: Found 3286 values equal to 0, adding 1 to the matrix.
## `geom_smooth()` using formula = 'y ~ x'The factor z2.2 has 14 rows.
## The factor z2.3 has 15 rows.
lp_meta <- colData(lp_macrophage)
lp_meta[["slvsreads_log"]] <- log10(lp_meta[["slvsreads"]])
inf_values <- is.infinite(lp_meta[["slvsreads_log"]])
lp_meta[inf_values, "slvsreads_log"] <- -10
color_vector <- as.character(color_choices[["strain"]])
names(color_vector) <- names(color_choices[["strain"]])
color_vector <- color_vector[c("z2.2", "z2.3", "unknown")]
names(color_vector) <- c("z2.2", "z2.3", "none")
sl_violin <- ggplot(lp_meta,
aes(x = .data[["condition"]], y = .data[["slvsreads_log"]],
fill = .data[["condition"]])) +
geom_violin() +
geom_point() +
scale_fill_manual(values = color_vector)
sl_violinI want to make an estimate of ploidy using transcriptomic data. This is by definition a foold’s errand, but I think it might work.
lp_rpkm <- normalize(lp_se, convert = "rpkm", filter = TRUE,
length_column = "annot_cds_length", na_to_zero = TRUE)## Removing 149 low-count genes (8629 remaining).
## Error in hpgl_rpkm(count_table, annotations = annotations, length_column = length_column, : There is no column, annot_cds_length, unable to make a width column.
## Exclude scaffolds
unwanted <- grepl(pattern = "SCAF", x = rowData(lp_rpkm)[["annot_gene_location_text"]])## Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'grepl': error in evaluating the argument 'x' in selecting a method for function 'rowData': object 'lp_rpkm' not found
## Error: object 'lp_rpkm' not found
## Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'as.data.frame': error in evaluating the argument 'x' in selecting a method for function 'assay': object 'lp_wanted' not found
## Error: object 'summary_df' not found
## Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'rowData': object 'lp_wanted' not found
## Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'as.factor': object 'summary_df' not found
## Error: object 'summary_df' not found
summary_df <- summary_df[, c("gene_mean", "chromosome")] %>%
group_by(chromosome) %>%
summarize(chr_mean = mean(gene_mean, na.rm = TRUE))## Error: object 'summary_df' not found
## Error: object 'summary_df' not found
## Error: object 'summary_df' not found
## Error: object 'summary_df' not found
wanted <- colData(lp_wanted)[["knnv2classification"]] == "z22" | colData(lp_wanted)[["knnv2classification"]] == "z23"## Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'colData': object 'lp_wanted' not found
## Error: object 'lp_wanted' not found
## Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'colData': object 'lp_z' not found
## Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'colData': object 'lp_z' not found
## Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'as.data.frame': error in evaluating the argument 'x' in selecting a method for function 'assay': object 'lp_z' not found
## Error: object 'lp_z_assay' not found
## Error: object 'lp_z_assay' not found
## Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'rowData': object 'lp_z' not found
lp_z_means <- lp_z_assay[, c("z22_gene_mean", "z23_gene_mean", "chromosome")] %>%
group_by(chromosome) %>%
summarize(z22_mean = mean(z22_gene_mean, na.rm = TRUE),
z23_mean = mean(z23_gene_mean, na.rm = TRUE))## Error: object 'lp_z_assay' not found
## Error: object 'lp_z_means' not found
chr_reshaped[["chromosome"]] <- factor(chr_reshaped[["chromosome"]],
levels = c(as.character(1:19), "20.1", "20.2",
as.character(21:35)))## Error: object 'chr_reshaped' not found
putative_aneuploid <- ggplot(chr_reshaped, aes(x = value, y = chromosome)) +
geom_bar(aes(fill = variable), position = "dodge", stat = "identity")## Error: object 'chr_reshaped' not found
## Error: object 'putative_aneuploid' not found
## png
## 2
## Error: object 'putative_aneuploid' not found
found_idx <- data_structures %in% ls()
if (sum(!found_idx) > 0) {
not_found <- data_structures[!found_idx]
warning("Some datastructures were not generated: ", toString(not_found), ".")
data_structures <- data_structures[found_idx]
}## Warning: Some datastructures were not generated: lp_lengths, meta.
## Warning: Your system is mis-configured: '/etc/localtime' is not a symlink
## Warning: It is strongly recommended to set envionment variable TZ to
## 'America/New_York' (or equivalent)
R version 4.5.0 (2025-04-11)
Platform: x86_64-pc-linux-gnu
locale: C
attached base packages: stats4, stats, graphics, grDevices, utils, datasets, methods and base
other attached packages: ruv(v.0.9.7.1), BiocParallel(v.1.42.1), variancePartition(v.1.38.1), BSGenome.Leishmania.panamensis.MHOMCOL81L13.v68(v.2024.09), BSgenome(v.1.76.0), rtracklayer(v.1.68.0), BiocIO(v.1.18.0), Biostrings(v.2.76.0), XVector(v.0.48.0), GenomicRanges(v.1.60.0), GenomeInfoDb(v.1.44.2), org.Lpanamensis.MHOMCOL81L13.v68.eg.db(v.2024.09), AnnotationDbi(v.1.70.0), IRanges(v.2.42.0), S4Vectors(v.0.46.0), Biobase(v.2.68.0), hpgltools(v.1.2), Heatplus(v.3.16.0), ggplot2(v.4.0.0), glue(v.1.8.0), dplyr(v.1.1.4), BiocGenerics(v.0.54.0) and generics(v.0.1.4)
loaded via a namespace (and not attached): fs(v.1.6.6), matrixStats(v.1.5.0), bitops(v.1.0-9), httr(v.1.4.7), RColorBrewer(v.1.1-3), insight(v.1.4.2), doParallel(v.1.0.17), numDeriv(v.2016.8-1.1), tools(v.4.5.0), backports(v.1.5.0), R6(v.2.6.1), statsExpressions(v.1.7.1), lazyeval(v.0.2.2), mgcv(v.1.9-3), withr(v.3.0.2), prettyunits(v.1.2.0), gridExtra(v.2.3), cli(v.3.6.5), prismatic(v.1.1.2), labeling(v.0.4.3), sass(v.0.4.10), mvtnorm(v.1.3-3), S7(v.0.2.0), readr(v.2.1.5), genefilter(v.1.90.0), pbapply(v.1.7-4), Rsamtools(v.2.24.0), yulab.utils(v.0.2.1), DOSE(v.4.2.0), R.utils(v.2.13.0), dichromat(v.2.0-0.1), limma(v.3.64.3), RSQLite(v.2.4.3), gtools(v.3.9.5), vroom(v.1.6.5), zip(v.2.3.3), GO.db(v.3.21.0), Matrix(v.1.7-3), abind(v.1.4-8), R.methodsS3(v.1.8.2), lifecycle(v.1.0.4), yaml(v.2.3.10), edgeR(v.4.6.3), SummarizedExperiment(v.1.38.1), gplots(v.3.2.0), qvalue(v.2.40.0), SparseArray(v.1.8.1), BiocFileCache(v.2.16.1), Rtsne(v.0.17), paletteer(v.1.6.0), grid(v.4.5.0), blob(v.1.2.4), promises(v.1.3.3), crayon(v.1.5.3), lattice(v.0.22-7), cowplot(v.1.2.0), GenomicFeatures(v.1.60.0), annotate(v.1.86.1), KEGGREST(v.1.48.1), zeallot(v.0.2.0), pillar(v.1.11.0), knitr(v.1.50), varhandle(v.2.0.6), fgsea(v.1.34.2), rjson(v.0.2.23), boot(v.1.3-31), corpcor(v.1.6.10), codetools(v.0.2-20), fastmatch(v.1.1-6), data.table(v.1.17.8), vctrs(v.0.6.5), png(v.0.1-8), Rdpack(v.2.6.4), gtable(v.0.3.6), rematch2(v.2.1.2), datawizard(v.1.3.0), cachem(v.1.1.0), xfun(v.0.53), openxlsx(v.4.2.8), rbibutils(v.2.3), S4Arrays(v.1.8.1), mime(v.0.13), correlation(v.0.8.8), coda(v.0.19-4.1), reformulas(v.0.4.1), survival(v.3.8-3), iterators(v.1.0.14), statmod(v.1.5.0), directlabels(v.2025.6.24), nlme(v.3.1-168), pbkrtest(v.0.5.5), bit64(v.4.6.0-1), progress(v.1.2.3), EnvStats(v.3.1.0), filelock(v.1.0.3), bslib(v.0.9.0), KernSmooth(v.2.23-26), DBI(v.1.2.3), tidyselect(v.1.2.1), bit(v.4.6.0), compiler(v.4.5.0), curl(v.7.0.0), httr2(v.1.2.1), graph(v.1.86.0), xml2(v.1.4.0), DelayedArray(v.0.34.1), plotly(v.4.11.0), bayestestR(v.0.17.0), scales(v.1.4.0), caTools(v.1.18.3), remaCor(v.0.0.20), quadprog(v.1.5-8), rappdirs(v.0.3.3), stringr(v.1.5.1), digest(v.0.6.37), ggsankey(v.0.0.99999), minqa(v.1.2.8), rmarkdown(v.2.29), aod(v.1.3.3), RhpcBLASctl(v.0.23-42), htmltools(v.0.5.8.1), pkgconfig(v.2.0.3), lme4(v.1.1-37), MatrixGenerics(v.1.20.0), dbplyr(v.2.5.0), fastmap(v.1.2.0), rlang(v.1.1.6), htmlwidgets(v.1.6.4), UCSC.utils(v.1.4.0), shiny(v.1.11.1), farver(v.2.1.2), jquerylib(v.0.1.4), jsonlite(v.2.0.0), GOSemSim(v.2.34.0), R.oo(v.1.27.1), RCurl(v.1.98-1.17), magrittr(v.2.0.4), GenomeInfoDbData(v.1.2.14), patchwork(v.1.3.2), parameters(v.0.28.2), Rcpp(v.1.1.0), stringi(v.1.8.7), MASS(v.7.3-65), plyr(v.1.8.9), parallel(v.4.5.0), ggrepel(v.0.9.6), splines(v.4.5.0), pander(v.0.6.6), hms(v.1.1.3), locfit(v.1.5-9.12), fastcluster(v.1.3.0), effectsize(v.1.0.1), reshape2(v.1.4.4), biomaRt(v.2.64.0), rstantools(v.2.5.0), XML(v.3.99-0.19), evaluate(v.1.0.4), RcppParallel(v.5.1.11-1), nloptr(v.2.2.1), tzdb(v.0.5.0), foreach(v.1.5.2), httpuv(v.1.6.16), MatrixModels(v.0.5-4), BayesFactor(v.0.9.12-4.7), tidyr(v.1.3.1), purrr(v.1.1.0), broom(v.1.0.10), xtable(v.1.8-4), restfulr(v.0.0.16), fANCOVA(v.0.6-1), later(v.1.4.3), viridisLite(v.0.4.2), tibble(v.3.3.0), lmerTest(v.3.1-3), ggstatsplot(v.0.13.3), memoise(v.2.0.1), GenomicAlignments(v.1.44.0), sva(v.3.56.0) and GSEABase(v.1.70.0)
## If you wish to reproduce this exact build of hpgltools, invoke the following:
## > git clone http://github.com/abelew/hpgltools.git
## > git reset 159b347956b8e87168310c6d2f8096e8f512c924
## This is hpgltools commit: Mon Oct 13 17:35:31 2025 -0400: 159b347956b8e87168310c6d2f8096e8f512c924
## Saving to 01datasets.rda.xz