Skip to content

Instantly share code, notes, and snippets.

View ATpoint's full-sized avatar

Alexander Bender ATpoint

View GitHub Profile
@ATpoint
ATpoint / getPercentExpressed.R
Last active April 28, 2023 12:18
Calculate percentage of cells per group expressing the genes in a numeric matrix
# 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")
library(DESeq2)
#/ from https://raw.githubusercontent.com/shangguandong1996/picture_link/main/WFX_count_Rmatrix.txt
data <- read.delim("WFX_count_Rmatrix.txt", row.names = "Geneid")
get_res <- function(dds){
dds <- DESeq(dds)
res <- results(dds, name=resultsNames(dds)[2])
lfcShrink(dds, coef=resultsNames(dds)[2], res=res, type="ashr")
}
$ make
mkdir -p objs
g++ -std=c++11 -Wall -O3 -fopenmp -march=native -c src/chromap.cc -o objs/chromap.o -lm -lz
src/chromap.cc:1096:0: warning: ignoring #pragma omp taskloop [-Wunknown-pragmas]
#pragma omp taskloop grainsize(grain_size) //num_tasks(num_threads_* 50)
^
src/chromap.cc:2001:0: warning: ignoring #pragma omp taskloop [-Wunknown-pragmas]
#pragma omp taskloop num_tasks(num_threads_* num_threads_)
^
src/chromap.cc: In instantiation of 'void chromap::Chromap<MappingRecord>::MapSingleEndReads() [with MappingRecord = chromap::PAFMapping]':
@ATpoint
ATpoint / stdout_problem.nf
Last active June 8, 2021 19:41
Problem: .nextflow.out piles up the entire stdout channel, feels like it should not do that when output is explicitely stdout
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
// Dummy example: Decompress a BAM in processA => stdout => read in processB as stdin and compress back to BAM.
process processA {
input:
path(bam)
$ head renv.lock -n 40
{
"R": {
"Version": "4.0.3",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cran.rstudio.com"
}
]
library(recount)
library(edgeR)
#/ Get the counts from GTEx via recount as a SummarizedExperiment
#/ => 1.3GB file
options(timeout=600)
download_study("SRP012682", type = "rse-gene")
load(file.path("SRP012682", "rse_gene.Rdata"))
#/ remove whitespaces in tissue names:
FATAL: container creation failed: unable to copy files to container fs: while copying [environment.yml] to /tmp/rootfs-4b4c7b49-9f72-11eb-a808-12cf446d2005/environment.yml: exit status 1: /bin/cp: cannot stat 'environment.yml': No such file or directory
FATAL: While performing build: while running engine: while running /usr/local/libexec/singularity/bin/starter: exit status 255
FATAL: While performing build: build image size <= 0
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
@ATpoint
ATpoint / guides_angles.R
Last active September 24, 2021 10:35
No more messing with h/vjust when rotating labels
library(ggplot2)
library(reshape2)
library(egg)
# thanks to https://stackoverflow.com/questions/1330989/rotating-and-spacing-axis-labels-in-ggplot2/60650595#60650595
dat<-reshape2::melt(data.frame(groupA=rnorm(20),
groupB=rnorm(20),
groupC=rnorm(20)))
metaBigBam.c:485:12: warning: 'cigar_tab' is deprecated: Use bam_cigar_table[] instead [-Wdeprecated-declarations]
if (h->cigar_tab == 0)
^
/usr/local/include/htslib/sam.h:75:29: note: 'cigar_tab' has been explicitly marked deprecated here
const int8_t *cigar_tab HTS_DEPRECATED("Use bam_cigar_table[] instead");
^
/usr/local/include/htslib/hts_defs.h:75:49: note: expanded from macro 'HTS_DEPRECATED'
#define HTS_DEPRECATED(message) __attribute__ ((__deprecated__ (message)))
^
metaBigBam.c:487:5: warning: 'cigar_tab' is deprecated: Use bam_cigar_table[] instead [-Wdeprecated-declarations]