Skip to content

Instantly share code, notes, and snippets.

@inodb
inodb / ensemble_rest.md
Created August 27, 2015 22:57
Get region from ensembl rest and translate one-liner

Ensembl REST API

Get region from ensembl REST and translate in one line

curl 'http://grch37.rest.ensembl.org/sequence/region/human/17:41267755:41267763:-1' -H 'Content-type:text/x-fasta' \
    | python <(echo -e "import sys\nfrom Bio import SeqIO\nprint [r.seq.translate() for r in SeqIO.to_dict(SeqIO.parse(sys.stdin, 'fasta')).values()][0]")
@inodb
inodb / bam_length_readcount
Created March 13, 2014 16:49
Count the number of reads mapping to contigs of a given length
#!/bin/sh
samtools idxstats map.bam | awk '{split ($0, a, "\t")} {if (a[2]>999) SUM+=a[3]} END {print SUM}'
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@inodb
inodb / deinterleave_fastq_merge
Last active August 29, 2015 14:02
If you have a single fastq file that has single reads inbetween paris then this script can help you separate the pairs in r1, r2 and single reads.
cat ../Batch1.fastq | \
awk -v se=se.fastq -v r1=r1.fastq -v r2=r2.fastq '
BEGIN {l5=0}
{
if (l5 == 0) {
l1=$0; getline
}
else {
l1=l5
}
@inodb
inodb / rst2code
Last active August 29, 2015 14:10
Bash function to get the code parts from rst file (uses awk). Use either with ``rst_to_code filename`` or ``cat *.rst | rst_to_code -``
#!/bin/sh
# Get only code blocks from rst file, use like:
# rst2code index.rst
# or
# cat index.rst | rst2code -
# pipe to bash if it is bash code e.g.
# rst2code index.rst | bash -x
rst2code() {
awk 'BEGIN {code=0}
{
{
"metadata": {
"name": "",
"signature": "sha256:5e2aa6b0192161bf476557fbe7d2307d8e28ab5c3ce5229e942d671d5dd9689b"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
@inodb
inodb / init_raylim_pipeline
Last active August 29, 2015 14:16
init_raylim_pipeline
#!/bin/bash
echo "Cloning raylim/scripts"
git clone https://github.com/raylim/scripts
git clone https://github.com/raylim/modules
cat > Makefile <<EOF
# Autogenerated Makefile with init_raylim_pipeline
include modules/Makefile
EOF
#!/bin/bash
# Deduplicates all .txt files in sudirs
# creates file with .dedup postfix
# keeps one header line if file does not contains comments
# keeps two header lines if file contains comments
find . -name '*.txt' | parallel -k "f=$(mktemp -t mskimpact) &&" sort {} '|' uniq -d '>' '$f' '&&' test -s '$f' '&&' '('grep -q '^#' {} '&&' '('head -2 {} '>' {}.dedup '&&' tail -n +3 {} '|' sort '|' uniq '>>' {}.dedup')' '||' '('head -1 {} '>' {}.dedup '&&' tail -n +2 {} '|' sort '|' uniq '>>' {}.dedup'))'
# to replace all files run:
#find . -name '*.dedup' | parallel -k 'f='{} '&&' mv {} '${f/.dedup/}'
#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
export PORTAL_HOME=$DIR
@inodb
inodb / gbgrep
Created November 5, 2015 23:14 — forked from nas/gbgrep
git blame with grep
#!/usr/bin/env ruby
grep = `git grep -n #{ARGV[0]} #{ARGV[1]}`
puts "\n-----------------------------------------------------------"
puts "GREP RESULT"
puts '-----------------------------------------------------------'
puts grep
files = grep.scan /.*\:\d+/