Skip to content

Instantly share code, notes, and snippets.

View IdoBar's full-sized avatar

Ido Bar IdoBar

View GitHub Profile

Bash best practices and style-guide

Just simple methods to keep the code clean.

Inspired by progrium/bashstyle and Kfir Lavi post.

Quick big rules

  • All code goes in a function
  • Always double quote variables
@IdoBar
IdoBar / cn.mops.R
Last active July 5, 2022 23:47 — forked from danielecook/cn.mops.R
Call cnvs using cn.mops #cluster
#!/usr/bin/env Rscript
#PBS -V
# This script will call copy number variants using cn.mops
# usage: Rscript cn.mops.R --help
library(optparse)
option_list = list(
make_option(c("-i", "--input_dir"), type="character", default=NULL,
@IdoBar
IdoBar / bash_strict_mode.md
Created August 18, 2022 23:37 — forked from vncsna/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
@IdoBar
IdoBar / prepared_gtf_to_igv.sh
Created September 26, 2024 04:27 — forked from tbrittoborges/prepared_gtf_to_igv.sh
Sort and index gtf file for vizualization. Requires htslib.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <input_gtf_file>"
exit 1
fi
input_gtf="$1"
output_prefix="output"
sorted_gtf="${output_prefix}.sorted.gtf"
#! /bin/bash
## See also https://github.com/nextflow-io/nextflow/discussions/4308
## cd to a parent directory for a Nextflow pipeline executation, i.e. contains .nextflow and work directories
WORKDIR=$1
## Find work directories essential to the last pipeline run, as absolute paths
nextflow log last > $WORKDIR/preserve_dirs.txt
## Find all work directories, as absolute paths