Skip to content

Instantly share code, notes, and snippets.

View thanhleviet's full-sized avatar
🤗
Focusing

Thanh Lee thanhleviet

🤗
Focusing
View GitHub Profile
@thanhleviet
thanhleviet / subset_multiple_conditions.r
Created May 17, 2018 12:05
Subset with multiple conditions
mtcars %>%
mutate(
selected = case_when(
cyl == 6 & carb == 4 ~ "yes",
cyl == 8 & carb == 8 ~ "yes",
TRUE ~ "no"
)
) %>%
filter(selected == "yes") %>%
select(-selected)
@thanhleviet
thanhleviet / dehomopolymerate.nim
Created April 8, 2018 11:16
De-homopolymer in nim-lang
# Some proc are stolen from
# https://github.com/jhbadger/nimbioseq
import sequtils, strutils, math, tables, osproc, streams, os, typetraits
type Record* = object
## This type represents a genetic sequence with optional quality
id*: string
description*: string
quality*: string
@thanhleviet
thanhleviet / parse.txt
Last active March 12, 2018 03:16
Parsing BLAST results
ClusterBlast scores for /home/wms_joe/PVCs/other_genomes/multigene/operon_genbank/PVCcif_ATCC43949.gbk
Table of genes, locations, strands and annotations of query cluster:
PAU_01961 8 457 + T4-like_virus_tail_tube_protein_gp19 no_locus_tag
PAU_01962 521 1618 + major_tail_sheath_protein no_locus_tag
PAU_01963 1799 3280 + tail_sheath_protein no_locus_tag
PAU_01964 3334 4533 + tail_sheath_protein no_locus_tag
PAU_01965 4547 5005 + T4-like_virus_tail_tube_protein_gp19 no_locus_tag
PAU_01966 5002 5181 + hypothetical_protein no_locus_tag
PAU_01967 5168 5851 + hypothetical_protein no_locus_tag
@thanhleviet
thanhleviet / getGenomeNCBI.sh
Created December 25, 2017 09:17
Download genome from ncbi using accession number
while read id; do curl "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=nuccore&amp;id="$id"&amp;rettype=fasta&amp;retmode=text" > "$id".fasta; done < ecoli_ref.txt
@thanhleviet
thanhleviet / Dockerfile
Created September 8, 2017 08:30
docker for mosdepth
FROM debian:8.6
LABEL author="Maxime Garcia" \
description="HTSlib 1.4 image for use in CAW" \
maintainer="[email protected]"
# Dockefile for mosdepth is based on Dockerfile for HTSlib 1.4 by Maxime Garcia
# I just added few lines for quick building a docker image for mosdepth
# Install libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
@thanhleviet
thanhleviet / wget-gdrive.sh
Created August 28, 2017 06:46 — forked from lvzongting/wget-gdrive.sh
download google drive file only with wget 仅通过wget 在bash命令行下载谷歌网盘(狗哥网盘)上的文件
#reference https://unix.stackexchange.com/questions/136371/how-to-download-a-folder-from-google-drive-using-terminal
#get cookie and code
wget --save-cookies cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=FILEID' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/Code: \1\n/p'
#download the file
wget --load-cookies cookies.txt 'https://docs.google.com/uc?export=download&confirm=CODE_FROM_ABOVE&id=FILEID'
@thanhleviet
thanhleviet / df2phydat.r
Created May 31, 2017 11:00
Demo script for converting a data frame of nucleotide column to phydat format
rm(list = ls())
# Le Viet Thanh
# May 31st 2017
# Demo script for converting a data frame of nucleotide column to phydat format
# Asked by Dung Nguyen Chi
library(seqRFLP)
library(readr)
library(dplyr)
@thanhleviet
thanhleviet / sam_to_consensus_fa.sh
Created May 22, 2017 23:44 — forked from bede/sam_to_consensus_fa.sh
Bioinformatics code golf: SAM to consensus FASTA
# SAM to consensus FASTA code golf, inspired by http://lab.loman.net/2015/07/28/calling-haploid-consensus-sequence/
# Starting with a SAM:
samtools view -bS seqs.sam | samtools sort - seqs # Generate and sort BAM
samtools index seqs.bam # Index BAM
# Starting with an indexed BAM:
samtools mpileup -ud 1000 -f seqs_ref.fasta seqs.bam | bcftools call -c | vcfutils.pl vcf2fq | seqtk seq -a - > seqs.consensus.fa # Generate pileup, call variants, convert to fq, convert to fa
# Who can do better? The bar is set low...
@thanhleviet
thanhleviet / fib.jl
Created February 10, 2017 06:10
Rabbit fibonacci function for http://rosalind.info/problems/fib/
function total(n,k=3)
rfib(n) = n < 2 ? n : rfib(n-1) + k*rfib(n-2)
return rfib(n)
end
total(5,3)
@thanhleviet
thanhleviet / nd46.csv
Last active January 20, 2017 10:14
Trích xuất các mức phạt từ nghị định 46 từ trang web thuvienphapluat.vn ra tập tin csv sử dụng R.
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 7 columns, instead of 3 in line 6.
value,chuong,dieu,khoan,diem,ma_loi,muc_phat
Chương I,Chương I,NA,NA,NA,Chương I.NA.NA,[cá nhân: NA-NA]
NHỮNG QUY ĐỊNH CHUNG,Chương I,NA,NA,NA,Chương I.NA.NA,[cá nhân: NA-NA]
Điều 1. Phạm vi điều chỉnh,Chương I,Điều 1,NA,NA,Chương I.Điều 1.NA,[cá nhân: NA-NA]
"1. Nghị định này quy định về hành vi vi phạm hành chính; hình thức, mức xử phạt, biện pháp khắc phục hậu quả đối với từng hành vi vi phạm hành chính; thẩm quyền lập biên bản, thẩm quyền xử phạt, mức phạt tiền cụ thể theo từng chức danh đối với hành vi vi phạm hành chính trong lĩnh vực giao thông đường bộ và đường sắt.",Chương I,Điều 1,1,NA,Chương I.Điều 1.1,[cá nhân: NA-NA]
2. Các hành vi vi phạm hành chính trong các lĩnh vực quản lý nhà nước khác liên quan đến lĩnh vực giao thông đường bộ và đường sắt mà không quy định tại Nghị định này thì áp dụng quy định tại các Nghị định quy định về xử phạt vi phạm hành chính trong các lĩnh vực đó để xử phạt.,Chương I,Điều 1,2,NA,Chương I.Điều 1.2,[cá nhân: NA-NA]
Điều 2. Đối tượng áp dụng,Chương I,Điều