Skip to content

Instantly share code, notes, and snippets.

View smdabdoub's full-sized avatar

Shareef Dabdoub smdabdoub

View GitHub Profile
@smdabdoub
smdabdoub / convert_phyloseq_biom.R
Last active January 18, 2024 16:47
Export phyloseq object to BIOM-compatible TSV table
# Modified from https://forum.qiime2.org/t/exporting-otu-table-from-phyloseq-into-either-biom-or-text-format/19103/6
# to be directly exportable to a BIOM file using the official 'biom' command-line tool. The file-format requirements for
# a text table to be converted are listed here:
# https://forum.qiime2.org/t/csv-to-a-qiime2-readable-format/2284/7
# This version concatenates the taxonomy ranks into a single string that is added to the OTU table as a 'taxonomy' column.
# The resulting TSV table can be converted to a BIOM-format file with the following command (outside of R):
# #biom convert -i otu_table_biom.tsv -o otu_table.biom --to-hdf5 --header-key taxonomy
library(phyloseq)
library(readr)
library(tidyr)
@smdabdoub
smdabdoub / fastspar.rb
Last active April 20, 2018 04:16
fix fastspar homebrew script
class Fastspar < Formula
desc " Rapid and scalable correlation estimation for compositional data"
homepage "https://github.com/scwatts/fastspar"
url "https://github.com/scwatts/fastspar/archive/v0.0.5.tar.gz"
sha256 "c4cc7682720f566da7587e555b58a688671a97235d00c33d042a7f2cd6cef20a"
head "https://github.com/scwatts/fastspar.git"
depends_on "armadillo" => :run
depends_on "gsl" => :run
depends_on "gnu-getopt" => :run
@smdabdoub
smdabdoub / jags_mkl_build_linux.txt
Last active March 20, 2018 21:08
Building JAGS and rjags with the Intel MKL LAPACK routines (LINUX)
# NOTE: This was done on RHEL 7.3 with JAGS v4.3.0 and rjags v4-6. It should be fairly portable, but YMMV.
# Step 1: create an MKL environment variable for use in the --with-blas option for the JAGS configure script
# the below was taken from Martyn Plummer's "Building a portable R binary with Intel tools"
# https://martynplummer.files.wordpress.com/2014/10/r-intel-fedora.pdf
# I set MKL_LIB_PATH by looking at MKL_LIBS
export MKL="-Wl,--start-group ${MKL_LIB_PATH}/libmkl_gf_lp64.a \
> ${MKL_LIB_PATH}/libmkl_gnu_thread.a \
> ${MKL_LIB_PATH}/libmkl_core.a \
@smdabdoub
smdabdoub / list_flatten.py
Last active September 14, 2017 15:32
flatten a list of lists in python
# Original discussion
# https://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python
# vanilla python list comprehension
flatten = lambda lst: [item for sublist in lst for item in sublist]
# with itertools
flatten_chain = lambda lst: list(itertools.chain(*lst))
# with itertools >= 2.6
@smdabdoub
smdabdoub / merge_git_repo_as_subdir
Created June 9, 2015 14:02
Merge one git repository into another repository as a sub-directory
# based on the following:
# http://saintgimp.org/2013/01/22/merging-two-git-repositories-into-one-repository-without-losing-file-history/
# http://blog.caplin.com/2013/09/18/merging-two-git-repositories/
git clone repo_main
git clone repo_sub
cd repo_main
git remote add repo_sub ../repo_sub
git fetch repo_sub
@smdabdoub
smdabdoub / biom_otu_name.py
Created May 29, 2014 17:26
Method for extracting a simple genus_species string identifier from a BIOM table with taxonomy metadata. If no species, use Genus_spp, if no genus, use Unclassified_ and lowest available taxonomic identifier. This example script will also take a BIOM file from the command line and run the method on every row in the table and print the results.
import json
import sys
def otu_name(biom_row):
"""
Determine a simple Genus-species identifier for an OTU, if possible.
If OTU is not identified to the species level, name it as Unclassified (familly/genus/etc...)
"""
tax = biom_row['metadata']['taxonomy']
for i, lvl in enumerate(tax):
@smdabdoub
smdabdoub / gist:6781531
Created October 1, 2013 16:47
homebrew build error for ITK 4.4.2 with python wrappings
➜ ~ brew install https://raw.github.com/iMichka/homebrew-science/8614633a8927be14b7e00d48a75acb66af3fc83e/insighttoolkit.rb --with-python
######################################################################## 100.0%
==> Installing dependencies for insighttoolkit: vtk
==> Installing insighttoolkit dependency: vtk
==> Downloading http://www.vtk.org/files/release/6.0/vtk-6.0.0.tar.gz
######################################################################## 100.0%
==> cmake -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/vtk/6.0.0 -DCMAKE_BUILD_TYPE=None -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DVTK_REQUIRED_OBJCXX_FLAGS='' -DVT
==> make
==> make install
==> Caveats
@smdabdoub
smdabdoub / interleave.py
Created March 21, 2013 14:24
Simple python method to create an interleaved list from two or more iterables.
from itertools import chain, izip
ileave = lambda *iters: list(chain(*izip(*iters)))
# full method with doctests
def interleave(*iters):
"""
Given two or more iterables, return a list containing
the elements of the input list interleaved.