This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assume inputs are lists | |
def merge1(words, more): | |
sentence = "" | |
for w in words: sentence += w | |
for w in more: sentence += w | |
return sentence | |
def merge2(words, more): | |
sentence = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
cigar = "32M1I89M1D7M1D37M1D16M1I71M1I12M1I18M1I19M3S" | |
matches = re.findall("([0-9]+)([A-Z]+)", cigar) | |
for length, operation in matches: | |
print operation, length |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct { | |
int start; | |
int end; | |
} range_t; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ifs can have a value | |
val configFile = new java.io.File("~/.myapprc") | |
val configFilePath = if (configFile.exists()) { | |
configFile.getAbsolutePath() | |
} | |
else { | |
configFile.createNewFile() | |
configFile.getAbsolutePath() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer