Skip to content

Instantly share code, notes, and snippets.

@sephraim
sephraim / set_extension.rb
Created November 11, 2016 18:55
Automatically set output file extension
__F_OUT__ = __F_IN__.sub(/(\.[^.]+$)|$/, '.out')
@sephraim
sephraim / init_or_incr.rb
Last active November 12, 2016 01:18
Initialize or increment an integer variable
n = n ? n + 1 : 1
@sephraim
sephraim / mount_smb.sh
Last active November 12, 2016 01:16
Mount / unmount SMB file share on Mac OS X
# 1. Create the mount point
mkdir share_name
# 2. Mount the share
mount_smbfs //username:password@server.name/share_name share_name/
# 3. Unmount the share
umount share_name
@sephraim
sephraim / create_tar_gz.sh
Last active November 11, 2016 22:54
Create tar.gz file
tar -cvzf __OUTPUT__.tar.gz __INPUT__
@sephraim
sephraim / remove_VCF_duplicates.sh
Last active September 11, 2024 04:41
Remove duplicate variants from VCF file
#!/bin/bash
myvcf="$1"
# Print header
bcftools view -h -O v "$myvcf"
# Sort and remove duplicates per chromosome
for i in {1..22} MT X Y
do
@sephraim
sephraim / check_utils.sh
Created November 11, 2016 23:18
Check if bash utilities are installed
for util in 'awk' 'ruby' 'python' 'faketool'
do
if [ -z $(which "$util" 2> /dev/null) ]; then
echo "ERROR: $util is not in your \$PATH" >&2
exit 1
fi
done
@sephraim
sephraim / add_user.sh
Created November 11, 2016 23:56
Add new user (CentOS)
# Add user and user's full name and groups
useradd -m -c '__FULL_NAME__' -g __PRIMARY_GROUP__ -G __SECONDARY_GROUPS__ __USERNAME__
# Set user's password
passwd __USERNAME__
@sephraim
sephraim / multi_qsub_submit.sh
Last active November 12, 2016 01:05
Submit multiple qsub jobs quickly
#!/bin/bash
# Submit a job for each chromosome
# Job logs will be named __JOB_NAME__.chr1.o, __JOB_NAME__.chr2.o, etc.
for chr in {1..22} MT X Y
do
qsub -N __JOB_NAME__.chr$chr -v CHR=$chr qsub.sh
done
@sephraim
sephraim / sort_vcf.sh
Last active November 14, 2016 04:39
Sort a VCF (using bcftools + bash)
##
# Sort a VCF
#
# Input:
# vcf[.gz] or bcf[.gz]
# Output:
# vcf
#
# Example usage:
# ./sort_vcf.sh my.[vcf|bcf][.gz] > my.sorted.vcf
@sephraim
sephraim / vcf_la_norm.sh
Last active November 14, 2016 04:41
Left-align / normalize a VCF
bcftools norm -f ~/data/references/human_g1k_v37.fa -c s -m- -O v __INPUT__ | awk -F'\t' '$5 !~ ","' | bgzip -c > __OUTPUT__