Skip to content

Instantly share code, notes, and snippets.

View RasmusFonseca's full-sized avatar

Rasmus Fonseca RasmusFonseca

View GitHub Profile
@RasmusFonseca
RasmusFonseca / multiproducer-consumer.py
Last active November 12, 2021 18:56
Python multiple producer / single consumer example
from multiprocessing import Process, Queue
def square_producer(inputqueue, resultqueue):
"""
A producer that pops numbers off the inputqueue, squares them and puts the result on resultqueue
"""
while True:
num = inputqueue.get()
if num is None:
@RasmusFonseca
RasmusFonseca / astar.py
Last active July 21, 2020 07:18
A-star search with examples
import numpy as np
from collections import defaultdict
from typing import List, Tuple
from math import sqrt, pow
I = 1000 # Infinity
@RasmusFonseca
RasmusFonseca / flareplot-main.js
Created May 9, 2019 06:31
Flareplot main script with tracks moved toward center
/**
* Creates a flareplot svg in the container matched by the `containerSelector`, sets its width to `width` pixels,
* and associates it with the contents of `json`
* @param width
* @param inputGraph
* @param containerSelector
* @returns {{getNumFrames, setFrame, framesIntersect, framesSum, setTrack, setTree, getTreeNames, getTrackNames, addNodeToggleListener, addNodeHoverListener, addEdgeToggleListener, addEdgeHoverListener, graph}}
*/
function createFlareplot(width, inputGraph, containerSelector){
@RasmusFonseca
RasmusFonseca / sysusg.py
Last active July 2, 2018 20:16
Monitor CPU-time and max memory usage using ps
"""
Monitors a process using the `ps` command and records total CPU-time and maximum memory usage.
Example usage:
./runMyCommand &
sysusg.py runMyCommand
"""
import subprocess
import sys
import time
@RasmusFonseca
RasmusFonseca / scrollable-table.html
Created May 19, 2017 20:18
Scrollable table body
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
<style>
* {
box-sizing: border-box;
}
td, th{
/**
* Creates a tree and track selector for `flareplot` within `container`.
*
* If there are more than one tree in the graph a div will be added containing
* radio buttons to switch between them. If the graph has more than one track
* they'll be added in a div after. If there is only one tree and one track the
* container will be left untouched. The resulting layout will look as follows:
* <code>
* <div id="container">
{
"embeddings": [
{
"tensorName": "My tensor",
"tensorShape": [
1000,
50
],
"tensorPath": "https://gist.githubusercontent.com/RasmusFonseca/b4ca7261eab30d65b3376d2af2ca46ed/raw/610b1e1ef87464769277888f192f7eb60e6dabb3/allmoments.tsv",
"metadataPath": "https://gist.githubusercontent.com/RasmusFonseca/726d1b5508ec47c10d90641d71e3c7f2/raw/75788561e40b4ade4fc6981223b252cb545dbaa0/momentmetadata.tsv"
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
100D
101D
102D
103D
104D
109D
10MH
111D
112D
113D
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 30 columns, instead of 27. in line 4.
1.0000 1.3360 1.5382 1.6889 1.8106 1.9127 2.0003 2.0765 2.1437 2.2033 2.2568 2.3049 2.3486 2.3885 2.4249 2.4585 2.4895 2.5181 2.5448 2.5697 2.5929 2.6147 2.6352 2.6544 2.6726 2.6898 2.7061 2.7215 2.7362 2.7501
1.0000 1.3915 1.6346 1.8079 1.9395 2.0436 2.1287 2.2000 2.2611 2.3142 2.3612 2.4032 2.4412 2.4758 2.5076 2.5371 2.5645 2.5901 2.6142 2.6369 2.6584 2.6787 2.6979 2.7163 2.7337 2.7503 2.7661 2.7812 2.7956 2.8094
1.0000 1.3886 1.6307 1.8047 1.9379 2.0441 2.1312 2.2042 2.2667 2.3208 2.3683 2.4106 2.4485 2.4827 2.5140 2.5427 2.5693 2.5940 2.6171 2.6388 2.6593 2.6787 2.6971 2.7147 2.7314 2.7475 2.7628 2.7775 2.7917 2.8053
1.0000 1.4091 1.6618 1.8415 1.9783 2.0868 2.1758 2.2504 2.3143 2.3697 2.4186 2.4621 2.5012 2.5367 2.5692 2.5990 2.6266 2.6524 2.6764 2.6989 2.7201 2.7402 2.7591 2.7772 2.7943 2.8106 2.8261 2.8410 2.8552 2.8688
1.0000 1.3511 1.5648 1.7225 1.8484 1.9535 2.0435 2.1219 2.1910 2.2523 2.3071 2.3564 2.4008 2.4411 2.4778 2.5113 2.5421 2.5705 2.5966 2.6209 2.6435 2.6645 2.6841 2.7025 2.7198 2.7360 2.
@RasmusFonseca
RasmusFonseca / extractFeatures.py
Created January 2, 2017 21:38
Extracting protein features as .tsv using blosum62 from a fasta file
import numpy as np
import sys
# Amino acid substitution matrix
blosum62 ={
"C":[9,-1,-1,-3,0,-3,-3,-3,-4,-3,-3,-3,-3,-1,-1,-1,-1,-2,-2,-2],
"S":[-1,4,1,-1,1,0,1,0,0,0,-1,-1,0,-1,-2,-2,-2,-2,-2,-3],
"T":[-1,1,4,1,-1,1,0,1,0,0,0,-1,0,-1,-2,-2,-2,-2,-2,-3],
"P":[-3,-1,1,7,-1,-2,-1,-1,-1,-1,-2,-2,-1,-2,-3,-3,-2,-4,-3,-4],
"A":[0,1,-1,-1,4,0,-1,-2,-1,-1,-2,-1,-1,-1,-1,-1,-2,-2,-2,-3],