Skip to content

Instantly share code, notes, and snippets.

@mojaveazure
mojaveazure / read_file_to_array.sh
Created February 9, 2017 18:25
Read a file into an array without using `cat`
#!/bin/bash
set -euo pipefail
MY_FILE="$1"
declare -ax ARRAY=($(<"${MYFILE}"))
@mojaveazure
mojaveazure / UsefulCommands.md
Last active June 3, 2016 22:38
Some commands that I come across and find useful

Useful Commands

Bash

Command Meaning
echo -en "\rSomeText" Return carriage to the beginning of the line (-e and \r), write "SomeText" at that point in time. Do not output a new line at the end of the statement (-n). Useful for dynamic terminal messages.
find . -exec touch -am {} \; Update the access and modified times for all files in this current directory and all subdirectories. Useful for keeping files around when set to expire after a given amount of time.
find . -name 'foo-exclude-me' -prune -o -name 'foo*' -print Find all files with foo*, ignoring foo-exlude-me
@mojaveazure
mojaveazure / pileup.sh
Last active February 5, 2016 00:11
Perform a pileup using SAMTools and BCFTools
#!/bin/bash
set -e
set -o pipefail
# Check for dependent programs
if ! `command -v samtools > /dev/null 2> /dev/null`; then echo "Please install SAMTools and place in your PATH"; exit 1; fi # Do we have SAMTools installed?
if ! `command -v bcftools > /dev/null 2> /dev/null`; then echo "Please install BCFTools and place in your PATH"; exit 1; fi # Do we have BCFTools installed?
# Create a usage message
@mojaveazure
mojaveazure / InstallPlatypusMSI.sh
Last active February 20, 2017 18:04
Install Platypus on MSI
#!/bin/bash
# This script is designed to install Platypus on MSI
set -e
set -o pipefail
INSTALL_DIR=${1:-$(pwd)}
echo "Installing Platypus into ${INSTALL_DIR}..." >&2
@mojaveazure
mojaveazure / regionsFromBED.sh
Last active January 7, 2016 23:51
Extract regions from a BED file and format it for use with ANGSD and ANGSD-wrapper
#!/bin/bash
set -e
set -o pipefail
# Extract regions from a BED file and format it for use with ANGSD and ANGSD-wrapper
function Usage() {
echo -e "\
Usage: $(basename $0) BED_FILE NUMBER [OUTFILE] [SEED] \n\
@mojaveazure
mojaveazure / R_Formulas.md
Created December 18, 2015 22:44
Some stuff about formulas in R

R Formula Specifications

Adapted from the National Park Service


Right-Side

Right Side Meaning
A + B Main effects of A and B
A:B Interaction of A with B
@mojaveazure
mojaveazure / installSAMTools.sh
Created December 18, 2015 22:43
Install SAMTools without needing root privileges
#!/bin/bash
# This script downloads and installs SAMTools
# The current version of SAMTools is v1.3
set -e
set -o pipefail
# What versions of SAMTools are we downloading?
SAMTOOLS_VERSION="1.3"
@mojaveazure
mojaveazure / switch_arg.py
Last active December 11, 2015 23:21
An example of a switch argument in Python
#!/usr/bin/env python
import argparse
parser = argparse.ArgumentParser(add_help=True, description="A switch argument in Python")
parser.add_argument('-s',
'--switch',
help="The switch",
action='store_true',
@mojaveazure
mojaveazure / checkExtension.sh
Created September 29, 2015 17:27
A function that checks the extension of a file
#!/bin/bash
# A function that checks the extension of a file
function checkExtension() {
FILE="$1"
EXTENSION="$2"
if [[ "${FILE: -4}" == "${EXTENSION}" ]]
then
echo yes
return 0
@mojaveazure
mojaveazure / barcodeToAdapter.sh
Created September 26, 2015 22:55
Create an adapter sequence file from the barcodes in sample names
#!/bin/bash
set -e
set -o pipefail
###########################################################################################################################
######################################### Usage Information #########################################
# This is a script to extract adapter sequences that use barcodes embedded in the names of files
# To use, add a list of samples to the SAMPLE_INFO field on line 34
# This should look like: