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
# GRCh37.p13
# $ wget -r ftp://ftp.ncbi.nlm.nih.gov/genbank/genomes/Eukaryotes/vertebrates_mammals/Homo_sapiens/GRCh37.p13/Primary_Assembly/assembled_chromosomes/FASTA/
# $ for x in {1..22} X Y; do gzip -dc chr${x}.fa.gz >> GRCh37.p13.fa; done
# UCSC hg18 (Build36.1) -- http://hgdownload.cse.ucsc.edu/goldenPath/hg18/chromosomes/
# $ wget -r -l1 'ftp://hgdownload.cse.ucsc.edu/goldenPath/hg18/chromosomes/'
# $ for x in {1..22} X Y; do gzip -dc hgdownload.cse.ucsc.edu/goldenPath/hg18/chromosomes/chr${x}.fa.gz >> hg18.fa; done
# UCSC hg17 (Build35) -- http://hgdownload.cse.ucsc.edu/goldenPath/hg17/chromosomes/
# $ wget -r -l1 'ftp://hgdownload.cse.ucsc.edu/goldenPath/hg17/chromosomes/'
@knmkr
knmkr / proportional_division.sql
Created June 24, 2016 02:01
Proportional division by dates
CREATE TEMPORARY TABLE costs (
code varchar,
cost integer,
start_at date,
end_at date
);
INSERT INTO costs VALUES
('A', 100, '2016-01-01', '2016-01-01'),
('B', 100, '2016-01-02', '2016-01-02'),
('C', 300, '2016-01-01', '2016-01-03'),
@knmkr
knmkr / rank_per_group_window_function.sql
Created June 20, 2016 01:08
グループ毎にランクを振る(RANK, DENSE_RANK, ROW_NUMBER)
BEGIN;
CREATE TEMPORARY TABLE scores (uid integer, job varchar, "name" varchar, score integer);
INSERT INTO scores (uid, job, "name", score) VALUES
(9991, 'ANALYST', 'TEST1', 100),
(9992, 'SCOREESMAN', 'TEST2', 200),
(1, 'ANALYST', 'FORD', 3000),
(2, 'ANALYST', 'SCOTT', 3000),
(3, 'CLERK', 'ADAMS', 1100),
(4, 'CLERK', 'JAMES', 950),
@knmkr
knmkr / rank_per_group.sql
Created June 17, 2016 08:34
グループごとにランクを振る(同率を許し、その分順を飛ばす。例:同率2位が2つあったら、1, 2, 2, 4)
-- http://otn.oracle.co.jp/otn_pl/otn_tool/code_detail?n_code_id=113
BEGIN;
CREATE TEMPORARY TABLE emp (empno integer, job varchar, ename varchar, sal integer);
INSERT INTO emp (empno, job, ename, sal) VALUES
(9991, 'ANALYST', 'TEST1', 100),
(9992, 'SALESMAN', 'TEST2', 200),
(1, 'ANALYST', 'FORD', 3000),
(2, 'ANALYST', 'SCOTT', 3000),
@knmkr
knmkr / counts_of_articles_in_the_gwas_catalog_group_by_journals.md
Created January 28, 2016 09:39
Counts of articles in the GWAS Catalog group by journals

Counts of articles in the GWAS Catalog group by journals on 2016-01-28

$ cut -f2,5 gwas_catalog_v1.0-downloaded_2016-01-28.tsv| tail -n+2| sort -u| cut -f2| sort| uniq -c| sort -r
424 Nat Genet
188 Hum Mol Genet
157 PLoS One
150 PLoS Genet
67 Mol Psychiatry
66 Am J Hum Genet
@knmkr
knmkr / example_heart_rate_in_health_kit_xml.md
Created December 22, 2015 05:17
Example: Heart rate records in Health Kit XML (exported from iOS Healthcare app)

Example: Heart rate records in Health Kit XML (exported from iOS Healthcare app)

...
 <Record type="HKQuantityTypeIdentifierHeartRate" sourceName="SmartBand 2" sourceVersion="1.0.3" unit="count/min" creationDate="2015-12-22 13:42:10 +0900" startDate="2015-12-22 13:42:00 +0900" endDate="2015-12-22 13:42:00 +0900" value="83">
  <MetadataEntry key="HKHeartRateSensorLocation" value="2"/>
 <Record type="HKQuantityTypeIdentifierHeartRate" sourceName="SmartBand 2" sourceVersion="1.0.3" unit="count/min" creationDate="2015-12-22 13:44:12 +0900" startDate="2015-12-22 13:43:00 +0900" endDate="2015-12-22 13:43:00 +0900" value="85">
  <MetadataEntry key="HKHeartRateSensorLocation" value="2"/>
 <Record type="HKQuantityTypeIdentifierHeartRate" sourceName="SmartBand 2" sourceVersion="1.0.3" unit="count/min" creationDate="2015-12-22 13:45:13 +0900" startDate="2015-12-22 13:44:00 +0900" endDate="2015-12-22 13:44:00 +0900" value="85">
 
@knmkr
knmkr / healthcheck_url_with_auth.sh
Created October 4, 2015 06:18
Healthchek URL with auth
#!/usr/bin/env bash
set -e
AUTH_USER=user
AUTH_PASS=pass
URL=http://www.example.com
OUT=/tmp/log/healthcheck/example.com
STATUS=$(curl -L --anyauth --user ${AUTH_USER}:${AUTH_PASS} ${URL} -o ${OUT} -s -w '%{http_code}\n')
@knmkr
knmkr / install_virtualbox_and_vagrant_on_centos6.7.md
Last active September 13, 2015 07:08
Install VirtualBox and Vagrant on CentOS 6.7
@knmkr
knmkr / dbsnp_allele_length_count.md
Created June 10, 2015 02:07
dbSNP allele length count
$ zless Allele.bcp.gz| cut -f2 | awk '{print length($1)}' | sort -n | uniq -c > dbsnp_allele_length_count.txt     
      1 0
     24 1
    105 2
    174 3
   2046 4
   3503 5
   9223 6
  25570 7
@knmkr
knmkr / sort_and_uniq_example.sql
Created May 18, 2015 05:44
Sort and uniq example in PostgreSQL with intarray extension.
CREATE EXTENSION intarray;
SELECT uniq(sort(ARRAY[3,2,1,4,3]));
-- uniq
-- -----------
-- {1,2,3,4}
SELECT unnest(uniq(sort(ARRAY[3,2,1,4,3])));
-- unnest
-- --------