Skip to content

Instantly share code, notes, and snippets.

View mylons's full-sized avatar

Mike Lyons mylons

  • Incline Village, NV
View GitHub Profile
@mylons
mylons / gist:1287733
Created October 14, 2011 17:24
simple wrappers to pyplot
import matplotlib.pyplot as pyplot
def plot_list(xs, ys, clf=False, label=None):
if clf:
pyplot.clf()
line = pyplot.plot(xs, ps, label=name)
def make_plots(lists_of_x, lists_of_y):
#assumes they're equal length lists of lists [ [ ] ]
for i in xrange(lists_of_x):
@mylons
mylons / gist:1287777
Created October 14, 2011 17:42
lol @ perl
import re
cigar = "32M1I89M1D7M1D37M1D16M1I71M1I12M1I18M1I19M3S"
matches = re.findall("([0-9]+)([A-Z]+)", cigar)
for length, operation in matches:
print operation, length
while ($md =~ /(\d+)(\^?)([ACGTN]+)/g) {
if ($2) { # deletion
$read_pos += $1; # increment the matching length
} elsif ($3) { # mismatch
$read_pos += $1 + 1; # increment the matching length, then 1 for the mismatch
#print STDERR "MD: $1 $3 read_pos $read_pos md_map $md_map[$read_pos]\n"; ##-#
if ($line[1] & 0x0010) { # reverse read
$errors[$read_len - $md_map[$read_pos] - 1]++; # = 1 unless $errors[$read_len -
md_map[$read_pos] - 1]; ###
} else { # forward read
@mylons
mylons / banding.c
Created November 1, 2011 14:53
combines ranges assuming a sorted array by start position
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int start;
int end;
} range_t;
@mylons
mylons / gist:1331583
Created November 1, 2011 19:13
new banding code for tmap
if(end + 1 < sams->n) {
if(sams->sams[end].strand == sams->sams[end+1].strand //same strand
&& sams->sams[end].seqid == sams->sams[end+1].seqid) {
sam_start = sams->sams[end].pos;
sam_end = sams->sams[end].pos + sams->sams[end].target_len;
sam_next_start = sams->sams[end+1].pos;
sam_next_end = sam_next_start + sams->sams[end+1].target_len;
if ( (sam_next_end > sam_end) && ((sam_next_end - sam_end) <= opt->max_seed_band) ) {
end++;
keep_banding = 1;
@mylons
mylons / gist:1353320
Created November 9, 2011 22:24
super split!
import os
def super_split(absolute_path):
fdir, fname = os.path.split(absolute_path)
tokens = fname.split('.')
ext = tokens[-1]
fname_no_ext = '.'.join( [ x for x in tokens[:len(tokens)-1] ])
return fdir, fname_no_ext, ext
//ifs can have a value
val configFile = new java.io.File("~/.myapprc")
val configFilePath = if (configFile.exists()) {
configFile.getAbsolutePath()
}
else {
configFile.createNewFile()
configFile.getAbsolutePath()
}
#!/usr/bin/env python
import sys
import itertools
import collections
def Kdiff(nums, k):
return sum(1 for x, y in itertools.combinations(nums, 2) if (x-y) == k)
def ErrorAndExit():
print "0"
sys.exit()
class Singleton:
__single = None
def __init__( self ):
if Singleton.__single:
raise Singleton.__single
#this line of code is never reached
#if __single already exists
Singleton.__single = self
try {
BufferedReader in = new BufferedReader(new FileReader(pwd + "Makefile"));
String str;
while((str = in.readLine()) != null)
System.out.println(str);
in.close();
} catch (FileNotFoundException e) {