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 / makefile
Last active August 29, 2015 13:55
Float array returns with python ctypes
numbers.so: numbers.c
gcc --std=c99 -fPIC -c numbers.c
gcc -shared numbers.o -o numbers.so
clean:
rm -f numbers.o numbers.so
@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 / 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 / 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 / perl-cpp-arrays.pl
Created November 5, 2013 20:26
Using Perl Inline::CPP and perlapi to pass around array data
#!/usr/bin/perl
use warnings;
#not sure how to use strict here - does not allow bareword in "Inline CPP"
use Inline CPP;
my @data = (0..10);
my $result_ref = do_stuff(\@data);
my @result = @$result_ref;
print "@result\n";
__END__
__CPP__
@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 / 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 / ftp-download.py
Created June 6, 2013 03:50
Complete download file over FTP example. Complete with write-report closure in python3 style, writing stdout to same line and nice verbosity handling
#!/usr/bin/env python3
from ftplib import FTP
def ftp_download(server,remote_path,local_path,username="anonymous",password="",verbose=True):
#new ft object
ftp = FTP(server)
if verbose: print("Connected to %s"%server)
#notice that default login is "anonymous" with no password. works on most public servers
@ivan-krukov
ivan-krukov / lcsm.py
Created June 5, 2013 19:04
lcsm problem on Rosalind
#!/usr/bin/env python
import fastaparse
import sys
sequences = [i.seq for i in fastaparse.parse_fasta(sys.argv[1])]
def substrings(string):
n = len(string)
for length in range(n,0,-1):
@ivan-krukov
ivan-krukov / qw.py
Created May 31, 2013 20:23
A little perl-like qw function for interactive work
def qw(s,t=str):
return list(map(t,s.split()))