Skip to content

Instantly share code, notes, and snippets.

@nievergeltlab
nievergeltlab / cpg_correlation
Created July 17, 2019 20:51
Going over a user specified moving window, take the correlation between CpG sites within the window, report the ones with abs ( r ) > given cutoff.
library(Hmisc)
library(data.table)
cormethod="pearson"
windowsize=300000 #
windowjump=10000 #Jump over this increment for correlation analysis
minR=0.6 #minimum correlation to report
#GeMes https://www.cell.com/ajhg/pdfExtended/S0002-9297(14)00069-X
#http://www.sthda.com/english/wiki/correlation-matrix-a-quick-start-guide-to-analyze-format-and-visualize-a-correlation-matrix-using-r-software
flattenCorrMatrix <- function(cormat, pmat) {
for chr in 10 # X # 2 6 11 # {7..20} # {2..20} # {1..20} #22 # {1..8} # {1..22} X MT XY Y
do
echo $chr
date
mkdir temporary_files/chr"$chr"_baf1
mkdir temporary_files/chr"$chr"_baf2
mkdir temporary_files/chr"$chr"_baf3
mkdir temporary_files/chr"$chr"_baf4
mkdir temporary_files/chr"$chr"_l2r1
#!/usr/bin/env python
import math
########################################################
# plink2metasoft.py
# Convert Plink .assoc files to Metasoft input file
# Free license -- you are free to use it in any ways
# Buhm Han (2012)
########################################################
import sys, subprocess, os
@nievergeltlab
nievergeltlab / tin_gwas1
Last active January 10, 2023 18:21
sample code for running BOLTLmm
BOLT-LMM_v2.3.2/bolt \
--bed=pca/UKB_tinnitus_eur_unrelated_{1..22}.bed \
--bim=pca/UKB_tinnitus_eur_unrelated_{1..22}.bim \
--fam=pca/UKB_tinnitus_eur_unrelated_1.fam \
--LDscoresFile=BOLT-LMM_v2.3.2/tables/LDSCORE.1000G_EUR.tab.gz \
--geneticMapFile=BOLT-LMM_v2.3.2/tables/genetic_map_hg19_withX.txt.gz \
--lmmForceNonInf \
--numThreads=6 \
--bgenFile=/mnt/ukbb/adam/bgen/ukb_imp_chr{1..22}_v3.bgen \
--bgenMinMAF=1e-3 \
nsub=30000
nr=nsub
ncol=nsub
dummy_datamatrix <- data.frame(pc1=rnorm(nsub), pc2=rnorm(nsub),studytype=round(runif(nsub)))
distmat <- matrix(rnorm(nsub^2),ncol=nsub,nrow=nsub)
library(vegan)
@nievergeltlab
nievergeltlab / lanc_simulation_v5_loopsims2.txt
Last active June 29, 2021 19:14
Power analysis for Tractor method
args <- commandArgs(TRUE)
parmfile <- args[1]
linestart <- args[2]
linestop <- args[3]
run_no <- args[4]
library(lmtest)
nrep=100 #Number of simulation repetitions per parameter set
for chr in {1..22}
do
for pwd in $(cat /mnt/sdb/genetics/hrv_2/umichpwds.txt) #supply a file with umich password, i can never keep track of these
do
echo $pwd
unzip -P $pwd chr_"$chr".zip
done
#rm chr_"$chr".zip
done
@nievergeltlab
nievergeltlab / summarize_p2.r
Created January 17, 2019 22:20
For a P2 level phenotype, get descriptive information
args = commandArgs(trailingOnly=TRUE)
#Rscript p2_phenocode.r mrsc > test.txt
study <- args[1]
#study='mrsc'
library(psych)
dat <- read.csv(paste(study,'_p2.csv',sep=''),stringsAsFactors=F,header=T,na.strings=c(NA,"#N/A","-9"))
@nievergeltlab
nievergeltlab / prepare_data_hrc.sh
Last active November 30, 2018 19:24
Reformat PLINK data to VCF to be loaded in VCF
# Will Rayner provides a great toolbox to prepare data: HRC or 1000G Pre-imputation Checks.
# The main steps for HRC are:
# Download tool and sites
#wget http://www.well.ox.ac.uk/~wrayner/tools/HRC-1000G-check-bim-v4.2.7.zip
#wget ftp://ngs.sanger.ac.uk/production/hrc/HRC.r1-1/HRC.r1-1.GRCh37.wgs.mac5.sites.tab.gz
# Convert ped/map to bed
##Part 1: If final report is not split into 1 subject per file, this will split it up. Otherwise don't run this part!
#User: List name of final report file here
final_report=Akesogen_Cohen_FC_CNV_V.1_FinalReport.txt
#Creates a header
head -n10 $final_report > header.txt
#Column $1 is the default here, but the number should correspond to whatever number the subjects are named in
awk 'NR>10{print >$1}' $final_report