Skip to content

Instantly share code, notes, and snippets.

@mortonjt
mortonjt / dune.txt
Last active March 31, 2016 01:26
vegan files
"Achimill" "Agrostol" "Airaprae" "Alopgeni" "Anthodor" "Bellpere" "Bromhord" "Ch
"1" 1 0 0 0 0 0 0 0 0 0 0 4 0 0 0 0 7 0 4 2 0 0 0 0 0 0 0 0 0 0
"2" 3 0 0 2 0 3 4 0 0 0 0 4 0 0 0 0 5 0 4 7 0 0 0 0 5 0 5 0 0 0
"3" 0 4 0 7 0 2 0 0 0 0 0 4 0 0 0 0 6 0 5 6 0 0 0 0 2 0 2 0 2 0
"4" 0 8 0 2 0 2 3 0 2 0 0 4 0 0 0 0 5 0 4 5 0 0 5 0 2 0 1 0 2 0
"5" 2 0 0 0 4 2 2 0 0 0 0 4 0 0 0 0 2 5 2 6 0 5 0 0 3 2 2 0 2 0
"6" 2 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 6 5 3 4 0 6 0 0 3 5 5 0 6 0
"7" 2 0 0 0 2 0 2 0 0 0 0 0 0 0 0 2 6 5 4 5 0 3 0 0 3 2 2 0 2 0
"8" 0 4 0 5 0 0 0 0 0 0 4 0 0 0 4 0 4 0 4 4 2 0 2 0 3 0 2 0 2 0
"9" 0 3 0 3 0 0 0 0 0 0 0 6 0 0 4 4 2 0 4 5 0 2 2 0 2 0 3 0 2 0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
"""
Filter sequences from a biom table based on a fasta file
used for AG bloom filtering
"""
# amnonscript
@mortonjt
mortonjt / poisson-cat.py
Last active April 17, 2019 22:18
Closed form categorical Poisson regression
import numpy as np
import patsy
import pandas as pd
from biom import Table
# This is the main function
def poisson_cat(table, metadata, category, ref=None):
""" Poisson differential abundance.
Parameters
## import modules
import os
import copy
import time
from tqdm import tqdm
import numpy as np
from skbio.stats.composition import clr_inv as softmax
from scipy.stats import spearmanr
import datetime
import pandas as pd
"""
Installation can be done with conda via
conda create -n textminer beautifulsoup4 numpy pandas scipy scikit-learn nltk lxml jupyter notebook matplotlib seaborn
"""
@mortonjt
mortonjt / negative-binomial-regression.stan
Last active November 26, 2019 00:30
This performs a very simple negative binomial regression tailored for differential abundance analysis
data {
int<lower=0> N; // number of samples
int<lower=0> D; // number of dimensions
int<lower=0> p; // number of covariates
real depth[N]; // sequencing depths of microbes
matrix[N, p] x; // covariate matrix
int y[N, D]; // observed microbe abundances
}
parameters {
@mortonjt
mortonjt / negative-binomial-random-effects.stan
Created May 29, 2020 19:27
Show how to fit a random effects models with negative binomial
data {
int<lower=0> N; // number of samples
int<lower=0> D; // number of dimensions
int<lower=0> J; // number of subjects
int<lower=0> p; // number of covariates
real depth[N]; // sequencing depths of microbes
matrix[N, p] x; // covariate matrix
int y[N, D]; // observed microbe abundances
int<lower=1, upper=J> subj_ids[N]; // subject ids
import numpy as np
import matplotlib.pyplot as plt
from skbio.stats.ordination import pcoa
from skbio import DistanceMatrix
from scipy.spatial.distance import pdist, squareform
# embedding = < your language model embedding > # dim L x D where L is the length, D is the dimension
rr_dist = squareform(pdist(embedding))
dm = DistanceMatrix(rr_dists_d.mean(2))
@mortonjt
mortonjt / adasoft.py
Created July 21, 2021 03:42 — forked from rosinality/adasoft.py
Adaptive Softmax implementation for PyTorch
import torch
from torch import nn
from torch.autograd import Variable
class AdaptiveSoftmax(nn.Module):
def __init__(self, input_size, cutoff):
super().__init__()
self.input_size = input_size
self.cutoff = cutoff