Skip to content

Instantly share code, notes, and snippets.

@mattravenhall
Last active May 14, 2018 09:46
Show Gist options
  • Save mattravenhall/6da4802248ca37c35b4dbe6976b86ddb to your computer and use it in GitHub Desktop.
Save mattravenhall/6da4802248ca37c35b4dbe6976b86ddb to your computer and use it in GitHub Desktop.
Often you'll need to pass a standard form genomic location (chr:bpA-bpB) but actually use the components. Splitting in bash is a pain, this does that for you. Assigning chr, bpA, and bpB to those variable names.
# Here the function assumes you're passing a standard form genomic position (chr:bpA-bpB) as the first argument.
function splitRegion {
IFS=':' read -ra REGION <<< "$1"
chr="${REGION[0]}"
IFS='-' read -ra LOCATION <<< "{REGION[1]}"
bpA="${LOCATION[0]}"
bpB="${LOCATION[1]}"
}
splitRegion $1
# chr, bpA, and bpB are now assigned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment