Skip to content

Instantly share code, notes, and snippets.

View ATpoint's full-sized avatar

Alexander Bender ATpoint

View GitHub Profile
> 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:
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
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:
$ head renv.lock -n 40
{
"R": {
"Version": "4.0.3",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cran.rstudio.com"
}
]
@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)
$ 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]':
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")
}
@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")
@ATpoint
ATpoint / biostars_461026.Rmd
Last active January 17, 2024 18:59
biostars_461026
---
title: "https://www.biostars.org/p/461026/"
author: "ATpoint"
output: html_document
---
# Load data
```{r loadData}
@ATpoint
ATpoint / colorblind.R
Created December 19, 2022 22:39
A colorblind-friendly palette including gray and black
cb <- c("#E69F00", "#0072B2", "#009E73",
"#CC79A7", "#56B4E9", "#D55E00",
"#661100", "#F0E442", "#332288",
"gray40", "black")
library(ggplot2)
ggplot(data.frame(x=c(rep(c(1,2,3), each=3), 4,4), y=1:length(l), color=LETTERS[1:length(l)]),
aes(x=x, y=y, color=color)) +
geom_point(size=10, show.legend=FALSE) +