This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Read loom files into R as CsparseMatrix, depending on Matrix and hdf5r | |
#' @param path to file loom file on disk | |
#' @param include.ambiguous logical, whether to also read the "ambiguous" counts from velocyto, default FALSE | |
#' | |
readLoomMatrices <- function(file, include.ambiguous=FALSE) { | |
require(Matrix) | |
require(hdf5r) | |
engine='hdf5r' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
title: "https://www.biostars.org/p/461026/" | |
author: "ATpoint" | |
output: html_document | |
--- | |
# Load data | |
```{r loadData} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# BundleAndValidate <FOLDER_TO_BUNDLE> <tar/tarReplaceLink/zip> <Destination> | |
# | |
# Tar a folder and validate integrity of the tarball. For this, compare the file listing of the input folder | |
# with the file listing of the tarball via md5sum. If identical assume tarball is fine. | |
# Option tar makes a tarball, tarReplacelink uses tar -h to replace links with pointing file and zip makes a zipball. | |
# Don't be surprised that it can take some time before you see the tarball at destination after submitting the job. | |
# The first step is a full listing of the origin file, and with many folders and files that can take a while. | |
# Uses mbuffer internally to buffer incoming tar stream. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Create unique combinations | |
#' | |
#' To a given vector of numeric values add or subtract a constant value, | |
#' and return all possible combinations of that as a matrix | |
#' | |
#' @param values a vector with numeri values | |
#' @param change_value a numeric value too add or subtract | |
#' | |
#' @details | |
#' There are 2^length(values) possible combinations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
reprex::reprex({ | |
d <- data.frame(a=1) | |
# Works | |
suppressMessages({library(AnnotationDbi); library(dplyr)}) | |
d %>% select(a) | |
detach("package:AnnotationDbi", unload=TRUE) | |
detach("package:dplyr", unload=TRUE) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Retrieve REACTOME terms for human directly from the website, then map to mouse. | |
# Pull human to mouse mappings via biomaRt. | |
library(biomaRt) | |
library(data.table) | |
library(magrittr) | |
library(rtracklayer) | |
library(tidyverse) | |
options(timeout=999) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(biomaRt) | |
library(data.table) | |
library(dplyr) | |
library(magrittr) | |
kegg <- sapply(c("mouse", "human"), function(x){ | |
if(x=="mouse"){ | |
dataset <- "mmusculus_gene_ensembl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Murine peripheral blood cell numbers based on: | |
# https://www.stemcell.com/media/files/wallchart/WA10011-Frequencies_Percentages_Mouse_Immune_Cell_Types.pdf | |
library(magrittr) | |
library(patchwork) | |
library(tidyverse) | |
options(ggplot2.discrete.fill=c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", | |
"#0072B2", "#D55E00", "#CC79A7")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Given a matrix-like object with genes being rows and samples being columns, | |
# and a group information for the columns, calculate the percentage of columns per group | |
# that have counts > threshold per gene. Efficiently done via base R, compatible with dgCMatrix. | |
# data <- data.frame(A=c(1,1,0,0), B=c(1,0,0,0), C=c(1,0,0,0)) | |
# group <- as.character(c(1,1,2)) | |
get_pexpr <- function(data, group, threshold=0, digits=2){ | |
if(ncol(data)!=length(group)) stop("ncol(data) != length(group)") | |
if(!is.numeric(threshold) | threshold < 0) stop("threshold must be numeric and > 0") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Take output of UCell::ScoreSignatures_UCell() and return a vector of labels with highest score. | |
#' If the highest score per row is unique (only one value is the highest value) return that label. | |
#' If all scores are zero return "NA". | |
#' If more than one value is the highest value return "ambiguous". | |
#' library(UCell) | |
#' data(sample.matrix) | |
#' gene.sets <- list(Tcell_signature = c("CD2","CD3E","CD3D"), | |
#' Myeloid_signature = c("SPI1","FCER1G","CSF1R")) | |
#' scores <- ScoreSignatures_UCell(sample.matrix, features=gene.sets) | |
#' convertUCell(scores) |
NewerOlder