Skip to content

Instantly share code, notes, and snippets.

View danielecook's full-sized avatar
😀
Things are going good

Daniel E Cook danielecook

😀
Things are going good
View GitHub Profile
@danielecook
danielecook / sort_vcf.sh
Last active November 15, 2019 18:16
sort_vcf
function sort_vcf {
grep "^#" ${1}
grep -v "^#" ${1} | sort -V -k1,1 -k2,2n
}
@danielecook
danielecook / 0README.md
Created November 14, 2019 10:02 — forked from juancarlospaco/0README.md
Python Versus Nim: Async

Python Versus Nim: Async

  • No performance benchmark.
  • Python ⟿ PEP-8
  • Nim ⟿ NEP1
  • Python ⟿ 3.7
  • Nim ⟿ 0.19
  • No Ofuscation, no Code-Golf.

This is to compare elegant, simple, expressive code.

@danielecook
danielecook / ls_snapshot.sh
Created November 2, 2019 20:29
ls snapshots
function ls_snapshot {
if [[ -z $1 ]]; then
n_backup=1
else
n_backup=${1}
fi;
search=""
original_path=$(pwd -P)
@danielecook
danielecook / fetch_cendr_cites.py
Last active October 20, 2019 21:40
Extract articles that cite CeNDR; The C. elegans natural diversity resource
import scholarly
search_results = scholarly.search_pubs_query("CeNDR")
top = next(search_results)
assert top.bib["title"] == "CeNDR, the Caenorhabditis elegans natural diversity resource"
citations = list(top.get_citedby())
for i in citations:
print("\t".join(i.bib["title"], i.bib["author"], i.bib.get("eprint"))]
@danielecook
danielecook / OR_in_R.R
Last active April 24, 2020 01:31
II, I, &&, & Operators in R
# A double bar || OR in R "short circuits"
# The || operator will skip evaluating the second argument if the first argument is TRUE.
{ print("left"); TRUE } || { print("right"); TRUE } # Prints left
{ print("left"); FALSE } || { print("right"); TRUE } # Prints left, right
# The && operator will skip evaluating the second argument if the first argument is TRUE.
{ print("left"); TRUE } && { print("right"); TRUE } # Prints left, right
{ print("left"); FALSE } && { print("right"); TRUE } # Prints right
# Both arguments will be evaluated, even though the first one is TRUE
conda activate primary-env
function extract_gts() {
i=${1}
patient=$(echo ${i} | egrep -o "LTX[0-9]+" | head -n 1)
sample=$(echo ${i} | cut -f 5 -d "/")
vcf2tsv -g ${i} | \
awk -v patient=${patient} -v fname=${i} -v OFS="\t" -v sample=${sample} 'NR == 1 { print "patient", "sample", "fname", $0 } NR > 1 { print patient, sample, fname, $0 }' | \
awk '!arr[$0]++' > gl_genotypes/${patient}.tsv
}
@danielecook
danielecook / excel.sh
Created June 28, 2019 09:16
Open a file from the command line in Excel #MacOS
function excel() {
tmp=`mktemp`
out=${1}
cat ${out} > $tmp
open -a "Microsoft Excel" $tmp
}
@danielecook
danielecook / groovy-grapes.nf
Last active May 4, 2020 12:12
Import filename utilities nextflow groovy grape
#!/usr/bin/env nextflow
@Grab(group='commons-io', module='commons-io', version='2.6')
import org.apache.commons.io.FilenameUtils;
@danielecook
danielecook / nextflow-bash.sh
Last active January 26, 2024 18:03
Useful nextflow bash functions
# Shortcut for going to work directories
# Usage: gw <workdir pattern>
# Replace the work directory below as needed
# Where workdir pattern is something like "ab/afedeu"
function gw {
path=`ls --color=none -d /path/to/work/directory/$1*`
cd $path
}
# Go work that fetches work dir from .nextflow.log
@danielecook
danielecook / nim-notes.md
Created June 5, 2019 09:03
nim-lang notes #notes
uint32.high # High value for uint32
uint32.low # Low value for uint32