Skip to content

Instantly share code, notes, and snippets.

View slowkow's full-sized avatar
🐄
moooooo

Kamil Slowikowski slowkow

🐄
moooooo
View GitHub Profile
@slowkow
slowkow / bigWigRegions.sh
Created August 24, 2015 20:45
Print bigWig data for each region in a BED file
#!/usr/bin/env bash
# bigWigRegions
# Kamil Slowikowski
#
# Depends on bigWigToBedGraph: http://hgdownload.cse.ucsc.edu/admin/exe/
if [[ $# -ne 2 ]]; then
echo "bigWigRegions - Print bigWig data for each region in a bed file."
echo -e "usage:\n bigWigRegions in.bigWig in.bed > out.bedGraph"
echo " bigWigRegions in.bigWig <(zcat in.bed.gz) > out.bedGraph"
@slowkow
slowkow / mycd.sh
Last active September 8, 2015 15:55 — forked from leipzig/mycd.sh
Record folder-specific history in `.dir_bash_history`
function cd_dir_history()
{
OLDPWD="$PWD"
echo "# $(date) $USER -> $@" >> "$HISTFILE"
command cd "$@"
# If this directory is writable then write to directory-based history file
# otherwise write history in the usual home-based history file.
touch "$PWD/.dir_bash_history" 2>/dev/null \
@slowkow
slowkow / query_ncbi.pl
Created March 24, 2011 06:27
Query any NCBI database (nucleotide, protein, nucgss, etc.) and retrieve resulting records.
#!/usr/bin/perl
# Author : Kamil Slowikowski <kslowikowski@gmail.com>
# Date : March 23, 2011
# Version : 0.1
# Description : Modified code from
# http://www.bioperl.org/wiki/HOWTO:EUtilities_Cookbook
use strict;
use warnings;
@slowkow
slowkow / merge.py
Created October 21, 2015 19:26
Merge two files with Python.
# https://www.biostars.org/p/162853
cache = {}
f2 = open('f2')
header2 = f2.next()
for line in f2:
fields = line.strip().split()
snp = fields[0]
@slowkow
slowkow / merge_intervals.py
Last active December 13, 2015 19:39
Python snippet: mimic the command `bedtools merge`
#!/usr/bin/env python
"""merge_intervals.py
Merge tab-delimited intervals:
cat tissue1.txt
chr1,1-2
chr1,3-4
chr1,5-6
@slowkow
slowkow / ncbi_fetch.py
Created February 21, 2013 19:58
Query any NCBI database and retrieve batches of records as gzip archives
#!/usr/bin/env python
"""ncbi_fetch.py
Query NCBI and fetch the results into gzipped files. Files will be saved in
the current directory as: 001-050.gz, 051-100.gz, etc.
You can then do:
zcat 001-050.gz | head
@slowkow
slowkow / genomic_intervals.py
Last active December 20, 2015 18:59
Genomic intervals: 0-based, 1-based, overlaps, and distance
"""
genomic_intervals.py
Kamil Slowikowski
February 27, 2014
Genomic intervals: 0-based, 1-based, overlaps, and distance
===========================================================
This document describes genomic intervals and includes source code for testing
overlap and calculating distance between intervals.
@slowkow
slowkow / chromtree.py
Last active December 26, 2015 22:08
Python snippet: one interval tree for each chromosome
"""
chromtree.py
Kamil Slowikowski
October 30, 2013
This module is a simple extension of
bx.intervals.intersection.IntervalTree
to neatly handle a dictionary of interval trees.
@slowkow
slowkow / merge_lanes.py
Last active July 27, 2016 13:23
Merge FASTQ files from multiple lanes.
#!/usr/bin/env python
# encoding: utf8
"""
merge_lanes.py
Kamil Slowikowski
July 17, 2015
Broad Technology labs provides sequencing data in a directory structure like
this:
@slowkow
slowkow / fix_alleles.py
Last active July 27, 2016 13:27
Join multiple PLINK dosage files into one file.
#!/usr/bin/env python
"""
Kamil Slowikowski
fix_alleles.py
==============
Change the alleles in a dosage file to match the alleles specified in
a separate reference file. If a variant is not present in the reference file,
then it will not be changed.