Skip to content

Instantly share code, notes, and snippets.

View mobiusklein's full-sized avatar

Joshua Klein mobiusklein

View GitHub Profile
@mobiusklein
mobiusklein / xcorr_score.py
Last active October 2, 2019 17:07
A simple implementation of the Xcorr score algorithm.
import numpy as np
# These methods assume that x and y have been normalized by dividing by their maximum value in order
# to get xcorr scores comparable to those seen in common Sequest-ish search engines.
def xcorr_score(x, y, k=75):
'''Based on blogpost by Will Fondrie:
https://willfondrie.com/2019/02/an-intuitive-look-at-the-xcorr-score-function-in-proteomics/
'''
y_p = y * 0
@mobiusklein
mobiusklein / numfoo.pyx
Created April 25, 2019 22:07
`implement_array_function method already has a docstring` Minimal Reproducible Example
cimport cython
import numpy as np
cimport numpy as np
np.import_array()
ctypedef cython.floating floating_t
ctypedef fused numeric_collection:
@mobiusklein
mobiusklein / levmarq.c
Created November 9, 2015 01:02 — forked from rbabich/ levmarq - Levenberg-Marquardt in plain C
A simple implementation of the Levenberg-Marquardt algorithm in plain C
/*
* levmarq.c
*
* This file contains an implementation of the Levenberg-Marquardt algorithm
* for solving least-squares problems, together with some supporting routines
* for Cholesky decomposition and inversion. No attempt has been made at
* optimization. In particular, memory use in the matrix routines could be
* cut in half with a little effort (and some loss of clarity).
*
* It is assumed that the compiler supports variable-length arrays as
#!/home/inorton/bin/pywin
import comtypes, comtypes.client
from ctypes import *
from comtypes.automation import *
import sys
import numpy
# GetMassListFromScanNum(long FAR* pnScanNumber, LPCTSTR szFilter,
# long nIntensityCutoffType, long nIntensityCutoffValue,
# long nMaxNumberOfPeaks, BOOL bCentroidResult,
// Utility
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// On Ready Handler
$(function(){
import sqlitedict
import psutil
from uuid import uuid4
class ResourceTracker(object):
def __init__(self, cpu_usage_total=0, memory_usage_total=0, runtime_total=0, pid=None):
self.cpu_total = cpu_usage_total
self.memory_total = memory_usage_total
self.runtime_total = runtime_total
self.pid = pid
@mobiusklein
mobiusklein / compress.js
Last active August 29, 2015 14:09
Different methods of testing browserify-zlib against python gzip
var zlib = require("zlib"),
fs = require("fs");
var datum = new Buffer(JSON.stringify({cats: [1, 2]}))
zlib.gzip(datum, function(error, results){
if (error !== null){
throw error
}
console.log(results)
@mobiusklein
mobiusklein / subprocess_with_logging_control.py
Created November 6, 2014 02:44
Subprocess with logging files
import os
import random
import subprocess
root_log_dir = "./log_home"
def get_random_file_name(length=25):
rand_part = ''.join([chr(random.randint(65,122)) for i in range(length)])
return "logfile_%s.txt" % randpart
@mobiusklein
mobiusklein / matrixHierarchicalClustering.R
Created September 23, 2014 21:25
Do the hierarchical clustering a heatmap does, without the heatmap
matrixHierarchicalClustering <- function (x, Rowv = NULL, Colv = if (symm) "Rowv" else NULL,
distfun = dist, hclustfun = hclust, reorderfun = function(d,
w) reorder(d, w), add.expr, symm = FALSE, revC = identical(Colv,
"Rowv"), scale = c("row", "column", "none"), na.rm = TRUE,
margins = c(5, 5), ColSideColors, RowSideColors, cexRow = 0.2 +
1/log10(nr), cexCol = 0.2 + 1/log10(nc), labRow = NULL,
labCol = NULL, main = NULL, xlab = NULL, ylab = NULL, keep.dendro = FALSE,
verbose = getOption("verbose"), ...)
{
scale <- if (symm && missing(scale))
import csv
tsvreader = csv.reader(open('my_file_name', 'rb'), delimiter = '\t')
best_matches = [match for match in [line for line in tsvreader] if int(match[2]) == 100]