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 / seq2colored_seq.py
Created December 13, 2012 08:27
Get sequence with colors, according to color table {sub_sequence: color_name }, e.g, {'A': 'red'}.
from termcolor import colored
def seq2colored_seq(seq, color_table):
"""Return sequence with colors, according to color_table {sub_sequence: color_name}, e.g, {'A': 'red'}.
"""
result = ''
for x in seq:
if x in color_table:
@knmkr
knmkr / quote-as-list.el
Last active December 10, 2015 11:18
elisp / Quote selected region as python-list.
(eval-when-compile (require 'cl))
;;; Quote selected region as python-list.
(defun quote-as-list ()
;; a t g c
;; -> ["a", "t", "g", "c"]
(interactive)
;; cut region as `seq`
(setq seq (buffer-substring (region-beginning) (region-end)))
@knmkr
knmkr / quote-as-dict.el
Last active December 10, 2015 11:28
elisp / Quote selected region as python-dict.
(eval-when-compile (require 'cl))
(defun quote-as-dict ()
"Quote selected region as python-dict.
a t g c
-> {'a': 't', 'g': 'c'}
"
(interactive)
@knmkr
knmkr / tmux-split-or-select-pane.sh
Created January 3, 2013 06:09
tmux / Split-window if there is only one pane, else select-pane.
#!/bin/sh
## Split-window if there is only one pane, else select-pane.
##
## Set key-binding to run this script, in .tmux.conf, like,
## bind -n C-t run "/path/to/tmux-split-or-select-pane.sh"
# check if more than one pane exists
tmux list-panes > /tmp/tmux.list-panes
awk '{if ($1!="0:") {exit 1}}' /tmp/tmux.list-panes
@knmkr
knmkr / eject.py
Created January 22, 2013 18:04
for Mac, do `eject`
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import subprocess
def _main():
parser = argparse.ArgumentParser()
args = parser.parse_args()
@knmkr
knmkr / print-bits-of-string.py
Last active December 13, 2015 18:19
print bits of 'hello, world\n\0'
for c in 'hello, world\n\0':
print format(ord(c), 'b').rjust(8, '0')
# 01101000
# 01100101
# 01101100
# 01101100
# 01101111
# 00101100
# 00100000
@knmkr
knmkr / md5check.sh
Last active December 14, 2015 20:09
md5-check by bash
#!/bin/bash
# USAGE: md5check [files]
#
# example: ./md5check *.gz
if [ $# -eq 0 ]; then
echo "USAGE: md5check [files]"
exit 0
fi
@knmkr
knmkr / get_contigs.py
Created March 28, 2013 13:41
Get contig information by `samtools view -H`
def get_contigs(bam_path):
"""Get contig information by `samtools view -H`
Arg:
bam_path: path to a bam-file
RetVal:
['chr1', 'chr2', ..., 'chrM']
"""
@knmkr
knmkr / count-acgt.py
Created April 2, 2013 14:38
count the number of each characters in <stdin>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import Counter
import fileinput
def _main():
"""
Usage example:
@knmkr
knmkr / use_blast_from_command-line.md
Last active October 15, 2022 14:59
How to use blast from command-line, on Mac OS X.

#How to use blast from command-line, on Mac OS X.

Install blast

Download executables (binary) of blast-commands for Mac OS X.

$ curl -O ftp://ftp.ncbi.nih.gov/blast/executables/blast+/2.2.28/ncbi-blast-2.2.28+.dmg
or
$ wget ftp://ftp.ncbi.nih.gov/blast/executables/blast+/2.2.28/ncbi-blast-2.2.28+.dmg