Skip to content

Instantly share code, notes, and snippets.

View knmkr's full-sized avatar

Kensuke Numakura knmkr

  • Genomelink
  • SF Bay Area || Tokyo, Japan
View GitHub Profile
@knmkr
knmkr / is_postgres_greater_equal_9_3.sh
Last active August 29, 2015 14:20
Check if PostgreSQL version > 9.3
$ psql $dbname $username --tuples-only -c "SELECT substring(version() from 'PostgreSQL (\d\.\d)')::float >= 9.3"| tr -d ' '
t
@knmkr
knmkr / unit_testing_in_postgresql_with_pgtap_pg_prove_.md
Created May 2, 2015 14:59
[postgresql] Unit testing in PostgreSQL with pgTAP extension + pg_prove

pgTAP に付随して公開されている pg_prove というツールでユニットテストの実行・計測ができる.

perl なので cpan からインストール. pg_prove コマンドが使えるようになる.

$ cpan TAP::Parser::SourceHandler::pgTAP
$ pg_prove --version
pg_prove 3.29
@knmkr
knmkr / unit_testing_in_postgresql_with_pgtap_extension.md
Last active August 29, 2015 14:20
[postgresql] Unit testing in PostgreSQL with pgTAP extension

PostgreSQL の ユニットテストフレームワーク pgTAP を使ってみる.

ドキュメント通りインストールする.

コンパイル:

$ wget http://api.pgxn.org/dist/pgtap/0.95.0/pgtap-0.95.0.zip
$ ./pgtap-0.95.0
$ cd pgtap-0.95.0
@knmkr
knmkr / get_fasta_sequence_of_rs_id.py
Created May 1, 2015 08:39
[bioinfo] Get FASTA sequence of rs ID
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import gzip
import re
import sys
from Bio import SeqIO
from Bio.Alphabet import IUPAC
@knmkr
knmkr / get_current_chromosome_and_position_from_old_reference_genome_version.md
Created April 28, 2015 09:05
[bioinfo] Get current chromosome and position from old reference genome version

Download liftOver executable from UCSC

$ wget http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/liftOver
$ chmod +x liftOver

Download chain files (mapping information between different genome version) from UCSC

@knmkr
knmkr / get_fasta_sequence_of_rs_id.md
Created April 28, 2015 08:42
[bioinfo] Get FASTA sequence of rs ID

Download all FASTA records (stored in multi-FASTA files) from FTP for current dbSNP build.

$ wget -r -l 0 ftp://ftp.ncbi.nih.gov/snp/organisms/human_9606/rs_fasta

Parse multi-FASTA file, using Biopython ($ pip install biopython).

@knmkr
knmkr / row2col_crosstab_example.sql
Last active August 29, 2015 14:17
Convert rows to cols by crosstab()
CREATE EXTENSION IF NOT EXISTS tablefunc;
CREATE TEMP TABLE my_rows (age integer, gender varchar, val integer);
INSERT INTO my_rows VALUES (10, 'M', 11), (10, 'W', 12), (10, 'A', 13);
INSERT INTO my_rows VALUES (20, 'M', 21), (20, 'W', 22);
INSERT INTO my_rows VALUES (30, 'A', 33);
-- rows
SELECT * FROM my_rows;
-- age | gender | my_value
@knmkr
knmkr / with_recursive_tree_examples.sql
Created March 16, 2015 09:12
PostgreSQL WITH RECURSIVE example
DROP TABLE IF EXISTS my_tree;
CREATE TABLE my_tree (id integer, parent integer);
INSERT INTO my_tree VALUES (1, null), (2, 1), (3, 1), (4, 3);
--
-- 1
-- / \
-- 2 3
-- |
-- 4
@knmkr
knmkr / not_null_check_in_combination_demo.sql
Created March 16, 2015 07:01
Not null check in combination: check (foo is not null) or (bar is not null).
DROP TABLE IF EXISTS snp_info;
CREATE TABLE snp_info (
snp_id varchar NOT NULL,
foo integer,
bar integer
CHECK (foo IS NOT NULL OR bar IS NOT NULL)
);
-- Success:
-- INSERT INTO snp_info VALUES ('rs10', 1, NULL);
@knmkr
knmkr / git2hg.md
Last active August 29, 2015 14:14
Git <-> Hg
To do Git Hg reference
commit内容を表示 git show hg log -r REV -p link
直前のcommit取り消し(変更内容は保持) git reset --soft HEAD^ hg strip --keep -r . link, link
直前のcommitメッセージ変更 git commit —amend ?
ファイル削除も含めてadd git add —A hg addremove -A = --no-ignore-removal
過去のcommitがHEADから何番目かを調べる git reflog ?
特定のcommitまで戻る(HEADから何番目かを指定) git reset --hard HEAD@{1} ?
addを取り消し git reset ?
ステージされている変更のみを表示 git diff head --cached? ?