Skip to content

Instantly share code, notes, and snippets.

View jrjhealey's full-sized avatar

Joe Healey jrjhealey

View GitHub Profile
@jrjhealey
jrjhealey / prime_anagrams.py
Last active February 1, 2018 10:54
Work out if 2 words are anagrams based on their unique prime products.
#!/usr/bin/env python
"""
Using products of primes to work out whether 2 strings are anagrams of one another.
Inspired by: https://twitter.com/fermatslibrary/status/958700402647674880
Map each of the 26 english characters (A, B, C, ...) to a (unique) prime number.
Multiply the values mapped to each character together (A x B x C x ...).
Since every integer is a prime, or a unique product of primes, according to the
fundamental theorem of arithmetic), two words are anagrams of one another if their
#!/bin/bash
set -eo pipefail
# A small script to generate artemis comparison files (nucleic acid comparison)
# since all the webservers are apparently defunct!
# Script requires blastn (NOT LEGACY BLAST) and makeblastdb in path - check for existence:
command -v makeblastdb >/dev/null 2>&1 || { echo >&2 "makeblastdb doesn't appear to be installed. Aborting."; exit 1; }
command -v blastn >/dev/null 2>&1 || { echo >&2 "BLAST+ doesn't appear to be installed. Aborting."; exit 1; }
#!/usr/bin/env Rscript
# Perform cell-wise averaging of matrices (ignoring headers and row names)
# Standard install if missing
list.of.packages <- c("argparse", "abind")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
for(i in list.of.packages){suppressMessages(library(i, character.only = TRUE))}
@jrjhealey
jrjhealey / slice_genes.py
Last active September 18, 2023 09:33
Code to 'slice' or subset genbank format sequences from one gene specifier to another by looking up their locations.
#!/usr/bin/env python
# Slice subregions out of a genbank between 2 genes.
# Usage:
# slice_genes.py infile.gbk gene1:gene2:strand
from Bio import SeqIO
import sys, argparse
def get_args():
@jrjhealey
jrjhealey / seqcol.sh
Created October 10, 2018 11:49
Entirely uncessarily complex script to colour DNA sequences at arbitrary positions.. because...reasons? Even the help is colourful!
#!/bin/bash
# Set colours:
df=$(tput sgr0)
tr=$(tput setaf 1)
tg=$(tput setaf 2)
ty=$(tput setaf 3)
tb=$(tput setaf 4)
usage(){
@jrjhealey
jrjhealey / seqcol.sh
Created October 10, 2018 11:49
Entirely uncessarily complex script to colour DNA sequences at arbitrary positions.. because...reasons? Even the help is colourful!
#!/bin/bash
# Set colours:
df=$(tput sgr0)
tr=$(tput setaf 1)
tg=$(tput setaf 2)
ty=$(tput setaf 3)
tb=$(tput setaf 4)
usage(){
@jrjhealey
jrjhealey / README.rst
Created November 15, 2018 17:30 — forked from sublee/README.rst
Finger Binary ASCII art generator for Python

Finger Binary

What's Finger Binary?

Here is a description of Finger Binary in Wikipedia.

Finger binary is a system for counting and displaying binary numbers on the

@jrjhealey
jrjhealey / Orthologies_over_time.tsv
Created November 20, 2018 15:48
Results of HHPred homology queries
We can't make this file beautiful and searchable because it's too large.
PVCpnf_1 PAU_03353 PAU_03392 5W5F 5W5F_F 99.4 1.7e-16 2.8e-21 108.8 >5W5F_F Tail tube protein gp19; T4 tail tube, dose limit;{Enterobacteria phage T4 sensu lato}
PVCpnf_2 PAU_03352 PAU_03391 3J9Q 3J9Q_B 100.0 3.6e-34 6e-39 243.2 >3J9Q_B sheath, tube; pyocin, bacteriocin, sheath, tube, STRUCTURAL; 3.5A {Pseudomonas aeruginosa}
PVCpnf_3 PAU_03351 PAU_03390 3J9Q 3J9Q_B 99.9 8.9e-32 1.5e-36 234.4 >3J9Q_B sheath, tube; pyocin, bacteriocin, sheath, tube, STRUCTURAL; 3.5A {Pseudomonas aeruginosa}
PVCpnf_4 PAU_03350 PAU_03389 3J9Q 3J9Q_B 99.9 9.3e-28 1.6e-32 207.6 >3J9Q_B sheath, tube; pyocin, bacteriocin, sheath, tube, STRUCTURAL; 3.5A {Pseudomonas aeruginosa}
PVCpnf_5 PAU_03349 PAU_03388 5IV5 5IV5_I 99.0 2.4e-13 4e-18 93.6 >5IV5_IB Baseplate wedge protein gp6, Baseplate; T4, baseplate-tail tube complex, pre-attachment; 4.11A {Enterobacteria phage T4}
PVCpnf_6 PAU_03348 PAU_03387 3SLS 3SLS_B 75.1 1.5 2.5e-05 26.7 >3SLS_B Dual specificity mitogen-activated protein kinase; Serine-threonine kinase, Signalling, TRANSFER
@jrjhealey
jrjhealey / PythonColours.py
Last active April 4, 2024 01:03
Basics of python string colouring with ANSI codes
#Copy to a script and run in a terminal to see the codes and their results (this is not an exhaustive list)
print("\033[0;37;40m Normal text\n")
print("\033[2;37;40m Underlined text\033[0;37;40m \n")
print("\033[1;37;40m Bright Colour\033[0;37;40m \n")
print("\033[3;37;40m Negative Colour\033[0;37;40m \n")
print("\033[5;37;40m Negative Colour\033[0;37;40m\n")
print("\033[1;37;40m \033[2;37:40m TextColour BlackBackground TextColour GreyBackground WhiteText ColouredBackground\033[0;37;40m\n")
print("\033[1;30;40m Dark Gray \033[0m 1;30;40m \033[0;30;47m Black \033[0m 0;30;47m \033[0;37;41m Black \033[0m 0;37;41m")
print("\033[1;31;40m Bright Red \033[0m 1;31;40m \033[0;31;47m Red \033[0m 0;31;47m \033[0;37;42m Black \033[0m 0;37;42m")
@jrjhealey
jrjhealey / align_and_remap.sh
Created January 15, 2019 09:09
Aligning and remapping reads to a reference.
#!/bin/bash
# Script to align fastq reads to a given reference, and output the necessary files sorted etc.
# Script requires bwa and samtools in path - check for existence:
command -v bwa >/dev/null 2>&1 || { echo >&2 "BWA doesn't appear to be installed. Aborting."; exit 1; }
command -v samtools >/dev/null 2>&1 || { echo >&2 "samtools doesn't appear to be installed. Aborting."; exit 1; }
# Capture inputs