Skip to content

Instantly share code, notes, and snippets.

View jrjhealey's full-sized avatar

Joe Healey jrjhealey

View GitHub Profile
@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 / 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 / fastafetcher.py
Created September 13, 2017 21:47
Pull out fastas from a multifasta based on keyword search as a string or keyfile
# Extract fasta files by their descriptors stored in a separate file.
# Requires biopython
from Bio import SeqIO
import sys
import argparse
def getKeys(args):
"""Turns the input key file into a list. May be memory intensive."""
#!/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; }
# This script will calculate Shannon entropy from a MSA.
# Dependencies:
# Biopython, Matplotlib [optionally], Math
"""
Shannon's entropy equation (latex format):
H=-\sum_{i=1}^{M} P_i\,log_2\,P_i
Entropy is a measure of the uncertainty of a probability distribution (p1, ..... , pM)
#!/usr/bin/ruby
# Create display override file to force Mac OS X to use RGB mode for Display
# see http://embdev.net/topic/284710
require 'base64'
data=`ioreg -l -d0 -w 0 -r -c AppleDisplay`
edids=data.scan(/IODisplayEDID.*?<([a-z0-9]+)>/i).flatten
vendorids=data.scan(/DisplayVendorID.*?([0-9]+)/i).flatten
@jrjhealey
jrjhealey / addingusers.sh
Last active February 10, 2020 12:56
Adding Server Users (reminder for myself)
# Step 1
# Add the user with
sudo adduser username
# Ensure a temporary password is given to the account else it remains locked
# other options can be left blank
# Add the username to the AllowedUsers field in /etc/ssh/sshd_config (on the server)
# Next step is often easier to do as the new user to avoid messing up file ownership
sudo -i -u newuser
@jrjhealey
jrjhealey / structfit.py
Created December 4, 2017 14:32
Connecting HHSuite to Chimera for visualitations of how similar 2 HMM PDBs are.
"""
This script pulls in homologs of proteins from PDB
as determined by HHSuite. It then employs pychimera and
UCSF Chimera to structurally match them and get an
indication of how well they score (RMSD) in order
to pick the best simulation.
"""
import os
import subprocess
import sys
@jrjhealey
jrjhealey / crop_to_fix.tex
Created June 19, 2019 09:33
A construct to enable, centered, cropped-to-fit content to be generated dynamically. Useful for equations/figures etc. This example uses TeXShade for sequence alignment.
\documentclass[a4paper, oneside, 11pt]{memoir} % Doc Setup
\usepackage[left=1cm, right=1cm, top=1cm, bottom=1cm]{geometry} % Doc Geometry
\usepackage{texshade}
\usepackage{lscape}
\usepackage[active, tightpage]{preview}
\begin{document}
\begin{landscape}
\begin{preview}
@jrjhealey
jrjhealey / RandomHumanKmers.txt
Created January 21, 2019 18:42
Generating N random kmers from the Human Genome (GRCh38)
# This gist contains 10 randomly selected kmers (9mers) from the reference human genome (GRCh38).
The following code was used to generate the output:
import re, sys
from Bio import SeqIO
import random
import time
k = 9
n = 10