Skip to content

Instantly share code, notes, and snippets.

View GabrielHoffman's full-sized avatar

Gabriel Hoffman GabrielHoffman

View GitHub Profile
@GabrielHoffman
GabrielHoffman / PheCodes_with_edgeR.R
Last active February 2, 2021 18:03
PheCodes with edgeR
# PheCode analysis with NB regression and edgeR
library(MASS)
# Analysis of 1 phenotype
#########################
# number of individuals
n = 100
@GabrielHoffman
GabrielHoffman / GTEx_cellCulture.R
Last active February 2, 2021 23:52
Combine GREx and cell culture scores into 1 set of scores
# Gabriel Hoffman
# Feb 2 , 2021
#
# Combine GREx and cell culture scores into 1 set of scores
library(ggrepel)
library(ggplot2)
df = read.csv("shRNA.All.fdr.EpiXcan.vs.TWAS_joint_statistic_all.csv")
# Gabriel Hoffman
# Feb 11, 2021
# Plot and compare two curves
library(data.table)
library(ggplot2)
# simulate data
set.seed(1)
n = 10000
@GabrielHoffman
GabrielHoffman / fast_file_loading.R
Created February 17, 2021 20:39
Accelerating loading large results files in R
# Gabriel Hoffman
# Feb 17, 2021
#
# Accelerating loading large results files in R
# Using data.table::fread() with a commandline pipe
# and awk to filter rows is the fastest and uses least memory
# Here are empirical results for 1.4 Gb gzip'd eQTL results file
# Performance will depend on filtering
# modules based on https://github.com/genomely/RAPiD-nf/blob/85fa4c1e4e3ffb8d2e7bdce368318b5c688f415b/config/chimera.config#L276
# versions based on https://github.com/genomely/RAPiD-nf/blob/85fa4c1e4e3ffb8d2e7bdce368318b5c688f415b/config/chimera.config#L70
ml python/2.7.17 samtools/1.11 bcftools/1.10.2
# Set variable
export NGSCHECKMATE=/sc/arion/projects/H_PBG/scripts/NGSCheckMate
# move to temp directory
cd /hpc/users/hoffmg01/work/test/ngs
# 95% confidence intervals for fractions
library(binom)
Same = 95
Total = 100
res = binom.confint(Same, Total, method="exact")
res[,c('n','mean', 'lower', 'upper')]
# create regression coefficents and standard errors
beta1 = .5
se1 = .1
beta2 = .2
se2 = .09
# t-statistic for comparing the beta values
# Since beta1 and beta2 are independent,
# var(beta1 - beta2) = var(beta1) + var(beta2)
library(variancePartition)
library(Rfast)
library(Matrix)
final.everything <- readRDS("/sc/arion/projects/psychgen2/lbp/data/RAW/rna/bulk/fromSema4/CompiledData/lbp_allBatches_RAPiD_Metadata_21JUL2021.RDS")
metadata <- final.everything$covariates
# Simulate 10 genes
set.seed(1)
R loads packages from paths: .libPaths()
R tries to install packages into .libPaths()[1]. If you dont have access to this path, the install will fail.
You need to create a local folder to install packages to, and make it first in the search path. Add the following to your ~/.bash_profile file:
# specify a local library
R_LIBS_USER=/hpc/users/${USER}/.Rlib/R_libs/
# Make the local library first in the search path
R_LIBS=$R_LIBS_USER:$R_LIBS
# Need new version
if( packageVersion("zellkonverter") < 1.2 ){
stop("Need newer version")
}
# Reading snRNA-seq data into R with low memory usage
library(SingleCellExperiment)
library(zellkonverter)
# path to h5ad file