Skip to content

Instantly share code, notes, and snippets.

View davipatti's full-sized avatar

David Pattinson davipatti

  • UW-Madison
  • New York, USA
View GitHub Profile
#!/usr/bin/env python3
import time
import random
from typing import Generator, Iterable
def extend_loop(boxes: tuple[int, ...], loop: list[int], pointer: int) -> tuple[int, ...]:
"""
@davipatti
davipatti / serosolver-1.0.1-compilation-error.txt
Created July 27, 2022 15:43
Compilation error trying to install serosolver 1.0.1
> devtools::install_github("seroanalytics/serosolver")
Downloading GitHub repo seroanalytics/serosolver@HEAD
✔ checking for file ‘/tmp/Rtmpw3v9xS/remotes52ad50a06bda/seroanalytics-serosolver-4b632c4/DESCRIPTION’ ...
─ preparing ‘serosolver’:
✔ checking DESCRIPTION meta-information ...
─ cleaning src
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
─ building ‘serosolver_1.0.1.tar.gz’
@davipatti
davipatti / full-width.py
Created April 20, 2022 00:01
Full width cells jupyter notebook cells
from IPython.core.display import display, HTML
display(HTML("<style>.container { width:100% !important; }</style>"))
@davipatti
davipatti / integrate-executables-in-linux.md
Created January 28, 2022 20:27
Integrate executable programs with the system launcher in Ubuntu

Integrate executable programs with the system launcher in Ubuntu

Occasionally you download some pre-compiled software. It can be a pain to remember where you put it, navigate there in a shell and run it.

Better would be if it were integrated with the desktop launchers so you can launch it like a regular program.

Information for this behaviour (like where the executable is, what the icon is, etc...) is defined by a .desktop file, which has to be put in a directory the system monitors. See here for more details.

I was recently wanted to do this with Zotero, and their instructions had some recommendations on how to set this up properly:

@davipatti
davipatti / remove_missing.py
Created September 1, 2021 14:54
[Remove missing data from pandas DataFrame] #pandas #python
import pandas as pd
def remove_missing(df: pd.DataFrame) -> pd.DataFrame:
"""
Remove missing data from a DataFrame.
Iteratively remove the column or row that contains the highest proportion of
missing data, until there is no missing data left.
"""
@davipatti
davipatti / extract-csv.r
Last active August 5, 2021 10:58
[Extracting CSV files from a Prism GraphPad .pzfx] #r #rscript #prism #graphpad
library(pzfx)
path = 'data.pzfx'
for (table in pzfx_tables(path))
{
filename = paste(sub(" ", "-", table), "csv", sep = ".")
df = read_pzfx(path, table=table)
write.csv(df, filename)
}
@davipatti
davipatti / README.md
Last active June 28, 2021 17:45
Quiet pymc3 info logging #pymc3 #python #logging

Running any model in pymc3 spits out a lot of info, even if everything is running fine:

import pymc3 as pm

with pm.Model():
    pm.Normal(
        "obs",
        mu=pm.Normal("mu", 0, 1),
 sigma=pm.Exponential("sigma", 1),
import sys
import csv
import networkx as nx
import matplotlib.pyplot as plt
"""
Expects CSV on stdin, containing weights of edges
,a,b,c
a,,2,3
@davipatti
davipatti / blast-pipe.py
Last active December 16, 2020 16:08
Driving NCBI BLAST from python without writing to disk
import os
from Bio.Blast.Applications import NcbiblastpCommandline
from Bio import SeqIO
# Grab any sequence to blast
with open("db.fasta", "r") as f:
record = next(SeqIO.parse(f, "fasta"))
read, write = os.pipe()
@davipatti
davipatti / pipe.py
Last active December 16, 2020 15:48
Getting my head around os.pipe in python
import os
read, write = os.pipe()
# Variable 'parent' is the process id of the parent fork
# It gets a value of 0 when the parent process exits
parent = os.fork()
if parent: