Skip to content

Instantly share code, notes, and snippets.

View timothymillar's full-sized avatar

Tim Millar timothymillar

View GitHub Profile
@timothymillar
timothymillar / rough_chunked_kinship.py
Last active April 10, 2024 09:12
Example of manually calculating kinship in chunks for a large pedigree
# %%
# # Rough chunked kinship with sgkit
#
# This is a rough example of calculating kinship in chunks with sgkit.
# It is not well optimised and can be very slow in practice.
# It will also be less effective in deep pedigrees with many genertions
# because calculating each chunk of the kinship matrix will require
# calculating the kinship matrix of the sample in that chun *and* their
# ancestors.
#
@timothymillar
timothymillar / Zarr-sgkit-figure.tex
Created December 22, 2023 02:20
Zarr-sgkit-figure
\documentclass{article}
\usepackage{forest}
\usepackage{tikz}
\usetikzlibrary{quotes,arrows.meta,3d}
\title{Zarr-sgkit}
\author{Tim Millar}
\date{December 2023}
%% flexible cuboid from
@timothymillar
timothymillar / cohorts.py
Created December 10, 2021 04:01
Test cohort reductions for sgkit
import numpy as np
import dask.array as da
from numba import guvectorize
from sgkit.typing import ArrayLike
import sgkit as sg
from typing import Any, Callable, Hashable, Iterable, Optional, Tuple, Union
@timothymillar
timothymillar / simple.output.mixed_depth.likelihoods.vcf
Last active July 7, 2021 08:32
Example VCFs with fields of length G
##fileformat=VCFv4.3
##fileDate=20210420
##source=mchap v0.4.2
##phasing=None
##commandline="mchap assemble --bam simple.sample1.bam simple.sample2.deep.bam simple.sample3.bam --ploidy 4 --targets simple.bed.gz --variants simple.vcf.gz --reference simple.fasta --mcmc-steps 500 --mcmc-burn 100 --mcmc-seed 11 --genotype-likelihoods"
##randomseed=11
##contig=<ID=CHR1,length=60>
##contig=<ID=CHR2,length=60>
##contig=<ID=CHR3,length=60>
##FILTER=<ID=PASS,Description="All filters passed">
@timothymillar
timothymillar / cbnb.filter.py
Last active June 28, 2020 07:49
A pandoc filter for converting jupytext or similar markdown to a codebraid notebook
#!/usr/bin/env python
"""A Pandoc filter to convert jupytext (or similar)
markdown to a codebraid "notebook".
"""
from pandocfilters import toJSONFilter, CodeBlock
def get_jupyter_kernel(data):
@timothymillar
timothymillar / flatten.py
Created May 21, 2020 22:38
Generic flatten function for Python
def flatten(obj, *args, depth=1):
"""Generic function for flattening nested sequences.
Parameters
----------
obj : iterable
iterable sequence
args : list of type
one or more iterable types to flatten
depth : int
@timothymillar
timothymillar / read_shell.py
Created November 5, 2018 21:13
Read the result of a shell command into a pandas dataframe
#! /usr/bin/env python3
import io
import subprocess
import pandas
def read_shell(command, **kwargs):
"""
Takes a shell command as a string and and reads the result into a Pandas DataFrame.
@timothymillar
timothymillar / PythonLearningResources.md
Last active July 10, 2019 23:05
Python Learning Resources

Python Learning Resources

Getting Started with Python

There are a huge range of tutorials and books available for learning Python. There are a couple things to watch out for when selecting learning material:

  1. Python 2 & 3 are very similar but subtly different languages. This can be a bit of a pain point when first learning Python so be aware of what version a tutorial or book is demonstrating. I highly recommend sticking to Python 3 as Python 2 is slowly being phased out of existence.
  2. Python is a very general purpose language (e.g. compared to R) so a lot of material is focused on web development, games and etc. The style of code used can be different between these topics so try to find learning material from an appropriate domain.

Bellow is a list of resources that are generally more focussed towards science and numerical programming rather than other topics (e.g. web development). I have used parts of most of these or otherwise trust the source of the material.

# For complete documentation of this file, please see Geany's main documentation
[styling=Lisp]
[keywords]
# all items must be in one line
keywords=abs acos and angle append apply asin assoc assq assv atan begin boolean? caar cadr call-with-current-continuation call-with-input-file call-with-output-file call-with-values car case cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cond cons cos current-input-port current-output-port define define-syntax delay denominator display do dynamic-wind else eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt floor for-each force gcd if imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lambda lcm length let let* let-syntax letrec letrec-syntax list list->string list