This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
__author__ = "dnanto" | |
import json | |
import sys | |
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser, FileType | |
from pathlib import Path | |
from Bio.PDB import PDBParser, Superimposer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
read_ft <- function(file) { | |
# read tsv with a maximum of five columns | |
suppressWarnings( | |
read_tsv( | |
file, | |
col_names = c("start", "end", "name", "key", "val"), | |
col_types = cols(.default = "c") | |
) | |
) %>% | |
# associate rows with a feature accession and feature identifier number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
geomid <- function(lat, lon) | |
{ | |
# http://www.geomidpoint.com/calculation.html | |
lat <- lat * pi / 180 | |
lon <- lon * pi / 180 | |
x <- mean(sum(cos(lat) * cos(lon))) | |
y <- mean(sum(cos(lat) * sin(lon))) | |
z <- mean(sum(sin(lat))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_coor(coor): | |
return int(coor[0].lstrip(">").lstrip("<")), int(coor[1].lstrip(">").lstrip("<")) | |
def parse_ft(file): | |
acc, feat, coors, anno = None, None, None, None | |
for line in map(str.rstrip, file): | |
if line.startswith(">Feature"): | |
acc = line[9:].split("|", maxsplit=2)[1].split(".")[0] | |
elif acc and line: | |
if not line[0].isspace(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(igraph) | |
parse_attr <- function(val) | |
{ | |
tokens <- | |
str_split(val, '(,)(?=(?:[^"]|"[^"]*")*$)') %>% | |
lapply(str_split, '(=)(?=(?:[^"]|"[^"]*")*$)') %>% | |
unlist() %>% | |
str_trim() %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ideally, set this outside of this script, like in a profile | |
export BEAST_PACKAGE_PATH="$(pwd)"/.pkg | |
arr=( | |
"https://github.com/BEAST2-Dev/BEASTLabs/releases/download/v1.9.0/BEASTlabs.addon.v1.9.2.zip" | |
"https://github.com/BEAST2-Dev/bModelTest/releases/download/v1.2.0/bModelTest.addon.v1.2.1.zip" | |
"https://github.com/BEAST2-Dev/model-selection/releases/download/v1.5.0/MODEL_SELECTION.addon.v1.5.2.zip" | |
"https://github.com/BEAST2-Dev/nested-sampling/releases/download/v1.1.0/NS.addon.v1.1.0.zip" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# mafft ncov.fna > msa.fna | |
# snp-sites -c -v msa.fna > snp.vcf | |
library(tidyverse) | |
lines <- read_lines("snp.vcf") | |
fields <- str_split(last(lines[startsWith(lines, "#")]), "\t")[[1]] | |
read_tsv(lines, comment = "#", col_names = fields, col_types = cols(.default = "c")) %>% | |
select(10:ncol(.)) %>% | |
mutate_all(as.integer) %>% | |
colSums() %>% | |
sort(decreasing = T) %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
axiom = "0" | |
rules = { "0": "1[0]0", "1": "11" } | |
for i in range(int(sys.argv[1])): | |
axiom = "".join(rules.get(e, e) for e in axiom) | |
print(axiom) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
comp <- set_names( | |
as.list(str_split("TAACGRYSWMKVHDBN", "", simplify = 1)), | |
str_split("ATUGCYRSWKMBDHVN", "", simplify = T) | |
) | |
revcomp_btop <- function(btop) | |
{ | |
str_replace_all(btop, "([A-Z-])([A-Z-])", " \\2 \\1 ") %>% | |
str_split(" ", simplify = T) %>% | |
rev() %>% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
decode_btop <- function(btop) | |
{ | |
matches <- as.integer(str_extract_all(btop, "\\d+", simplify = T)) | |
matches <- if (str_starts(btop, "\\d", negate = T)) c(0, matches) else matches | |
pos <- 0; n <- 0; m <- 0; muts <- list(); | |
for (ele in Filter(nchar, str_split(btop, "\\d+", simplify = T))) | |
{ | |
pos <- pos + matches[n<-n+1] | |
for (i in seq(1, nchar(ele), 2)) muts[[m<-m+1]] <- list(pos = pos<-pos+1, mut = substr(ele, i, i+1)) | |
} |
NewerOlder