Skip to content

Instantly share code, notes, and snippets.

@cth
cth / README.md
Last active February 22, 2016 09:03 — forked from anonymous/README.md

Markdown based testing of files

This is a markdown based language for specification of testcases for files in a filesystem. Ideally a set of files may be described and at the same time formal specifications about the files can be specified using test cases written in, e.g., shell scripts embedded as code-blocks.

Overview

@cth
cth / swapgeno.rb
Created September 22, 2014 10:51
Script to swap alleles in imputed .gprobs files (genotype likelihoods), e.g., from IMPUTE2
# Script to swap alleles in imputed .gprobs files (genotype likelihoods), e.g., from IMPUTE2
# ruby swapgeno.rb genotypes.gprobs swap_snps.txt swapped.gprobs
# swap_snps.txt is a list of SNPs for which genotypes should be swapped (one per line in file)
# Read list of snps to swap
swap_snps = {}
File.open(ARGV[1]) { |sf| sf.each { |l| swap_snps[l.chomp] = true } }
File.open(ARGV[2],"w") do |outfile|
File.open(ARGV[0]) do |file|
@cth
cth / nth.sh
Created March 12, 2014 11:43
Select index of a particular named argument
function nth() {
target=$1
shift
idx=1
for symbol in $@; do
if [ $symbol == $target ]; then
echo $idx
return
fi
idx=$(($idx+1))
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JComponent;
public class RectangleComponent extends JComponent {
public void paintComponent(Graphics g) {
// Recover Graphics2D
Graphics2D g2 = (Graphics2D)g;
@cth
cth / prism_switch_html.pl
Created May 2, 2011 07:37
A prolog program that creates a colored HTML document for visualizing PRISM parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% A simple script to create a visual report of PRISM parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% May 2011, Christian Theil Have
%
% usage: prism_switch_html(PRISM_SWITCH_FILE, HTML_OUTPUT_FILE).
%
:- table int_to_hex/2.
#!/usr/bin/env ruby
# Simple utility to remove trailing space in the end of lines
# Takes as first argument the file to be processed.
lines = []
File.open(ARGV[0]).each do |line|
line.reverse =~ /\s*(.*)/
lines << $1.reverse
end
#!/usr/bin/ruby
if ARGV.length != 1
puts "Usage: ./average_experiments experiment_directory\n\n"
puts "Computes the average over a number of experiment data files"
puts "located in the directory given as first argument. "
puts "The experiment files are expected to contain an equal number lines "
puts "with an equal number of entries. Each entry is expected to be a number"
puts "and entries are expected to be separated by space."
exit
#!/usr/bin/env ruby
# Christian Theil Have, Sep. 2009.
require 'rubygems'
require 'xmlsimple'
class String
def to_prolog
"'" + self.gsub("'",'\\\\\'') + "'"
end
@cth
cth / gist:168989
Created August 17, 2009 07:59
A simple O(n^2) DFA minimization implementation in CHR
% DFA minimization
:- use_module(library(chr)).
:- chr_constraint trans/3, state/1, same/2, different/2, final/1, non_final/1, state_order/2.
% A simple test DFA for arithmetic expressions
test :-
final(s3),
trans('(', s1, s1),
@cth
cth / simplehmm2prism.pl
Created August 13, 2009 16:16
Convert a HMMs in simplistic fact format to a PRISM program
:- use_module(library(chr)).
:- set_prolog_flag(chr_toplevel_show_store,false).
simplehmm2prism(InputFile,OutputFile) :-
read_hmm(InputFile),
write_hmm(OutputFile).
% These rules are only used as template for creating
hmm(L) :- msw(trans(start),S0),hmm(S0,L).