Skip to content

Instantly share code, notes, and snippets.

@nievergeltlab
nievergeltlab / ambiguous_alleles.sh
Last active July 25, 2017 18:42
Get ambiguous alleles
#Assumes data is a table delimited .bim file
bimfile=bim_name_here
grep -P "A\tT" $bimfile > ambiguous_snps.txt
grep -P "T\tA" $bimfile >> ambiguous_snps.txt
grep -P "C\tG" $bimfile >> ambiguous_snps.txt
grep -P "G\tC" $bimfile >> ambiguous_snps.txt
#for metal
bimfile=LOOMeur_1_.results
@nievergeltlab
nievergeltlab / forest_plot
Last active February 14, 2017 20:15
Forest plot for meta-analysis in R
library(metafor)
y <- scan(what=numeric())
0.273936
0.278002
0.117789
0.170343
se <- scan(what=numeric())
0.0864617
@nievergeltlab
nievergeltlab / make_dos.pbs
Last active April 4, 2017 20:10
This makes imputed probabilities from ricopili into a dosage file format Working with job system (TORQUE). Have a list of files. Want to run same operation on all of them. Can run multiple at the same time on a single node The files to be processed are listed in a single file. The number of processes to be run on a single node are noted. The job…
#PBS -lnodes=1
#PBS -lwalltime=0:05:00
#!/bin/bash
while getopts n:o:p:d:s: option
do
case "${option}"
in
o) outputfile=${OPTARG};;
@nievergeltlab
nievergeltlab / analyze_snp_in_R.r
Last active June 29, 2021 21:12
User R to analyze a single SNP from PLINK. The SNP is analyzed using an ordered logit model, with the SNP as an outcome (usually it's done as OLS or logistic with the SNP as a predictor).
#Test the association between a SNP and PTSD, in R, assuming ordered logit of the SNP
#Do the following in PLINK
plink --bfile --snp rs4680 --recodeA --out rs4680
#Open the corresponding .raw file and note the column name for the SNP. you'll need this for R
#Then load R
R
@nievergeltlab
nievergeltlab / qq_plot.pbs
Last active November 2, 2017 18:44
QQ plot function. v2 reads data using the data.table library
#!/bin/bash
while getopts s:i:o:e: option
do
case "${option}"
in
s) scriptname=${OPTARG};;
i) indata=${OPTARG};;
o) outdata=${OPTARG};;
e) errorbars=${OPTARG};;
@nievergeltlab
nievergeltlab / manhattan_plot.r
Last active May 1, 2017 18:51
Manhattan Plots V2 of the plotter will color SNPs within a set kb window of any hits
args <- commandArgs(trailingOnly = TRUE)
scriptloc <- args[1]
results <- args[2]
outfile <- args[3]
snpcol <- args[4]
chrcol <- args[5]
bpcol <- args[6]
pcol <- args[7]
@nievergeltlab
nievergeltlab / name_chromosome_chunk.sh
Created March 13, 2017 16:18
Get chromosome number and chunk number from file name. For ricopili.
chunknum=$(echo $chunk | sed 's/.*\(chr[0-9]*_[0-9]*_[0-9]*\).*/\1/')
chrnum=$(echo $chunk | sed 's/.*\(chr[0-9]*\).*/\1/')
@nievergeltlab
nievergeltlab / ibd_compare
Created March 22, 2017 22:08
2 file IBD, if strand mismatches and allele mismatches
bimfile=pts_meg2_mix_am-qc.bim
grep -P "A\tT" $bimfile > ambiguous_snps.txt
grep -P "T\tA" $bimfile >> ambiguous_snps.txt
grep -P "C\tG" $bimfile >> ambiguous_snps.txt
grep -P "G\tC" $bimfile >> ambiguous_snps.txt
#filer out ambiguous
$plink_location --bfile pts_meg2_mix_am-qc --exclude ambiguous_snps.txt --make-bed --out pts_meg2_mix_am-qc-ambig
@nievergeltlab
nievergeltlab / analyze_dosages.pbs
Last active April 4, 2017 19:59
Analyze dosages data from Ricopili
#PBS -lnodes=1
#PBS -lwalltime=0:05:00
#!/bin/bash
while getopts a:b:o:p:d: option
do
case "${option}"
in
a) phenotype=${OPTARG};;
@nievergeltlab
nievergeltlab / extract_snp_from_dosages
Created March 24, 2017 18:23
Algorithm: Find which file the SNP is in, then zgrep the SNP out. This script will output a .dosage file for each snp in the list. to combine them into a file, it's of course just a matter of using "cat"
#Requires a list of SNPs written into snplist.txt
dosage_directory=write_path_to_dosage_files_here
for snp in $(cat snplist.txt)
do
filename=$(grep -w -m1 -l $snp "$dosage_directory"/*.map | sed 's/.map/.gz/g' )
zgrep -w -m1 $snp $filename > "$snp".dosage
done