Skip to content

Instantly share code, notes, and snippets.

Avatar
🌲
Genealogies

Ivan Krukov ivan-krukov

🌲
Genealogies
  • Canada
View GitHub Profile
@ivan-krukov
ivan-krukov / corr.pl
Created May 15, 2013
Solution to Rosalind CORR problem
View corr.pl
#!/usr/bin/env perl
use v5.14;
use warnings;
sub hamming {
my @a = split "", shift;
my @b = split "", shift;
my $distance = 0;
for (my $n = 0; $n < scalar(@a); $n++) {
unless (($a[$n]) eq ($b[$n])) {
@ivan-krukov
ivan-krukov / cons.py
Last active Dec 17, 2015
fancy consensus builder
View cons.py
#!/usr/bin/env python
#http://rosalind.info/problems/cons/
import fastaparse
letters = ["A","C","G","T"]
sequences = [i.seq for i in fastaparse.sequences("temp2")]
#create empty profile matrix
@ivan-krukov
ivan-krukov / time-update.sh
Created May 28, 2013
time resync and hwclock update (arch)
View time-update.sh
sudo ntpd -gq
sudo hwclock --systohc --utc
@ivan-krukov
ivan-krukov / fastaparse.py
Created May 29, 2013
Different ways of parsing fasta files. Last one is my favorite - generators and named tuples.
View fastaparse.py
#load everythin in memory
#split
def split_fasta(input_file):
with open(input_file) as fasta_file:
text = fasta_file.read().split(">")[1:]
data = []
for entry in text:
header,sequence = entry.split("\n",1)
sequence = sequence.replace("\n","")
@ivan-krukov
ivan-krukov / qw.py
Created May 31, 2013
A little perl-like qw function for interactive work
View qw.py
def qw(s,t=str):
return list(map(t,s.split()))
@ivan-krukov
ivan-krukov / lcsm.py
Created Jun 5, 2013
lcsm problem on Rosalind
View lcsm.py
#!/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 / ftp-download.py
Created Jun 6, 2013
Complete download file over FTP example. Complete with write-report closure in python3 style, writing stdout to same line and nice verbosity handling
View ftp-download.py
#!/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 / templater.py
Last active Dec 18, 2015
Template string wrapper. uses 'inspect' to get the caller namespace dict
View templater.py
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 Dec 20, 2015
Fasta grep. Search a fasta file with a pattern. Either a single query or a file with regexes
View grepseq.py
#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 / perl-cpp-arrays.pl
Created Nov 5, 2013
Using Perl Inline::CPP and perlapi to pass around array data
View perl-cpp-arrays.pl
#!/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__
You can’t perform that action at this time.