Skip to content

Instantly share code, notes, and snippets.

@nievergeltlab
nievergeltlab / filecomp.txt
Created November 29, 2018 21:35
Compare two directories to reconcile them
src='/run/media/genetics/pgc_ptsd/broad/gracy' # Source directory
dst='/run/media/root/_gen/pts1/gracy' # Destination directory
icp() {
f="${1}";
[ -d "$f" ] && {
[ ! -d "${dst}${f#$src}" ] && mkdir -p "${dst}${f#$src}";
return
}
@nievergeltlab
nievergeltlab / 01_get_mafs.sh
Created November 2, 2018 18:01
It is useful to have markers with MAF >1% in a given 1000G population, for filtering of combined genotype data, LDAK, etc.
#List 1000g Europeans
awk '{if ($3 == "EUR") print $1}' integrated_call_samples_v3.20130502.ALL.panel > 1000g_europeans.subjects
for i in 22 # {1..22}
do
vcf-subset -c 1000g_europeans.subjects ALL.chr"$i".phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz | fill-an-ac | gzip -c > CEU.chr"$i".phase1.vcf.gz
done
#Get marker info for all markers. Only take rs markers that are di-allelic
for i in {1..22}
@nievergeltlab
nievergeltlab / 01_popcorn.sh
Created October 31, 2018 16:38
Analyze data with Popcorn. Requires 1000G data.
#Convert all 1000g data to plink binary
for chr in {1..22}
do
plink2 --vcf 1000g/ALL.chr"$chr".phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz --keep 1000g_eur.ref2 --make-bed --out 1000g/1000geur_chr"$chr"
plink2 --vcf 1000g/ALL.chr"$chr".phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz --keep 1000g_afr.ref2 --make-bed --out 1000g/1000gafr_chr"$chr"
done
@nievergeltlab
nievergeltlab / compare_hrc_gwas.sh
Created October 31, 2018 16:36
Look up top associations from GWAS in a GWAS of HRC data
awk '{print $1"_"$2, $1"_"$2,$6}' pts_mrsc_mix_am-qc.fam > mrsc.pheno
awk '{print $1"_"$2, $1"_"$2,$4,$5,$6,$7,$8}' pts_mrsc_mix_am-qc-eur_pca.menv.mds_cov > mrsc.cov
awk '{print $1"_"$2, $1"_"$2,$4,$5,$6,$7,$8}' pts_mrsc_mix_am-qc-aam_pca.menv.mds_cov > mrscA.cov
zcat chr1.dose.vcf.gz | head -n 100000 | gzip > chr1.abbr.dose.vcf.gz
/mnt/sdb/genetics/tiff1/hrc_impute/plink --vcf chr1.dose.vcf.gz --hide-covar --pheno mrsc.pheno --allow-no-sex --covar mrsc.cov --double-id --logistic --ci 0.95 --out mrsc_chr1
#Compare to gwas results
zcat daner_mrsc_eur_analysis_run3.gz | grep -v NA | awk '{if (NR == 1 || $1 == "1") print}' | sort -g -k 11 > chr1_eur.out
@nievergeltlab
nievergeltlab / imputedhaps.sh
Last active June 29, 2021 21:11
I needed to impute haplotypes to obtain phased haplotypes, to perform the local ancestry analysis. Imputation results otherwise did not give me phased data because I didn't retain that info. So I redid it
wd=/home/maihofer/haps/
cd $wd
#Datasets that have (x) or need (y) to rephase haplotype data
# safr y
# mrsc y
# dnhs y
# gsdc y
# fscd y
# nss1 y
@nievergeltlab
nievergeltlab / plate matrix.txt
Created October 31, 2018 16:11
given a plating matrix, unwrap it, then perform association testing
Case Prep 65 CEPHDNA Crtl Post 31 Case Prep 29 Ctrl Prep 42 Case Post 64 Case Post 83 Ctrl Prep 75 Case Prep 85 Ctrl Post 81 Ctrl Post 116 Case Prep 107
Case Post 65 Ctrl Prep 179 Ctrl Prep 31 Case Post 29 Ctrl Post 42 Case Prep 64 Case Prep 83 Ctrl Post 75 Case Post 85 Ctrl Prep 81 Ctrl Prep 116 Case Post 107
Ctrl Post 28 Case Prep 72 Ctrl Prep 37 Case Post 93 Case Post 48 Ctrl Prep 56 Case Prep 49 Ctrl Post 66 Ctrl Post 68 Case Prep 95 Case Prep 104 Ctrl Post 136
Ctrl Prep 28 Case Post 72 Ctrl Post 37 Case Prep 93 Case Prep 48 Ctrl Post 56 Case Post 49 Ctrl Prep 66 Ctrl Prep 68 Case Post 95 Case Post 104 Ctrl Prep 136
Ctrl Prep 185 Case Post 90 Case Post 74 Ctrl Prep 39 Case Prep 77 Ctrl Post 60 Ctrl Post 58 Case Prep 87 Ctrl Prep 1 Case Post 97 Case Post 102 Ctrl Prep 73
Ctrl Post 185 Case Prep 90 Case Prep 74 Ctrl Post 39 Case Post 77 Ctrl Prep 60 Ctrl Prep 58 Case Post 87 Ctrl Post 1 Case Prep 97 Case Prep 102 Ctrl Post 73
Case Post 69 Ctrl Prep 35 Case Prep 215 Ctrl Post 41 Ctrl Post 54 Case Prep 78 Ctr
@nievergeltlab
nievergeltlab / affiliations.r
Created October 31, 2018 15:54
Assign numbers after author names for affiliations
#Note according to Katy format: Anyone with value "5-all others" is alphabetically ordered by last name.
#!!! ASSUMING THAT DATA HAS BEEN DOUBLE SORTED BY "Paper order" and "Published Name" !!!
dat_ordered <- read.csv('affiliations_Freeze2.csv',stringsAsFactors=F,header=T)
#Generate single variable for affiliations, easily to work with..
dat_ordered$Afone <- paste(dat_ordered$Institution..EDITED.,dat_ordered$Department..EDITED.,dat_ordered$City,dat_ordered$State,dat_ordered$Country,sep=". ")
dat_ordered$Afone <- sapply(dat_ordered$Afone, gsub, pattern='\xa0', replacement=" " )
@nievergeltlab
nievergeltlab / lanc_simulation_v5_mafdif.txt
Last active June 29, 2021 19:14
Simulation of power for local ancestry analysis
args <- commandArgs(TRUE)
scriptno <- args[1]
scriptno <- as.numeric(scriptno)
ncore=7 #Assume that node has this many cores
Ngroups=1
fineness=.005
efseq1 <- seq(1.05,1.3,by=fineness)
@nievergeltlab
nievergeltlab / 00_cluster_geno.r
Created September 21, 2018 16:55
IBD for methylation samples
impute_median <- function(x)
{
med <- median(x,na.rm=T)
x[is.na(x)] <- med
return(x)
}
##Read in a .csv file consisting of Barfield CpGs, one row per CpG, one column per sample.
d1 <- read.csv('MRS_Long_barfieldProbes.csv',header=T,nr=20000)
d1$CpG <- d1$X
@nievergeltlab
nievergeltlab / cnv_filename
Created September 5, 2018 16:33
CNV files don't have the name as the actual ID, this extracts the id from the file and lists the filename and id next to eachother. A couple of other functions are in here as well.
#list all files, make folder for each
ls * | grep .idat | awk 'BEGIN{FS="_"}{print $1}' | sort -u > folderlist.txt
for folders in $(cat folderlist.txt)
do
mkdir $folders
done