Skip to content

Instantly share code, notes, and snippets.

View dceoy's full-sized avatar
Lazy

Daichi Narushima dceoy

Lazy
View GitHub Profile
@dceoy
dceoy / extract_lowercase_regions_from_fasta.py
Last active May 19, 2020 17:28
[Python] Extract lowercase regions in a FASTA file and write them into a BED file
#!/usr/bin/env python
import argparse
import bz2
import gzip
import logging
import os
from pathlib import Path
from pprint import pformat
@dceoy
dceoy / read_fasta.py
Created July 10, 2019 04:31
[Python] Read a FASTA file using Biopython
#!/usr/bin/env python
import bz2
import gzip
from Bio import SeqIO
def read_fasta(path):
if path.endswith('.gz'):
@dceoy
dceoy / git_rewind_days.sh
Created June 3, 2019 18:32
[Shell] Rewind days at the latest commit of Git logs
#!/usr/bin/env bash
#
# Usage: ./git_rewind_days.sh <int>
set -eux
DAYS_TO_REWIND="${1}"
COMMIT_DATE=$(git log -1 | sed -ne 's/^Date: \+//p')
REWIDED_DATE=$(date -d "${COMMIT_DATE% *} - ${DAYS_TO_REWIND} days" | awk '{print $1" "$2" "$3" "$4" "$6}')" ${COMMIT_DATE##* }"
@dceoy
dceoy / install_rbenv.sh
Last active May 7, 2019 10:11
[Shell] Install the latest version of Ruby with rbenv
#!/usr/bin/env bash
#
# https://github.com/dceoy/ansible-dev/blob/master/roles/ruby/files/install_rbenv.sh
set -uex
RBENV_DIR="${HOME}/.rbenv"
RB_BUILD_DIR="${HOME}/.rbenv/plugins/ruby-build"
RBENV="${RBENV_DIR}/bin/rbenv"
[[ ${#} -ge 1 ]] && RB_MAJOR_VER="${1}" || RB_MAJOR_VER=2
@dceoy
dceoy / install_pyenv.sh
Last active May 7, 2019 10:12
[Shell] Install the latest version of Python with pyenv
#!/usr/bin/env bash
#
# https://github.com/dceoy/ansible-dev/blob/master/roles/python/files/install_pyenv.sh
set -uex
PYENV_DIR="${HOME}/.pyenv"
PYENV="${PYENV_DIR}/bin/pyenv"
[[ ${#} -ge 1 ]] && PY_MAJOR_VER="${1}" || PY_MAJOR_VER=3
@dceoy
dceoy / install_bio_stack.sh
Last active March 13, 2019 22:00
[Shell] Install BWA, Samtools, Bcftools, and Bedtools
#!/usr/bin/env bash
#
# Usage: ./install_bio_stack.sh <dest dir path>
set -uex
PREFIX_DIR=$(realpath "${1}")
BIN_DIR="${PREFIX_DIR}/bin"
SRC_DIR="${PREFIX_DIR}/src"
mkdir -p "${SRC_DIR}" "${BIN_DIR}"
@dceoy
dceoy / subprocess_line_generator.py
Last active December 4, 2018 14:25
[Python] Generate STDOUT lines from subprocess
#!/usr/bin/env python
import subprocess
def run_and_parse_subprocess(**popen_args):
with subprocess.Popen(**popen_args) as p:
for line in p.stdout:
yield line.decode('utf-8')
if p.poll() == 0:
@dceoy
dceoy / install_cudnn.sh
Created October 12, 2018 06:52
[CUDA] Configure CUDA
#!/usr/bin/env bash
#
# Usage: ./install_cudnn.sh <tar file>
set -ex
[[ -n "${1}" ]] \
&& tar -xzvf ${1} -C /tmp \
&& cp /tmp/cuda/include/cudnn.h /usr/local/cuda/include \
&& cp /tmp/cuda/lib64/libcudnn* /usr/local/cuda/lib64 \
@dceoy
dceoy / HotelligT2.py
Last active October 12, 2018 06:54
[Python] Hotelling's T-squared anomaly detection
#!/usr/bin/env python
import numpy as np
from scipy import stats
class HotellingsT2(object):
def __init__(self, alpha):
self.anomaly_score_threshold = stats.chi2.ppf(q=(1 - alpha), df=1)
@dceoy
dceoy / install_packages.R
Last active June 17, 2018 18:04
[R] Install R packages
#!/usr/bin/env Rscript
if(length(argv <- commandArgs(trailingOnly = TRUE)) > 0) {
install.packages(pkgs = argv,
repos = c(CRAN = 'https://cran.rstudio.com/'),
dependencies = TRUE)
} else {
message('Nothig to do.')
}