View realign_bam.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://lh3.github.io/2021/07/06/remapping-an-aligned-bam | |
samtools collate -Oun128 in.bam | samtools fastq -OT RG,BC - \ | |
| bwa mem -pt8 -CH <(samtools view -H in.bam|grep ^@RG) ref.fa - \ | |
| samtools sort -@4 -m4g -o out.bam - |
View get_header_and_combine.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get header from first file and drop it from other files | |
awk 'NR == FNR || FNR > 1' *.tsv > ${output_file} | |
# Add a column for filename and filename column | |
awk -v OFS='\t' 'NR == FNR { print \$0, 'filename' } FNR > 1 { print \$0, FILENAME }' |
View fix_bam_index.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This quick script will check for big differences in a bams index and creation date and perform indexing. | |
for i in *.bam; do | |
bam=${i} | |
bai=${i}.bai | |
bam_date=$(stat -c %Y ${bam}) | |
bai_date=$(stat -c %Y ${bai}) | |
diff=`expr ${bam_date} - ${bai_date}` | |
if [ ${diff} -gt 100000 ]; then | |
echo "${bam} ${diff}"; | |
sbatch --job-name=${bam} --partition=cpu --time=3:00:00 --cpus-per-task=32 --wrap "samtools index -@ 32 ${bam}" |
View split_bed.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function split_bed() { | |
# This function will split a bed file by chromosome and chunk_size=1000 | |
# In other words, split files will only possess one chromosome max. | |
# File sizes may be variable. | |
awk -v chunk_size=1000 'NR == 1 { chrom=$1; iter=0; fname_iter=0; print chrom } | |
{ | |
if(chrom == $1 && iter <= chunk_size) { | |
print > sprintf("x%04d_%s.segment.txt", fname_iter, $1); | |
iter++; | |
} else { |
View resolve_symbolic.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resolve-symbolic-link() { | |
if [ -L $1 ]; then | |
temp="$(readlink "$1")"; | |
rm -rf "$1"; | |
cp -rf "$temp" "$1"; | |
fi | |
} |
View node.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function node() { | |
# Usage: | |
# node ca015 | |
# ssh into node and go to current directory | |
ssh -t ${1} "cd ${PWD}; bash" | |
} |
View setup_script.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
error() { | |
>&2 echo -e "\n\t$(tput setaf 1)${1}$(tput sgr0)\n" | |
exit 1 | |
} | |
msg() { | |
>&2 echo -e "$(tput setaf 3)${1}$(tput sgr0)" | |
} |
View vectorize.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ITEMS <- vectorize(" | |
# a | |
# b | |
# c | |
# ") | |
vectorize <- function(x) { | |
x <- strsplit(x, "\n")[[1]] | |
x[!is.na(x) & x != ""] | |
} |
View parse_format.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parse_format_column <- | |
df[, .(rbindlist( | |
purrr::map2( | |
strsplit(vcf_format, ":", fixed=TRUE), | |
strsplit(vcf_gt, ":", fixed=TRUE), | |
function(x, y) { names(y) <- x; data.table(t(y)) } | |
) | |
) | |
), | |
] |
View stop_containers.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker stop $(docker ps -a -q) | |
docker rm $(docker ps -a -q) |
NewerOlder