Skip to content

Instantly share code, notes, and snippets.

View pansapiens's full-sized avatar

Andrew Perry pansapiens

  • Melbourne, Australia
View GitHub Profile
@pansapiens
pansapiens / standalone_html.py
Last active November 6, 2024 11:04
Convert HTML to a self contained file with inline Base64 encoded PNG images
#!/usr/bin/env python
# A simple script to suck up HTML, convert any images to inline Base64
# encoded format and write out the converted file.
#
# Usage: python standalone_html.py <input_file.html> <output_file.html>
#
# TODO: Consider MHTML format: https://en.wikipedia.org/wiki/MHTML
import os
from bs4 import BeautifulSoup
@pansapiens
pansapiens / ollama-export.sh
Last active September 25, 2024 15:31 — forked from supersonictw/ollama-export.sh
Ollama Model Export Script
#!/bin/bash
# Ollama Model Export Script
# Usage: bash ollama-export.sh vicuna:7b
# License: MIT (https://ncurl.xyz/s/o_o6DVqIR)
# https://gist.github.com/supersonictw/f6cf5e599377132fe5e180b3d495c553
set -e
echo "Ollama Model Export Script"
echo "License: MIT (https://ncurl.xyz/s/RD0Yl5fSg)"
@pansapiens
pansapiens / views.py
Created February 20, 2018 01:26
Django REST Framework CSV parser, RFC 4180
from typing import Dict, List
import csv
from rest_framework import status
from rest_framework.response import Response
from rest_framework.parsers import JSONParser, BaseParser
from rest_framework.views import APIView
class CSVTextParser(BaseParser):
"""
A CSV parser for DRF APIViews.
@pansapiens
pansapiens / README.md
Created November 9, 2023 03:53
Gzip compression heatmap

Gzip compression heatmap

Generates a heatmap plot showing the compression ratio of different block through a file.

Show interesting patterns in FASTQ files, and may be useful for diagnosing pathological or unusual data. I find using the zscore transformation for the plot is more informative.

Run like:

./compression_heatmap.py -b 1048576 -c rainbow -t zscore SRR11794587_2.fastq.gz
@pansapiens
pansapiens / .bashrc
Last active July 26, 2024 00:58
Some SLURM aliases
alias default_account='sacctmgr --parsable2 show user -s andrewpe | tail -1 | cut -f 2 -d '\''|'\'''
alias fairshare='sshare -a --accounts $(default_account)'
alias jhistory='sacct -u ${USER} --starttime $(date -d "-1 month" +%Y-%m-%d) --format=User,JobID,Jobname,partition,state,exitcode,time,start,end,elapsed,MaxRss,MaxVMSize,nnodes,ncpus,nodelist'
alias jshow='scontrol show job'
alias jinfo='sacct --starttime $(date -d "-1 month" +%Y-%m-%d) --format=User,JobID,Jobname%64,partition,qos,ReqCPUS,ReqMem,state,exitcode,time,start,end,elapsed,MaxRss,MaxVMSize,nnodes,ncpus,nodelist -j'
alias node_types='sinfo -o '\''%c %m %n %R'\'' --sort '\''P'\'''
alias qhogs='sreport cluster UserUtilizationByAccount -t hours'
alias si='sinfo -o "%20P %5D %14F %8z %10c %10m %10d %11l %16f %N"'
alias sq='squeue -o "%8i %.60j %4t %10u %20q %20a %10g %20P %10Q %5D %2C %5m %11l %11L %R"'
alias squ='squeue -u $USER --format="%.18i %.9P %.60j %.8u %.8a %.2t %.10M %.6D %R"'
@pansapiens
pansapiens / mirdeep_csv_to_counts.py
Created May 21, 2024 08:10
Convert miRDeep2 counts CSV to nicer TSV tables
#!/usr/bin/env python
import argparse
import pandas as pd
import re
import sys
from typing import Optional, List
import logging
import glob
import io
@pansapiens
pansapiens / appengine_leveldb2json.py
Last active July 13, 2024 05:34 — forked from xlfe/export.py
Export from Google App Engine Datastore Backup LevelDB format to JSON flat file
#!/usr/bin/env python2.7
# Export from Google App Engine Datastore Backup LevelDB format to JSON flat file
# Based on: https://gist.github.com/xlfe/af25f160256e4d52f499dee7e8fa212f
##
# 2024 instructions:
##
# Using the Google Cloud console (https://console.cloud.google.com), find "Firestore"
# and export your database to a Cloud Storage "Bucket". Download the content of the Bucket.
@pansapiens
pansapiens / .a_README.md
Last active June 13, 2024 03:25
schollz/hostyoself docker-compose
@pansapiens
pansapiens / bam2fq_softclip.py
Created June 13, 2024 03:22
Extract mapped reads from BAM, lowercase masking soft-clipping
#!/usr/bin/env python
###
# bam2fq_softclip.py
###
# A script for exploring soft-clipping of aligned reads.
# Extracts mapped reads from a BAM file as a FASTQ, but encodes 'soft-clipped' regions
# as lowercase. Soft-clipped regions can be quickly visualized in the terminal like:
#
# ./bam2fq_softclip.py aligned.bam | grep --color=always [atcg] |less -R
@pansapiens
pansapiens / 0README.md
Last active May 20, 2024 16:56
RStudio Server in Singularity (via rocker), M3 HPC flavour