Skip to content

Instantly share code, notes, and snippets.

View ivan-krukov's full-sized avatar
🗃️
Getting there

Ivan Krukov ivan-krukov

🗃️
Getting there
View GitHub Profile
@ivan-krukov
ivan-krukov / templater.py
Last active December 18, 2015 09:38
Template string wrapper. uses 'inspect' to get the caller namespace dict
import inspect
def render(string,variables=None):
"""Wrapper method for String Template:
name="Jeff"
render("Hello, $name")
>>Hello, Jeff
"""
t = Template(string)
if not variables:
@ivan-krukov
ivan-krukov / grepseq.py
Last active December 20, 2015 13:59
Fasta grep. Search a fasta file with a pattern. Either a single query or a file with regexes
#get sequences by regex match from a fasta file
from argparse import ArgumentParser
import re
parser = ArgumentParser(description="grep for fasta IDs")
group = parser.add_mutually_exclusive_group()
group.add_argument("--query_string","-q")
group.add_argument("--query_file","-f")
@ivan-krukov
ivan-krukov / linearSolver.cpp
Created November 29, 2013 03:18
Simple example for linear system solver in LAPACK
#include "mkl.h"
#include <math.h>
#include <float.h>
#include <stdio.h>
/* Auxiliary routine: printing a matrix */
void print_matrix(float * matrix, int nrow, int ncol) {
for (int i = 0; i < nrow; i++) {
for (int j = 0; j < ncol; j++) {
printf("%.*e\t",FLT_DIG, matrix[i * ncol + j]);
@ivan-krukov
ivan-krukov / scd.cpp
Created December 3, 2013 21:50
Singular value decomposition to solve the null space problem
#include "mkl.h"
#include <math.h>
#include <float.h>
#include <ctime>
#include <stdio.h>
/* Auxiliary routine: printing a matrix */
void print_matrix(double * matrix, int nrow, int ncol) {
for (int i = 0; i < nrow; i++) {
for (int j = 0; j < ncol; j++) {
@ivan-krukov
ivan-krukov / matplot.R
Created December 9, 2013 20:00
Matrix plotting in R
#this is a simple way to plot a matrix from a txt file
mat_data_frame=read.table("data.txt",header=F)
#rev is there to start plotting M(0,0) in the upper left corner
#col=rainbow(10) uses the rainbow color palette. You can find other ones here:
#http://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/palettes.html
image(as.matrix(rev(mat_data_frame)),col=rainbow(10))
@ivan-krukov
ivan-krukov / clone_all.sh
Last active March 17, 2016 03:34
Clone all repos for a given user
#Get repo list, filter git urls
GITHUB_NAME=octocat
curl https://api.github.com/users/$GITHUB_NAME/repos > github_response
for repo in `cat github_response | jq -r '.[] | .git_url'`; do;
git clone $repo;
done
@ivan-krukov
ivan-krukov / R_ify.R
Created March 30, 2016 16:18
Use dots instead of dollar signs in R
# Use dots (.) instead of ($)
R_ify <- function(expr) eval(parse(text=
gsub("\\.","$",substitute(expr))))
R_ify(mtcars.mpg)
@ivan-krukov
ivan-krukov / print_vector.cpp
Created April 19, 2016 21:56
Print vectors in C++, easy as `cout << vector << endl`
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "[";
typename vector<T>::const_iterator it;
for (it = v.begin(); it != v.end() - 1; ++it) {
os << *it << ", ";
}
os << *(it) << "]";
return os;
}
@ivan-krukov
ivan-krukov / multinomial.cpp
Created April 21, 2016 15:11
Generating multinomial random variates via the binomial conditional method
#include <vector>
#include <numeric>
#include <random>
using namespace std;
template <typename T>
T sum(vector<T> v) {
return accumulate(v.begin(), v.end(), 0.0);
}
@ivan-krukov
ivan-krukov / README.md
Last active April 27, 2016 21:53
Get ENSEMBL IDs for a given KEGG pathway

Problem

For a given KEGG pathway, we want to get a list of all the genes. Ensembl IDs are convenient here.

KEGG provides a REST API for some tasks, but is far from complete. For example, it is possible to map from KEGG to NCBI IDs, but not to Ensembl IDs.

The implementation peforms the following steps: