changeset 0:3723b54935cb draft

Uploaded
author mmaiensc
date Wed, 13 Nov 2013 16:13:17 -0500
parents
children 2086dd919b31
files ARTS/._ARTS.pl ARTS/.git/._description ARTS/.git/COMMIT_EDITMSG ARTS/.git/FETCH_HEAD ARTS/.git/HEAD ARTS/.git/config ARTS/.git/description ARTS/.git/hooks/README.sample ARTS/.git/index ARTS/.git/info/exclude ARTS/.git/logs/HEAD ARTS/.git/logs/refs/heads/master ARTS/.git/logs/refs/remotes/origin/master ARTS/.git/objects/23/a27cbd4eb27e3d498b4a7f8684122474eaff12 ARTS/.git/objects/36/d7f8954d184e225a9f3adf94f3cfc3bb7b86ce ARTS/.git/objects/54/a4951e3c5c45f409e70a985b0cea2455ae957e ARTS/.git/objects/55/8986773dda6bf91846f02b18a35c2fbb41a77b ARTS/.git/objects/59/e37ec92c80e295eee29cfe28f13b52a0306f0f ARTS/.git/objects/67/3f381f341d75f448fd82e0251c6411136e272c ARTS/.git/objects/81/59d9e699d4bd241500b9fe87550785c9442189 ARTS/.git/objects/94/3beea597c218662acd5a957a8c1b3c409d4862 ARTS/.git/objects/98/ac4760695f8e4565efb03f720a1574751b40c3 ARTS/.git/objects/a5/b4c893e5aa28015aa8f8efb38dee0abd477856 ARTS/.git/objects/bd/39087f25b3386a667a6744de4aa95642b0ad82 ARTS/.git/objects/e0/7c6c8ab6c5724f2b7600882631d6e367a848da ARTS/.git/refs/heads/master ARTS/.git/refs/remotes/origin/master ARTS/ARTS.pl ARTS/LICENSE ARTS/README ARTS/batched_data.txt ARTS/galaxy_arts.xml ARTS/galaxy_arts_score.xml ARTS/sample_data.txt
diffstat 33 files changed, 2038 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file ARTS/._ARTS.pl has changed
Binary file ARTS/.git/._description has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/COMMIT_EDITMSG	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,1 @@
+Update readme
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/HEAD	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,1 @@
+ref: refs/heads/master
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/config	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,12 @@
+[core]
+	bare = false
+	repositoryformatversion = 0
+	filemode = true
+	logallrefupdates = true
+	ignorecase = true
+[remote "origin"]
+	url = https://github.com/mmaiensc/ARTS.git
+	fetch = +refs/heads/*:refs/remotes/origin/*
+[branch "master"]
+	remote = origin
+	merge = refs/heads/master
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/description	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,1 @@
+Tools for study randomization
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/hooks/README.sample	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,5 @@
+#!/bin/sh
+#
+# Place appropriately named executable hook scripts into this directory
+# to intercept various actions that git takes.  See `git help hooks` for
+# more information.
Binary file ARTS/.git/index has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/info/exclude	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,2 @@
+# File patterns to ignore; see `git help ignore` for more information.
+# Lines that start with '#' are comments.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/logs/HEAD	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 bd39087f25b3386a667a6744de4aa95642b0ad82 mmaiensc <mmaiensc@gmail.com> 1384376349 -0600	commit (initial): Initial push
+bd39087f25b3386a667a6744de4aa95642b0ad82 54a4951e3c5c45f409e70a985b0cea2455ae957e mmaiensc <mmaiensc@gmail.com> 1384376504 -0600	commit: Update readme
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/logs/refs/heads/master	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,2 @@
+0000000000000000000000000000000000000000 bd39087f25b3386a667a6744de4aa95642b0ad82 mmaiensc <mmaiensc@gmail.com> 1384376349 -0600	commit (initial): Initial push
+bd39087f25b3386a667a6744de4aa95642b0ad82 54a4951e3c5c45f409e70a985b0cea2455ae957e mmaiensc <mmaiensc@gmail.com> 1384376504 -0600	commit: Update readme
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/logs/refs/remotes/origin/master	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,1 @@
+0000000000000000000000000000000000000000 54a4951e3c5c45f409e70a985b0cea2455ae957e mmaiensc <mmaiensc@gmail.com> 1384376550 -0600	update by push
Binary file ARTS/.git/objects/23/a27cbd4eb27e3d498b4a7f8684122474eaff12 has changed
Binary file ARTS/.git/objects/36/d7f8954d184e225a9f3adf94f3cfc3bb7b86ce has changed
Binary file ARTS/.git/objects/54/a4951e3c5c45f409e70a985b0cea2455ae957e has changed
Binary file ARTS/.git/objects/55/8986773dda6bf91846f02b18a35c2fbb41a77b has changed
Binary file ARTS/.git/objects/59/e37ec92c80e295eee29cfe28f13b52a0306f0f has changed
Binary file ARTS/.git/objects/67/3f381f341d75f448fd82e0251c6411136e272c has changed
Binary file ARTS/.git/objects/81/59d9e699d4bd241500b9fe87550785c9442189 has changed
Binary file ARTS/.git/objects/94/3beea597c218662acd5a957a8c1b3c409d4862 has changed
Binary file ARTS/.git/objects/98/ac4760695f8e4565efb03f720a1574751b40c3 has changed
Binary file ARTS/.git/objects/a5/b4c893e5aa28015aa8f8efb38dee0abd477856 has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/objects/bd/39087f25b3386a667a6744de4aa95642b0ad82	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,2 @@
+xN0D9+Vq]	U儸^%۱pysaT;.D@(ch5ƌJ"48u.#zJM?
+vLR+9ah;vxM=KlXUh_	->3tϧs^0
_sRk
09s S^2AޛWވrY
\ No newline at end of file
Binary file ARTS/.git/objects/e0/7c6c8ab6c5724f2b7600882631d6e367a848da has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/refs/heads/master	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,1 @@
+54a4951e3c5c45f409e70a985b0cea2455ae957e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/.git/refs/remotes/origin/master	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,1 @@
+54a4951e3c5c45f409e70a985b0cea2455ae957e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/ARTS.pl	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,1244 @@
+#!/usr/bin/perl
+# ARTS: Automated Randomization of multiple Traits for Study Design, using diploidly GA
+# Mark Maienschein-Cline, last updated 8/19/2013
+# mmaiensc@uic.edu
+# Center for Research Informatics, University of Illinois at Chicago
+#
+# Copyright (C) 2013 Mark Maienschein-Cline
+#
+#    This program is free software; you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License along
+#    with this program; if not, write to the Free Software Foundation, Inc.,
+#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+
+
+
+use Getopt::Long qw(:config no_ignore_case);
+#use Time::HiRes qw( clock_gettime );
+use Math::Trig;
+$|++;
+
+#
+# initialize random number parameters
+#
+&ran1_init();
+
+#
+# read command line
+#
+&read_command_line();
+
+#
+# read phenotype list: print the title lines of columns used for verbose
+#
+&read_data();
+if( $verb eq "y" || $verb eq "l" ){
+	printf("Using traits:");
+	for($i=0; $i<= $#allcols; $i++){
+		print "\t$titlevals[$allcols[$i]]";
+	}
+	print "\n";
+	printf("Using trait combinations:");
+	for($i=0; $i<= $#cols; $i++){
+		printf("\t{%s", $titlevals[$cols[$i][0]]);
+		for($j=1; $j<= $#{$cols[$i]}; $j++){
+			printf(",%s", $titlevals[$cols[$i][$j]]);
+		}
+		printf("}");
+	}
+	print "\n";
+}
+
+#
+# initialize GA parameters
+#
+&ga_init();
+
+#
+# if using the batchcolumn, fill in the batch
+#
+if( $bcolumn ne "" ){
+	if( $verb eq "y" ){
+		printf("Looking at column %i (%s) for batch assignments\n", $bcolumn+1, $titlevals[$bcolumn]);
+	}
+	# fill in batch from last column of @data
+	$numbatches = 0;
+	$foundbatchhash = {};
+	@batchsizes = ();
+	for($i=0; $i<=$#data; $i++){
+		if( $foundbatchhash->{$data[$i][$bcolumn]} eq "" ){
+			$foundbatchhash->{$data[$i][$bcolumn]} = $numbatches;
+			$numbatches++;
+			push(@batchnames, $data[$i][$bcolumn]);
+			push(@batchsizes, 0);
+		}
+		$batchsizes[$foundbatchhash->{$data[$i][$bcolumn]}]++;
+		$data[$i][$#{$data[0]}] = $data[$i][$bcolumn];
+	}
+	$mi = &mutual_info( $numbatches );
+	$bestmi = $mi;
+}
+
+#
+# else do sampling: run GA
+#
+if( $bcolumn eq "" ){
+	&initialize_population();
+
+	$oldavg = 1;
+	$err = 0.0001;
+	for($n=0; $n< $numgen; $n++){
+		&add_immigrants();
+		@population = &permute( \@population );
+		$k = 0;
+		$k = &crossover( $k );
+		$k = &mutate( $k );
+		$k = &add_parents( $k );
+		@pool = sort{$a->{score} <=> $b->{score}} @pool;
+		$average = &fill_population();
+
+		# check if we've done enough already, and print out status
+		if( $verb eq "y" ){printf("  Generation %i of %i, average fitness %0.4f\n", $n+1, $numgen, $average );}
+		if( $oldavg >= $average && $oldavg - $average < $err ){last;}
+		$oldavg = $average;
+	}
+
+	# save the final best one
+	for($i=0; $i<= $#data; $i++){
+		&fill_assignments( \@{$population[0]->{assignments}} );
+	}
+}
+
+#
+# print final log to stdout
+#
+if( $verb eq "y" || $verb eq "l" ){&print_info;}
+
+#
+# print result
+#
+if( $out ne "" ){
+	open(OUT,">$out");
+	print OUT "$title\t$bname\n";
+	for($i=0; $i<= $#data; $i++){
+		$orig[$i][1] = $data[$i][$#{$data[0]}];
+		printf OUT ("%s\t%i\n", $orig[$i][0], $orig[$i][1]);
+	}
+	close(OUT);
+}
+
+###############
+# SUBROUTINES #
+###############
+
+# read command line options
+sub read_command_line{
+	my $i;
+	
+	#
+	# option default values
+	#
+	$in = "";
+	$out = "";
+	$bcolumn = "";
+	$batch = "";
+	$bname = "batch";
+	$phenocols = "";
+	$contcols = "";
+	$datecols = "";
+	$bins = 5;
+	@blist = ();
+	$verb = "y";
+	$mmi = 0;
+
+	$options = "
+Usage: ./ARTS.pl <OPTIONS>
+	REQUIRED:
+	-i  input traits (rectangular, tab-delimited matrix, including title line with column names)
+	-c  trait columns to randomize
+	    comma- and semicolon delimited list, columns indexed from 1
+	    all traits indicated by commas are used in joint distributions
+	AND EITHER -b AND -o, OR -p:
+	-b  batch sizes (a single number, or a comma-delimited list)
+	-o  output file (formatted same as input file, with batch added as last column)
+	   -or-
+	-p  <batch column index>: print MI statistic for input traits using this column as batch designations
+	    -p will not do any sampling
+	OTHER OPTIONS:
+	-cc continuously-valued columns (will be binned)
+	-cd date-valued columns (should be M/D/Y); should also list these as continuous (in -cc)
+	-cb number of bins to use for continuous or date columns (default: $bins for each)
+	    can give 1 value, or a list of the same length as -cc; if a list, will be assigned in the same order as -cc
+	-bn batch name (title of added column, default $bname)
+	-s  random number seed (large negative integer, default: $seed)
+";
+
+#
+# Secret options:
+# -v y or l (verbose: print all, or just print status from beginning or end)
+# -mmi force use of MMI objective function on all columns indicated by -c, over-riding any other settings from -c
+#
+
+	GetOptions('i=s'  => \$in,
+		   'o=s'  => \$out,
+		   'p=i'  => \$bcolumn,
+		   'b=s'  => \$batch,
+		   'c=s'  => \$phenocols,
+		   'cc=s' => \$contcols,
+		   'cd=s' => \$datecols,
+		   'cb=s' => \$bins,
+		   'bn=s' => \$bname,
+		   's=i'  => \$seed,
+		   'mmi'  => \$mmi,
+		   'v=s'  => \$verb,
+		) || die "$options\n";
+
+	#
+	# check that required inputs exist
+	#
+	if( $in eq "" ){&exit_required("i");}
+	if( ($out eq "" || $batch eq "") && $bcolumn eq "" ){&exit_required("b and -o, or -p,");}
+	if( $phenocols eq "" || $phenocols eq "None" ){&exit_required("c");}
+
+	#
+	# check that inputs values are OK
+	#
+	if( $bcolumn ne "" ){
+		if( $bcolumn < 1 ){&exit_err("p","at least 1");}
+		$bcolumn--;
+	}
+	if( $verb ne "y" && $verb ne "n" && $verb ne "l" ){&exit_err("v","y or n or l");}
+	if( $seed > 0 ){$seed*= -1;}
+	if( $seed == 0 ){&exit_err("s","non-zero");}
+
+	#
+	# if mmi, reset phenocols value using all found columns
+	#
+	if( $mmi ){
+		@initcs = split(/[,;]/, $phenocols);
+		# remove duplicates
+		@clist = ();
+		$cinds = {};
+		for($i=0; $i<= $#initcs; $i++){
+			if( $cinds->{$initcs[$i]} eq "" ){
+				$cinds->{$initcs[$i]} = 1;
+				push(@clist, $initcs[$i]);
+			}
+		}
+		# add to new phenocols
+		$phenocols = "$clist[0]";
+		for($i=1; $i<= $#clist; $i++){
+			$phenocols = sprintf("%s,%s", $phenocols, $clist[$i]);
+		}
+		$phenocols = sprintf("%s;%s", $phenocols, $clist[0]);
+		for($i=1; $i<= $#clist; $i++){
+			$phenocols = sprintf("%s;%s", $phenocols, $clist[$i]);
+		}
+	}
+
+	#
+	# extract phenotype columns
+	#
+	@cols = ();
+	@allcols = ();
+	$alllist = {};
+	@jointlist = split(';',$phenocols);
+	for($i=0; $i<= $#jointlist; $i++){
+		@tmp = split(',',$jointlist[$i]);
+		@tmp = &fix_cols( \@tmp );
+		push(@cols, [@tmp]);
+		for($j=0; $j<= $#tmp; $j++){
+			if( $alllist->{$tmp[$j]} eq "" ){
+				$alllist->{$tmp[$j]} = 1;
+				push(@allcols, $tmp[$j]);
+			}
+		}
+	}
+
+	#
+	# extract continuous and date columns
+	# sort continuous columns so that bins correspond to them in order
+	#
+	if( $contcols ne "" && $contcols ne "None" ){
+		@conts = split(',',$contcols);
+		@conts = &fix_cols( \@conts );
+		$numconts = $#conts+1;
+	}
+	if( $datecols ne "" && $datecols ne "None" ){
+		@dates = split(',',$datecols);
+		@dates = &fix_cols( \@dates );
+		$numdates = $#dates+1;
+		# check that date columns are among continuous columns
+		for($i=0; $i<= $#dates; $i++){
+			for($j=0; $j<= $#conts; $j++){
+				if( $dates[$i] == $conts[$j] ){last;}
+				if( $j==$#conts ){
+					printf("Error: please specify date column %i as continuous\n", $dates[$i]+1 );
+					die;
+				}
+			}
+		}
+	}
+	if( $bins =~ /,/ ){
+		@blist = split(',',$bins);
+		if( $#blist+1 != $#conts + 1 ){
+			printf("Error: you input %i bins, but %i columns that need binning\n", $#blist+1, $#conts+1);
+			die;
+		}
+	}
+	else{
+		for($i=0; $i<= $#conts; $i++){
+			push(@blist, $bins);
+		}
+	}		
+}
+
+# print error message for flag $_[0], with correct values $_[1], and print usage
+sub exit_err{
+        printf("Error: set -%s to be %s\n%s\n", $_[0], $_[1], $options);
+        exit;
+}
+# print error message saying flag $_[0] is required
+sub exit_required{
+        printf("Error: option -%s is required\n%s\n", $_[0], $options);
+        exit;
+}
+
+# fix all indices in array $_[0]: cast to integer, check at least 1, and subtract 1
+sub fix_cols{
+	my @list;
+	my $i;
+	@list = @{$_[0]};
+	for($i=0; $i<= $#list; $i++){
+		$list[$i] = sprintf("%i", $list[$i]);
+		if( $list[$i] < 1 ){
+			print "Error: column indices should be at least 1\n";
+			die;
+		}
+		$list[$i]--;
+	}
+	return @list;
+}
+
+# print info about best randomization
+sub print_info{
+	#
+	# get MI of each phenotype and average
+	#
+	$bestmi = &mutual_info();
+	@bestmilist = &individual_mi( $numbatches );
+	$bestavgmi = 0;
+	for($i=0; $i<= $#bestmilist; $i++){
+		$bestavgmi+= $bestmilist[$i]/($#bestmilist+1);
+	}
+
+	printf("Final MI %0.4f ; Individual trait MIs (mean %0.4f ): ", $bestmi, $bestavgmi);
+	for($i=0; $i<= $#bestmilist; $i++){
+		printf("\t%0.4f", $bestmilist[$i]);
+	}
+	print "\n-----------------------------------------------------------------\n";
+	# 
+	# print the counts for each phenotype in each batch
+	# 
+	# first title line: phenotype names
+	for($i=0; $i<= $#allcols; $i++){
+		printf("\t%s values", $titlevals[$allcols[$i]]);
+		for($j=1; $j<= $#{$items->{$allcols[$i]}->{list}}; $j++){
+			printf("\t");
+		}
+	}
+	print "\nBatch (size)";
+	# second title line: phenotype values
+	for($i=0; $i<= $#allcols; $i++){
+		for($j=0; $j<= $#{$items->{$allcols[$i]}->{list}}; $j++){
+			if( $items->{$allcols[$i]}->{list}[$j] ne "" ){printf("\t%s", &name($items->{$allcols[$i]}->{list}[$j], $allcols[$i]) );}
+			else{printf("\tempty");}
+		}
+	}
+	print "\n-------";
+	# print a line of dashes to separate
+	for($i=0; $i<= $#allcols; $i++){
+		for($j=0; $j<= $#{$items->{$allcols[$i]}->{list}}; $j++){
+			printf("\t-------");
+		}
+	}
+	print "\n";
+	for($k=0; $k< $numbatches; $k++){
+		printf("%s (%i)", $batchnames[$k], $batchsizes[$k] );
+		for($i=0; $i<= $#allcols; $i++){
+			for($j=0; $j<= $#{$items->{$allcols[$i]}->{list}}; $j++){
+				printf("\t%i", &count( $#{$data[0]}, $batchnames[$k], $allcols[$i], $items->{$allcols[$i]}->{list}[$j] ) );
+			}
+		}
+		print "\n";
+	}
+	print "-------";
+	# print a line of dashes to separate
+	for($i=0; $i<= $#allcols; $i++){
+		for($j=0; $j<= $#{$items->{$allcols[$i]}->{list}}; $j++){
+			printf("\t-------");
+		}
+	}
+	# print totals for each type
+	print "\nTotal";
+	for($i=0; $i<= $#allcols; $i++){
+		for($j=0; $j<= $#{$items->{$allcols[$i]}->{list}}; $j++){
+			printf("\t%i", $items->{$allcols[$i]}->{$items->{$allcols[$i]}->{list}[$j]}[1] );
+		}
+	}
+	print "\n";
+}
+
+# for continuous valued columns, checked by $_[1], convert value $_[0] back to a range
+sub name{
+	my $i;
+	my $binw;
+
+	# 
+	# if there aren't any continuous columns, or $_[1] doesn't match one, just return $_[0]
+	#
+	if( $#conts < 0 ){return $_[0];}
+	for($i=0; $i<= $#conts; $i++){
+		if( $_[1] == $conts[$i] ){last;}
+		if( $i==$#conts ){return $_[0];}
+	}
+
+	#
+	# convert bin value back to continuous value
+	#
+	$binw = ($contstats[$i][2]-$contstats[$i][0])/$blist[$i];
+	$val1 = $binw*$_[0]+$contstats[$i][0];
+	$val2 = $binw*($_[0]+1)+$contstats[$i][0];
+	
+	# 
+	# if there aren't any date columns, or $_[1] doesn't match one, just return the range val1-val2
+	#
+	if( $#dates < 0 ){return sprintf("%s-%s", $val1, $val2);}
+	for($i=0; $i<= $#dates; $i++){
+		if( $_[1] == $dates[$i] ){last;}
+		if( $i==$#dates ){return sprintf("%s-%s", $val1, $val2);}
+	}
+	$val1 = sprintf("%i", $val1);
+	$val2 = sprintf("%i", $val2);
+	return sprintf("%s-%s", &convert_date( $val1 ), &convert_date( $val2 ));
+
+}
+
+# read in regular matrix from $in
+# for continuous (including date-value) columns, make histograms
+sub read_data{
+	my @lines;
+	my $i;
+	@data = ();
+	$items = {};
+	@orig = ();
+	@titlevals = ();
+	@batchsizes = ();
+	$numbatches = 0;
+
+	#
+	# fix newline convention
+	#
+	
+	
+	open(IN,"$in") || die "Error: can't open $in\n";
+	#
+	# read in all lines and check formatting
+	#
+	@lines = <IN>;
+	if( $lines[0] =~ /\r/ && $#lines == 0 ){
+		# this happens with tab-delimited text saved from excel
+		@lines = split('\r', $lines[0]);
+	}
+
+	#
+	# read title line
+	#
+	$title = $lines[0];
+	chomp($title);
+	@titlevals = split('\t',$title);
+	for($k=1; $k<= $#lines; $k++){
+		$line = $lines[$k];
+		chomp($line);
+		if( $line ne "" ){	# ignore blank lines
+			@parts = split('\t',$line);
+			for($i=$#parts+1; $i<= $#titlevals; $i++){
+				push(@parts, "");
+			}
+			if( $#parts != $#titlevals ){
+				printf("Error: not enough columns in line %i\n", $#data+2);
+				die;
+			}
+			# push 1 extra for the batch
+			push(@parts, 0);
+			push(@data, [(@parts)] );
+			push(@orig, [($line, 0)] );
+		}
+	}
+	close(IN);
+
+	#
+	# exit if no data read
+	#
+	if( $#data < 0 ){
+		printf("Error: no samples were read in\n");
+		die;
+	}
+
+	#
+	# if batch is not empty, check batches:
+	#   if no commas, cast to integer and count how many are needed
+	#   if there are commas, get batched on given sizes
+	#   double check that we add up
+	# 
+	@batchnames = ();
+	if( $batch ne "" ){
+		if( $batch !~ /,/ ){
+			$batch = sprintf("%i", $batch);
+			# fix batch size if too big
+			if( $batch > $#data + 1 ){
+				printf("Warning: you have %i samples, but asked for a batch size of %i, so there is only 1 batch\n", $#data+1, $batch);
+				$batch = $#data+1;
+			}
+			$numbatches = ($#data+1)/$batch;
+			$exactbatches = sprintf("%i", $numbatches);
+			if( $exactbatches < $numbatches ){$exactbatches++;}
+			$numbatches = $exactbatches;
+			for($i=0; $i< $numbatches-1; $i++){
+				push(@batchsizes, $batch);
+			}
+			push(@batchsizes, $batch - ($numbatches*$batch - ($#data+1)) );
+		}
+		else{
+			@batchsizes = split(',',$batch);
+			$numbatches = $#batchsizes+1;
+		}
+		$tot = 0;
+		for($i=0; $i< $numbatches; $i++){
+			push(@batchnames, $i+1);
+			$tot+= $batchsizes[$i];
+		}
+		if( $tot != $#data+1 ){
+			printf("Error: have %i spaces in all batches, but %i samples\n", $tot, $#data+1);
+			die;
+		}
+	}
+
+	#
+	# convert dates to numbers
+	#
+	for($i=0; $i<= $#data; $i++){
+		for($j=0; $j<= $#dates; $j++){
+			if( $data[$i][$dates[$j]] ne "" ){$data[$i][$dates[$j]] = &convert_date( $data[$i][$dates[$j]] );}
+		}
+	}
+
+	# 
+	# for all continuous columns, compute median and fill in missing values
+	# also record max and min for binning
+	#
+	@contstats = ();	# records min, median, max for each continuous column
+	for($j=0; $j<= $#conts; $j++){
+		@tmp = ();
+		for($i=0; $i<= $#data; $i++){
+			if( $data[$i][$conts[$j]] ne "" ){push(@tmp, $data[$i][$conts[$j]]);}
+		}
+		@tmp = sort{ $a <=> $b } @tmp;
+		$median = $tmp[sprintf("%i", ($#tmp+1)/2)];
+		push(@contstats, [($tmp[0], $median, $tmp[$#tmp])] );
+	#	for($i=0; $i<= $#data; $i++){
+	#		if( $data[$i][$conts[$j]] eq "" ){$data[$i][$conts[$j]] = $median;}
+	#	}
+	}
+
+	#
+	# for all continuous columns, bin data
+	#
+	for($j=0; $j<= $#conts; $j++){
+		$binw = ($contstats[$j][2] - $contstats[$j][0])/($blist[$j]);
+		if( $binw == 0 ){
+			printf("Error: max and min of column %i are equal (max/min are %f/%f)\n", $conts[$j]+1, $contstats[$j][2], $contstats[$j][0] );
+			die;
+		}
+		for($i=0; $i<= $#data; $i++){
+			if( $data[$i][$conts[$j]] ne "" ){
+				$data[$i][$conts[$j]] = sprintf("%i", ($data[$i][$conts[$j]] - $contstats[$j][0])/$binw);
+				if( $data[$i][$conts[$j]] >= $blist[$j] ){$data[$i][$conts[$j]] = $blist[$j]-1;}
+			}
+		}
+	}
+
+	# 
+	# for each column we're using, count how many item types there are
+	# empty phenotypes are considered their own, distinct phenotype
+	#
+	$items = &itemize( \@allcols );
+}
+
+# count how many item types of @{$_[0]} there are in @data
+sub itemize{
+	my $i;
+	my $j;
+	my $info;
+	my @cols;
+	my $items;
+	@cols = @{$_[0]};
+
+	for($j=0; $j<= $#cols; $j++){
+		$info = {};
+		$info->{list} = ();
+		for($i=0; $i<= $#data; $i++){
+			if( $info->{$data[$i][$cols[$j]]} eq "" ){
+				$info->{$data[$i][$cols[$j]]} = [($#{$info->{list}}+1,0)];
+				push(@{$info->{list}}, $data[$i][$cols[$j]]);
+			}
+			$info->{$data[$i][$cols[$j]]}[1]++;
+			$info->{count}++;
+		}
+		$info->{num} = $#{$info->{list}}+1;
+		$items->{$cols[$j]} = $info;
+	}
+
+	for($j=0; $j<= $#cols; $j++){
+		# this set prints the number of values and counts for each phenotype
+		#printf("%i,%s:", $cols[$j], $titlevals[$cols[$j]]);
+		#for($k=0; $k<= $#{$items->{$cols[$j]}->{list}}; $k++){
+		#	printf("\t%s,%i", $items->{$cols[$j]}->{list}[$k], $items->{$cols[$j]}->{$items->{$cols[$j]}->{list}[$k]}[1]  );
+		#}
+		#print "\n";
+		if( $items->{$cols[$j]}->{num} > 20 ){
+			printf("Warning: column %i (%s) has %i values; should you make it continuous?\n", $cols[$j], $titlevals[$cols[$j]], $items->{$cols[$j]}->{num} );
+		}
+	}
+	return $items;
+}
+
+# convert date in M/D/Y to integer, or integer to M/D/Y
+sub convert_date{
+	my $date;
+	my $month;
+	my $day;
+	my $year;
+	my $months;
+	my $i;
+	# cumulative days per month
+	$months->{0} = 0;
+	$months->{1} = 31;
+	$months->{2} = 59;
+	$months->{3} = 90;
+	$months->{4} = 120;
+	$months->{5} = 151;
+	$months->{6} = 181;
+	$months->{7} = 212;
+	$months->{8} = 243;
+	$months->{9} = 273;
+	$months->{10} = 304;
+	$months->{11} = 334;
+	$months->{12} = 365;
+	$date = $_[0];
+
+	# convert date to integer
+	if( $date =~ /\// ){
+		($month, $day, $year) = split('/',$date);
+		$month = sprintf("%i", $month);
+		$day = sprintf("%i", $day);
+		$year = sprintf("%i", $year);
+		if( $month < 1 || $month > 12 ){
+			print "Error: found a month $month not between 1 and 12\n";
+			die;
+		}
+		if( $day < 1 || $day > 31 ){
+			print "Error: found a day $day not between 1 and 31\n";
+			die;
+		}
+			
+		return $day + $months->{$month-1} + $year*$months->{12};
+	}
+	# convert integer to date
+	elsif( $date == sprintf("%i", $date) ){
+		$year = sprintf("%i", $date/($months->{12}));
+		$month = $date-$year*$months->{12};
+		for($i=1; $i<=12; $i++){
+			if( $month < $months->{$i} ){last;}
+		}
+		$day = $month - $months->{$i-1};
+		$month = $i;
+		return sprintf("%s/%s/%s", $month, $day, $year);
+	}
+	else{
+		printf("\nError: unrecognized format in convert_date(): %s\n", $date);
+		die;
+	}
+}
+
+# set globals used by ran1
+sub ran1_init{
+	#
+	# random number variables
+	#
+	$iset = 0;
+	$gset = 0;
+	#$iseed = clock_gettime(CLOCK_REALTIME);
+	#($first, $second) = split('\.', $iseed);
+	#$seed = sprintf("-%i%i", $second, $first);
+	$seed = -10854829;
+	$M1 = 259200;
+	$IA1 = 7141;
+	$IC1 = 54773;
+	$RM1 = 1.0/$M1;
+	$M2 = 134456;
+	$IA2 = 8121;
+	$IC2 = 28411;
+	$RM2 = 1.0/$M2;
+	$M3 = 243000;
+	$IA3 = 4561;
+	$IC3 = 51349;
+	$iff = 0;
+	$ix1 = 0;
+	$ix2 = 0;
+	$ix3 = 0;
+	@ranarray = ();
+	for($i=0; $i< 98; $i++){
+		push(@ranarray, 0);
+	}
+}
+
+# uniform random number generator, seed, iff, and various capital-letter variables set in beginning
+sub ran1{
+	my $j;
+	my $temp;
+
+	if( $seed < 0 || $iff == 0 ){
+		$iff = 1;
+		$ix1 = ($IC1 - $seed)%$M1;
+		$ix1 = ($IA1*$ix1 + $IC1)%$M1;
+		$ix2 = $ix1%$M2;
+		$ix1 = ($IA1*$ix1 + $IC1)%$M1;
+		$ix3 = $ix1%$M3;
+		for($j=1; $j<= 97; $j++){
+			$ix1 = ($IA1*$ix1 + $IC1)%$M1;
+			$ix2 = ($IA2*$ix2 + $IC2)%$M2;
+			$ranarray[$j] = ($ix1 + $ix2*$RM2)*$RM1;
+		}
+		$seed = 1;
+	}
+	$ix1 = ($IA1*$ix1 + $IC1)%$M1;
+	$ix2 = ($IA2*$ix2 + $IC2)%$M2;
+	$ix3 = ($IA3*$ix3 + $IC3)%$M3;
+
+	$j = sprintf("%i", 1 + ((97*$ix3)/$M3) );
+	if( $j> 97 || $j< 1 ){
+		printf("Error in ran1: $j outside of [1:97]\n");
+		die;
+	}
+	$temp = $ranarray[$j];
+	$ranarray[$j] = ($ix1 + $ix2*$RM2)*$RM1;
+	return $temp;
+}
+
+# permute array $_[0]
+sub permute{
+	my @assignments;
+	my $i;
+	my $j;
+	my $tmp;
+
+	@assignments = @{$_[0]};
+
+	# 
+	# shuffle batches randomly
+	#
+	for($i=$#assignments; $i>= 0; $i--){
+		$j = sprintf("%i", ($i+1)*&ran1() );
+		$tmp = $assignments[$j];
+		$assignments[$j] = $assignments[$i];
+		$assignments[$i] = $tmp;
+	}
+	return @assignments;
+}
+
+# fill data with assignments $_[0]
+sub fill_assignments{
+	my @list;
+	my $i;
+	@list = @{$_[0]};
+	if( $#list != $#data ){
+		print "Error in fill_assignments: mismatching list lengths\n";
+		die;
+	}
+	for($i=0; $i<= $#list; $i++){
+		$data[$i][$#{$data[0]}] = $list[$i];
+	}
+}
+
+# compute mutual information of a batch assignment
+sub mutual_info{
+	my $i;
+	my $s;
+	my $mi;
+	my $stot;
+
+	$mi = 0;
+	for($i=0; $i<= $#cols; $i++){
+		$mi += &this_mi( $_[0], $#{$data[0]}, \@{$cols[$i]} )/($#cols+1);
+	}
+	
+	return $mi;
+}
+
+# compute all single-phenotype mutual information
+sub individual_mi{
+	my $i;
+	my @list;
+	my @milist;
+	
+	@milist = ();
+	for($i=0; $i<= $#allcols; $i++){
+		@list = ($allcols[$i]);
+		push(@milist, &this_mi( $_[0], $#{$data[0]}, \@list ) );
+	}
+	return @milist;
+}
+
+# compute mutual information of columns $_[1] ($_[0] bins) and all of @{$_[2]}
+sub this_mi{
+	my $i;
+	my $j;
+	my $summand;
+	my @list;
+	my $jprob;
+	my $m1prob;
+	my $m2prob;
+	my $jbin;
+	my $m1bin;
+	my $m2bin;
+	my $jbinstot;
+	my $m1binstot;
+	my $m2binstot;
+	my @jbinlist;
+	my @m1binlist;
+	my @m2binlist;
+	my $mi;
+	my $s1;
+	my $s2;
+	my $s;
+	@list = @{$_[2]};
+	
+	# initialize probabilities
+	$jprob = {};			# joint distribution
+	$m1prob = {};			# batch marginal dist
+	$m2prob = {};			# pheno marginal dist
+	@jbinlist = ();			# phenotype combos found in joint distribution
+	@m1binlist = ();		# batches found in batches distribution (1st marginal dist)
+	@m2binlist = ();		# phenotype combos found in phenotypes distribution (2nd marginal dist)
+
+	#	
+	# read through data and add to distributions
+	#
+	$summand = 1.0/($#data+1);
+	for($i=0; $i<= $#data; $i++){
+		#
+		# define bin names based on phenotype/batch
+		# for phenotypes p1, p2, etc., batch b:
+		#   joint = p1_p2_..._pn_b
+		#   1st marginal = b
+		#   2nd marginal = p1_p2_..._pn
+		#
+		$jbin = sprintf("%s", $data[$i][$#{$data[0]}]);
+		$m1bin = sprintf("%s", $data[$i][$#{$data[0]}]);
+		$m2bin = "";
+		for($j=0; $j<= $#list; $j++){
+			# NOTE:
+			# $list[$j] is a phenotype column (e.g., gender)
+			# $data[$i][$list[$j]] is the value of that phenotype in sample $i (e.g., M or F)
+			# $items->{$list[$j]}->{$data[$i][$list[$j]]}[0] is the bin index (e.g., M->0, F->1) of that phenotype
+
+			$jbin = sprintf("%s_%i", $jbin, $items->{$list[$j]}->{$data[$i][$list[$j]]}[0]);
+			if( $j>0 ){$m2bin = sprintf("%s_", $m2bin);}
+			$m2bin = sprintf("%s%i", $m2bin, $items->{$list[$j]}->{$data[$i][$list[$j]]}[0]);
+		}
+
+		# 
+		# check if we've already seen this bin, for each distribution
+		# initialize probabilities and add to list if it's the first time
+		#
+		if( $jprob->{$jbin} eq "" ){
+			$jprob->{$jbin} = 0;
+			push(@jbinlist, [($jbin, $m1bin, $m2bin)] );
+		}
+		if( $m1prob->{$m1bin} eq "" ){
+			$m1prob->{$m1bin} = 0;
+			push(@m1binlist, $m1bin);
+		}
+		if( $m2prob->{$m2bin} eq "" ){
+			$m2prob->{$m2bin} = 0;
+			push(@m2binlist, $m2bin);
+		}
+
+		#
+		# add a count to each distribution
+		#
+		$jprob->{$jbin} += $summand;
+		$m1prob->{$m1bin} += $summand;
+		$m2prob->{$m2bin} += $summand;
+	}
+
+	#
+	# compute mutual information, and entropy of m1prob and m2prob (for normalization)
+	#
+	$mi = 0;
+	$s1 = 0;
+	$s2 = 0;
+	for($i=0; $i<= $#jbinlist; $i++){
+		$mi+= ($jprob->{$jbinlist[$i][0]}) * log( ($jprob->{$jbinlist[$i][0]})/($m1prob->{$jbinlist[$i][1]} * $m2prob->{$jbinlist[$i][2]}) );
+	}
+	for($i=0; $i<= $#m1binlist; $i++){
+		$s1-= $m1prob->{$m1binlist[$i]} * log( $m1prob->{$m1binlist[$i]} );
+	}
+	for($i=0; $i<= $#m2binlist; $i++){
+		$s2-= $m2prob->{$m2binlist[$i]} * log( $m2prob->{$m2binlist[$i]} );
+	}
+	$s = sqrt($s1*$s2);
+
+	#	
+	# normalize mi
+	#
+	if( $s>0 ){$mi/= $s;}
+
+	#
+	# return normalized mi (0=independent, 1=completely dependent)
+	#
+	return $mi;
+}
+
+# count how many of @data have column $_[0] equal $_[1] and column $_[2] equal $_[3]
+sub count{
+	my $i;
+	my $tot;
+
+	$tot = 0;
+	for($i=0; $i<= $#data; $i++){
+		if( $data[$i][$_[0]] eq $_[1] && $data[$i][$_[2]] eq $_[3] ){$tot++;}
+	}
+	return $tot;
+}
+
+# initialize GA parameters and large matrices
+sub ga_init{
+	my $i;
+	my $j;
+	my $info;
+
+	$popsize = 100;
+	$numgen = 300;
+	$nchrmuts = 2;
+	$nnewimm = 10;
+	$nkeepparents = 2;
+	$nchrpool = ($nnewimm+$popsize) + ($nnewimm+$popsize)*$nchrmuts + $nkeepparents;
+
+	#
+	# population to turn over each generation
+	#
+	@population = ();
+	for($i=0; $i< $popsize+$nnewimm; $i++){
+		$info = {};
+		$info->{score} = 0;
+		$info->{assignments} = [()];
+		for($j=0; $j<= $#data; $j++){
+			push(@{$info->{assignments}}, 0);
+		}
+		push(@population, $info);
+	}
+
+	#
+	# new individuals to fill each generation
+	#
+	@pool = ();
+	for($i=0; $i< $nchrpool; $i++){
+		$info = {};
+		$info->{score} = 0;
+		$info->{assignments} = [()];
+		for($j=0; $j<= $#data; $j++){
+			push(@{$info->{assignments}}, 0);
+		}
+		push(@pool, $info);
+	}
+
+	#
+	# array to randomize for batch assignments
+	#
+	@batched = ();
+	@bcounts = ();
+	for($i=0; $i<= $#batchsizes; $i++){
+		push(@bcounts, 0);
+		for($j=0; $j< $batchsizes[$i]; $j++){
+			push(@batched, $i+1);
+		}
+	}
+}
+
+# initialize the population array: randomize $popsize batches and score each one
+sub initialize_population{
+	my $i;
+	
+	for($i=0; $i< $popsize; $i++){
+		@{$population[$i]->{assignments}} = &permute( \@batched );
+		&fill_assignments( \@{$population[$i]->{assignments}} );
+		$population[$i]->{score} = &mutual_info( $numbatches );
+	}
+}
+
+# complete the crossover step, keeping track of our index with $_[0]
+sub crossover{
+	my $i;
+	my $j;
+	my $k;
+
+	$k = $_[0];
+
+	for($i=0; $i< $popsize + $nnewimm; $i+=2){
+		&do_cross($i, $k);
+		&fill_assignments( \@{$pool[$k]->{assignments}} );
+		$pool[$k]->{score} = &mutual_info( $numbatches );
+		$k++;
+		&fill_assignments( \@{$pool[$k]->{assignments}} );
+		$pool[$k]->{score} = &mutual_info( $numbatches );
+		$k++;
+	}
+	return $k;
+}
+
+# do a crossover between population members $_[0] and $_[0]+1, fill to pool members $_[1] and $_[1]+1
+sub do_cross{
+	my $i;
+	my $j;
+	my $popmem;
+	my $poolmem;
+	my $index;
+	my @swap;
+	my @subswap;
+	my $swapinds;
+
+	$popmem = $_[0];
+	$poolmem = $_[1];
+	$index = sprintf("%i", $#data * &ran1() );
+
+	#
+	# count how many of each batch to switch
+	#
+	for($i=0; $i<= $#bcounts; $i++){
+		$bcounts[$i] = 0;
+	}
+	for($i=0; $i<= $index; $i++){
+		$bcounts[$population[$popmem]->{assignments}[$i] - 1]++;
+	}
+
+	#
+	# for each batch i:
+	# 	record into subswap all indices with that batch from popmem+1
+	#	permute subswap
+	#	add first bcounts[$i] into swap
+	# then sort swap
+	#
+	@swap = ();
+	$swapinds = {};
+	for($i=0; $i<= $#bcounts; $i++){
+		@subswap = ();
+		for($j=0; $j<= $#data; $j++){
+			if( $population[$popmem+1]->{assignments}[$j] == $i+1 ){
+				push(@subswap, $j);
+			}
+		}
+		@subswap = &permute( \@subswap );
+		for($j=0; $j< $bcounts[$i]; $j++){
+			push(@swap, $subswap[$j]);
+			$swapinds->{$subswap[$j]} = 1;
+		}
+	}
+	@swap = sort{$a <=> $b} @swap;
+
+	#
+	# fill start of first new chr from swap indices of second chr, and end from end of first chr
+	#
+	for($i=0; $i<= $index; $i++){
+		$pool[$poolmem]->{assignments}[$i] = $population[$popmem+1]->{assignments}[$swap[$i]];
+	}
+	for($i=$index+1; $i<= $#data; $i++){
+		$pool[$poolmem]->{assignments}[$i] = $population[$popmem]->{assignments}[$i];
+	}
+
+	#
+	# fill start of second chr from start of first chr, and end from remaining parts of second chr
+	#
+	for($i=0; $i<= $index; $i++){
+		$pool[$poolmem+1]->{assignments}[$i] = $population[$popmem]->{assignments}[$i];
+	}
+	$j = $index+1;
+	for($i=0; $i<= $#data; $i++){
+		if( $swapinds->{$i} != 1 ){
+			$pool[$poolmem+1]->{assignments}[$j] = $population[$popmem+1]->{assignments}[$i];
+			$j++;
+		}
+	}
+	
+
+	#
+	# check that batch counts are still ok
+	#
+	$checkbatch = 0;
+	if( $checkbatch ){
+		for($i=0; $i<= $#bcounts; $i++){
+			$bcounts[$i] = 0;
+		}
+		for($i=0; $i<= $#data; $i++){
+			$bcounts[$pool[$poolmem]->{assignments}[$i] - 1]++;
+		}
+		for($i=0; $i<= $#bcounts; $i++){
+			if( $bcounts[$i] != $batchsizes[$i] ){
+					print "Error in do_cross: lost some batch counts in first daughter chr\n";
+				exit;
+			}
+		}
+		for($i=0; $i<= $#bcounts; $i++){
+			$bcounts[$i] = 0;
+		}
+		for($i=0; $i<= $#data; $i++){
+			$bcounts[$pool[$poolmem+1]->{assignments}[$i] - 1]++;
+		}
+		for($i=0; $i<= $#bcounts; $i++){
+			if( $bcounts[$i] != $batchsizes[$i] ){
+				print "Error in do_cross: lost some batch counts in first daughter chr\n";
+				exit;
+			}
+		}
+	}
+}
+
+# complete the mutation step, keeping track of our index with $_[0]
+sub mutate{
+	my $i;
+	my $j;
+	my $k;
+
+	$k = $_[0];
+
+	for($i=0; $i< $popsize+$nnewimm; $i++){
+		for($j=0; $j< $nchrmuts; $j++){
+			&do_mutation($i, $k);
+			&fill_assignments( \@{$pool[$k]->{assignments}} );
+			$pool[$k]->{score} = &mutual_info( $numbatches );
+			$k++;
+		}
+	}
+	return $k;
+}
+
+# do a mutation for population member $_[0], fill to pool member $_[1]
+sub do_mutation{
+	my $i;
+	my $popmem;
+	my $poolmem;
+	my $index1;
+	my $index2;
+
+	$popmem = $_[0];
+	$poolmem = $_[1];
+
+	#
+	# fill all of poolmem
+	#
+	for($i=0; $i<= $#data; $i++){
+		$pool[$poolmem]->{assignments}[$i] = $population[$popmem]->{assignments}[$i];
+	}
+
+	# 
+	# switch two members
+	#
+	$index1 = sprintf("%i", ($#data+1) * &ran1() );
+	$index2 = sprintf("%i", ($#data+1) * &ran1() );
+
+	$pool[$poolmem]->{assignments}[$index1] = $population[$popmem]->{assignments}[$index2];
+	$pool[$poolmem]->{assignments}[$index2] = $population[$popmem]->{assignments}[$index1];
+}
+
+# add immigrants, keeping track of our index with $_[0]
+sub add_immigrants{
+	my $j;
+
+	for($j=0; $j< $nnewimm; $j++){
+		@{$population[$popsize+$j]->{assignments}} = &permute( \@batched );
+		&fill_assignments( \@{$population[$popsize+$j]->{assignments}} );
+		$population[$popsize+$j]->{score} = &mutual_info( $numbatches );
+		$k++;
+	}
+}
+
+# add top-scoring parents, keeping track of our index with $_[0]
+sub add_parents{
+	my $i;
+	my $j;
+	my $k;
+
+	$k = $_[0];
+	# sort population now
+	@population = sort{$a->{score} <=> $b->{score}} @population;
+
+	for($j=0; $j< $nkeepparents; $j++){
+		&copy_parents( $j, $k );
+		# will copy score also in copy_parents()
+		$k++;
+	}
+	return $k;
+}
+
+# add population member $_[0] to pool member $_[1]
+sub copy_parents{
+	my $i;
+	my $popmem;
+	my $poolmem;
+	my $index1;
+	my $index2;
+
+	$popmem = $_[0];
+	$poolmem = $_[1];
+
+	#
+	# fill all of poolmem
+	#
+	for($i=0; $i<= $#data; $i++){
+		$pool[$poolmem]->{assignments}[$i] = $population[$popmem]->{assignments}[$i];
+	}
+	$pool[$poolmem]->{score} = $population[$popmem]->{score};
+}
+
+# copy top of pool to population (assumes pool is sorted)
+sub fill_population{
+	my $i;
+	my $j;
+	my $m;
+
+	$m = 0;
+	for($i=0; $i< $popsize; $i++){
+		$population[$i]->{score} = $pool[$i]->{score};
+		$m+= $population[$i]->{score};
+		for($j=0; $j<= $#data; $j++){
+			$population[$i]->{assignments}[$j] = $pool[$i]->{assignments}[$j];
+		}
+	}
+	return $m/$popsize;
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/LICENSE	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,280 @@
+GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/README	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,227 @@
+ARTS: Automated Randomization of multiple Traits for Study design
+Written by Mark Maienschein-Cline
+mmaiensc@gmail.com
+Center for Research Informatics
+University of Illinois at Chicago
+
+ARTS uses a genetic algorithm to optimize (minimize) a mutual information-based objective function, obtaining
+an optimal randomization for studies of arbitrary size and design.
+
+The publication for this code is in preparation; citation to be added soon (hopefully!). When it is published,
+the section of the supplementary information will give more details about usage (in addition to what's below).
+
+Please contact me at the email above with questions.
+
+
+
+There are two ways of using this code: command-line (it's a perl script), or through Galaxy.
+
+You can learn about, and download, Galaxy at http://galaxyproject.org.
+
+################
+# INSTALLATION #
+################
+
+#
+# Command line version:
+#
+No installation needed, as long as you have a perl interpreter. Should work fine on a Mac or Linux system;
+probably fine on Windows, but I haven't tested it.
+
+#
+# Galaxy version:
+#
+Two options:
+1) You can download this tool from the Galaxy toolshed directly into your installation.
+2) Move the ARTS.pl and .xml files into tools/ in your Galaxy distribution, and edit the tool_config file
+appropriately. If you don't know how to do this, you should probably use strategy #1.
+
+###########
+# RUNNING #
+###########
+
+#
+# Galaxy version
+#
+Once you get the tools installed in Galaxy, there are help sections in the tool descriptions you can refer to.
+Also refer to the instructions for the command-line version below.
+
+#
+# Command line version:
+#
+
+Run ARTS.pl without any inputs to see the usage. All inputs are specified using the usual [-flag] [value]
+syntax (i.e., -i input.txt).
+
+Sample command using the sample_data.txt file:
+./ARTS.pl -i sample_data.txt -c "2,3,4,5;2;3;4;5" -b 10 -o batched_data.txt -cc 2,4 -cd 4
+
+
+More information about the inputs (*'ed remarks refer to the values in the sample command above):
+
+-i  Input trait table: tab-delimited table, including 1 header line. See sample_data.txt for an example.
+    You can prepare this table in Excel and save as a tab-delimited text, or just write it in a text file,
+    or copy-paste from Excel to a text file. You can have more columns than you will actually care about
+    randomizing here.
+    * You can use the file sample_data.txt as an example input; there are 5 columns, Sample ID, Age, Sex,
+      Collection Date, and Disease.
+
+-c  Trait columns to randomize. This is a comma- and semicolon-delimited list. Its syntax is important,
+    so pay attention.
+    Columns are numbered starting from 1. Traits that should be considered jointly should be listed together
+    separated by commas. Each set of jointly considered traits should be listed separated by semicolons. Hence,
+    * -c "2,3,4,5;2;3;4;5" says to consider all the traits (columns 2-5) jointly (that's the 2,3,4,5 part), AND
+      to consider each trait individually (that's the ;2;3;4;5 part).
+    You could opt to only consider traits individually (-c "2;3;4;5"), or only jointly (-c "2,3,4,5"), or only
+    pair-wise (-c "2,3;2,4;2,5;3,4;3,5;4,5"), or whatever you want.
+    OUR GENERAL-PURPOSE RECOMMENDATION is to consider all traits jointly, plus all individually, as in the sample
+    command. This corresponds to the MMI statistic discussed in the publication.
+    GALAXY USERS: you just get to select the columns to consider, and the script will use the MMI statistic 
+    automatically (you don't get a choice).
+    FINAL NOTE: you should put quotes around the value here, since otherwise semicolons will be interpreted
+    as end-of-line characters.
+
+-b  Batch size (number of samples that can be processed at the same time). You have two options:
+    1) Enter a single number. This will fill as many complete batches as possible, and put the remainder into a smaller
+       batch. This is probably convenient, but you should do a quick count to make sure you don't end up with a really
+       small last batch (e.g., if you have 105 samples and do batch size of 25, your last batch will only have 5 samples).
+    2) Enter a comma-delimited list that adds up to the number of samples, which allows for uneven batch sizes
+       For example, -b 10,10,9,9 for 38 samples. If your math doesn't add up, the program will exit and let you know.
+    * sample_data.txt has 30 samples, so "-b 10" makes 3 batches of 10 samples each.
+
+-o  Output file. Self-explanatory. The batch assignments are added as an extra column on the end, otherwise looks
+    like the input.
+    * batched_data.txt is our output file.
+
+-p  (sort-of optional: you MUST use both -b and -o, OR just -p) Print (to STDOUT) the statistics of a batched
+    run using this column. The result will look like the last part of the STDOUT from an ARTS run (see below),
+    but you can use this option for testing batch assignments from another algorithm, or if you did one by hand.
+
+-cc Indices of continuously-valued columns. ARTS uses discrete values for its statistics, so these columns must
+    be discretized (binned). If ARTS encounters a column with more than 20 values, it will generate a warning asking
+    if you want it to be continuous. Comma-delimited list.
+    * In sample_data.txt, columns 2 (age) and 4 (date) could be considered continuous (that is, it's worth treating 
+      a 35 year-old similarly to a 36 year-old), so we set "-cc 2,4".
+
+-cd Date-valued columns. These columns should also be listed under -cc, but this lets ARTS know to expect a date
+    (format MUST be M/D/Y, where month is a number (1 instead of January)) and convert the date to a number before
+    binning.
+    * In sample_data.txt, column 4 is a date, so set "-cd 4".
+
+-cb Number of bins to use for discretizing the continuous columns. Again, you can set a single value, or give a comma-
+    delimited list, which will match the order of the list given in the -cc flag.
+    * For the sample run, we left the default value of 5, but we could do, for example, "-cb 5,7", which would bin 
+      the ages into 5 bins and the dates into 7 bins (since we set "-cc 2,4", and column 2 was age, column 4 was date).
+
+-bn Name for the batch column added to the output. Default is "batch".
+
+-s  Random number seed. Set as a large negative integer. The code always uses the same seed, but if you want to 
+    rerun with a different seed you can use this option.
+
+----------------------------------------------
+
+When you run the sample command, the STDOUT looks like this (I added the N) line numbers):
+
+"""""""""""""""""""
+1)  Using traits:	Age	Sex	Collection date	Disease
+2)  Using trait combinations:	{Age,Sex,Collection date,Disease}	{Age}	{Sex}	{Collection date}	{Disease}
+3)    Generation 1 of 300, average fitness 0.1432
+4)    Generation 2 of 300, average fitness 0.1342
+5)    Generation 3 of 300, average fitness 0.1298
+6)    Generation 4 of 300, average fitness 0.1279
+7)    Generation 5 of 300, average fitness 0.1250
+8)    Generation 6 of 300, average fitness 0.1227
+9)    Generation 7 of 300, average fitness 0.1211
+10)   Generation 8 of 300, average fitness 0.1194
+11)   Generation 9 of 300, average fitness 0.1187
+12)   Generation 10 of 300, average fitness 0.1181
+13)   Generation 11 of 300, average fitness 0.1175
+14)   Generation 12 of 300, average fitness 0.1165
+15)   Generation 13 of 300, average fitness 0.1143
+16)   Generation 14 of 300, average fitness 0.1133
+17)   Generation 15 of 300, average fitness 0.1132
+18)   Generation 16 of 300, average fitness 0.1127
+19)   Generation 17 of 300, average fitness 0.1123
+20)   Generation 18 of 300, average fitness 0.1116
+21)   Generation 19 of 300, average fitness 0.1119
+22)   Generation 20 of 300, average fitness 0.1113
+23)   Generation 21 of 300, average fitness 0.1113
+24)   Generation 22 of 300, average fitness 0.1110
+25)   Generation 23 of 300, average fitness 0.1110
+26) Final MI 0.1045 ; Individual trait MIs (mean 0.0091 ): 	0.0155	0.0000	0.0209	0.0000
+27) -----------------------------------------------------------------
+28) 	Age values					Sex values		Collection date values					Disease values	
+29) Batch (size)	19-27.2	35.4-43.6	51.8-60	43.6-51.8	27.2-35.4	M	F	2/26/2012-11/11/2012	11/11/2012-7/27/2013	6/14/2011-2/26/2012	9/29/2010-6/14/2011	1/15/2010-9/29/2010	Y	N
+30) -------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------
+31) 1 (10)	2	2	2	1	3	5	5	3	2	2	2	1	5	5
+32) 2 (10)	2	2	1	2	3	5	5	2	2	4	1	1	5	5
+33) 3 (10)	3	2	1	1	3	5	5	3	2	2	2	1	5	5
+34) -------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------	-------
+35) Total	7	6	4	4	9	15	15	8	6	8	5	3	15	15
+"""""""""""""""""""
+
+Here's what the lines mean:
+1)  Tells you what traits you've selected.
+2)  Tells you what trait combinations you've selected.
+3-25) Prints the progress for each generation of the GA. Converges when average fitness changes by less than 0.0001.
+26) Final objective function value. Normalized between 0 and 1, ideal case is 0. Note that different choices of the
+    objective function ARE NOT COMPARABLE: if you select fewer traits, or simpler combinations of traits (fewer
+    joint traits) using different -c values, you will get lower MI values, but this does not necessarily indicate better
+    overall randomization, because your choices may be overly simplistic. This is why we recommend sticking with the 
+    MMI definition (all joint + all individual) consistently. This line also gives the randomization values for all 
+    individual traits.
+27-24) Inividual trait counts per batch for different values. Continuously-valued columns are given as a range
+    (e.g., age 19-27.2).
+35) Total number of traits in each bin over all samples.
+
+----------------------------------------------
+
+The output, batched_data.txt, will look like this:
+
+"""""""""""""""""""
+Sample ID       Age     Sex     Collection date Disease batch
+sample1 25      M       3/28/2012       Y       3
+sample2 37      F       4/27/2013       N       3
+sample3 36      F       3/10/2013       N       1
+sample4 52      M       7/1/2012        Y       1
+sample5 48      M       8/13/2011       Y       3
+sample6 60      M       9/21/2011       N       3
+sample7 31      F       10/22/2010      Y       3
+sample8 28      F       1/15/2010       N       2
+sample9 26      M       1/7/2012        N       1
+sample10        44      F       4/5/2012        Y       1
+sample11        33      M       5/18/2012       N       3
+sample12        25      F       7/27/2013       N       3
+sample13        28      M       1/20/2013       Y       2
+sample14        30      F       8/11/2012       Y       3
+sample15        51      M       11/23/2011      N       2
+sample16        22      M       12/21/2011      N       2
+sample17        28      M       9/26/2010       Y       1
+sample18        19      F       1/18/2010       Y       3
+sample19        35      M       2/10/2012       N       1
+sample20        38      F       2/17/2012       N       2
+sample21        25      F       4/28/2012       Y       1
+sample22        55      M       1/7/2013        Y       2
+sample23        33      F       6/30/2013       N       1
+sample24        24      M       7/1/2012        Y       2
+sample25        42      M       2/15/2011       N       3
+sample26        60      M       5/21/2011       N       1
+sample27        34      F       10/23/2010      Y       2
+sample28        37      F       12/18/2010      Y       1
+sample29        41      F       11/7/2012       N       2
+sample30        50      F       2/15/2012       Y       2
+"""""""""""""""""""
+
+Looks the same as the input file, with a sixth column titled "batch" added, saying which of the three
+batches each sample should be processed in (of course, you can permute the order of batches if you want).
+
+Included file batched_data.txt is what the output should look like.
+
+
+
+
+
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/batched_data.txt	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,31 @@
+Sample ID	Age	Sex	Collection date	Disease	batch
+sample1	25	M	3/28/2012	Y	3
+sample2	37	F	4/27/2013	N	3
+sample3	36	F	3/10/2013	N	1
+sample4	52	M	7/1/2012	Y	1
+sample5	48	M	8/13/2011	Y	3
+sample6	60	M	9/21/2011	N	3
+sample7	31	F	10/22/2010	Y	3
+sample8	28	F	1/15/2010	N	2
+sample9	26	M	1/7/2012	N	1
+sample10	44	F	4/5/2012	Y	1
+sample11	33	M	5/18/2012	N	3
+sample12	25	F	7/27/2013	N	3
+sample13	28	M	1/20/2013	Y	2
+sample14	30	F	8/11/2012	Y	3
+sample15	51	M	11/23/2011	N	2
+sample16	22	M	12/21/2011	N	2
+sample17	28	M	9/26/2010	Y	1
+sample18	19	F	1/18/2010	Y	3
+sample19	35	M	2/10/2012	N	1
+sample20	38	F	2/17/2012	N	2
+sample21	25	F	4/28/2012	Y	1
+sample22	55	M	1/7/2013	Y	2
+sample23	33	F	6/30/2013	N	1
+sample24	24	M	7/1/2012	Y	2
+sample25	42	M	2/15/2011	N	3
+sample26	60	M	5/21/2011	N	1
+sample27	34	F	10/23/2010	Y	2
+sample28	37	F	12/18/2010	Y	1
+sample29	41	F	11/7/2012	N	2
+sample30	50	F	2/15/2012	Y	2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/galaxy_arts.xml	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,110 @@
+<tool id="ARTS" name="ARTS">
+  <description>automated study randomization</description>
+  <command interpreter="perl">ARTS.pl -i $input -o $out -b $batch -c "$column" -cc $conts -cd $dates -cb $bins -bn $bname -s $seed -mmi -v l </command>
+  <inputs>
+    <param name="input" type="data" format="tabular" label="Input traits per sample" help="Ensure input is formatted as tabular"/>
+    <param name="batch" type="text" size="40" label="Batch size" optional="False" help="Set to a single number, or a comma-delimited list"/>
+    <param name="column" type="data_column" data_ref="input" multiple="True" numerical="False" label="Trait columns to randomize" help="Multi-select list - hold the appropriate key while clicking to select multiple columns." />
+    <param name="conts" type="data_column" data_ref="input" multiple="True" numerical="False" optional="True" label="Continuous- and date-valued columns for binning (if any)" help="Multi-select list. Values should be numbers." />
+    <param name="dates" type="data_column" data_ref="input" multiple="True" numerical="False" optional="True" label="Date-valued columns for binning (if any)" help="Multi-select list. Dates should be M/D/Y, where M, D, and Y are all integers (e.g., 7/9/1985)." />
+    <param name="bins" type="text" size="40" label="Bin sizes (for continuously-valued columns)" value="5" optional="False" help="Set to a single number, or a comma-delimited list. If given as a list, will be used in same order as continuous columns."/>
+    <param name="bname" type="text" size="40" label="Batch name" value="batch" optional="False" help="Name given to the batch column in the output."/>
+    <param name="seed" type="integer" size="40" label="Random number seed" optional="False" value="-123456789"/>
+  </inputs>
+  <outputs>
+    <data format="tabular" name="out" />
+  </outputs>
+  <help>
+  
+**Purpose**
+
+This tool completes automated study randomization for a selected number of traits over the samples in your data set by minimizing a mutual information-based objective function using a genetic algorithm.
+
+NOTE: in the history output, click the i (view details) icon (between the save-to-disk and rerun icons), then click on stdout to see a summary of the run. This allows you to confirm which traits are being considered, and gives you a snapshot of how randomized individual traits are (it does not inform you about combinations of traits, which ARE ALSO being randomized).
+
+-----
+
+**Input traits per sample**
+
+- A list of traits associated with each sample, including a header line giving the name of each type of trait. For example::
+     
+       ID      Sex    Age  Sample date  Diseased
+       Sample1   M     15     6/7/2011         Y
+       Sample2   M     25     8/5/2012         Y
+       Sample3   F     23    1/30/2012         N
+       Sample4   F     45     4/1/2013         N
+       Sample5   M     52    3/21/2011         Y
+       Sample6   F     37    3/12/2013         N
+       Sample7   M     31    7/17/2011         N
+
+-----
+
+**Batch size**
+
+- The size of each batch. You can specify this with a single number (e.g., 50), or a list of numbers (separated by commas, for example 50,50,49,49.
+
+- The first choice will fill up full batches as much as possible, and put all remaining samples in a smaller batch. Thus, the latter choice may be better if the batch size does not evenly divide the number of samples. For example, lets say you have 105 samples and can do a batch size of up to 30. Then::
+
+       (First option)  Batch size = 30 --> batch sizes of 30, 30, 30, and 15
+        -or-
+       (Second option) Batch size = 27,26,26,26
+     
+The second option has a more evenly distributed batch size, and will give better results.
+
+-----
+
+**Traits to randomize**
+
+- Which traits should be randomized. On Macs, hold command to multi-select. You do not need to select all columns (it would be silly, for example, to randomize over sample ID).
+
+- Note missing values for traits will be treated as an additional trait value (i.e., empty).
+
+- For the example above, we would select c2, c3, c4, and c5 (Sex, Age, Sample date, and Diseased). Not all traits need be selected, just the relevant ones (we may not care about Sample date, for example).
+
+-----
+
+**Continuous- and date-valued columns (optional)**
+
+- Use if you have columns with continuous values (e.g., age, blood pressure) or dates. They will be discretized prior to running.
+
+- For the example above, we would select c3 and c4 (Age, Sample date).
+
+-----
+
+**Date-valued columns (optional)**
+
+- Use if any of the columns selected as continuous are dates (MUST be formatted M/D/Y, where month is a number, for example 7/9/1985).
+
+- For the example above, we would select c4 (Sample date).
+
+-----
+
+**Bin sizes**
+
+- This only relates to any columns selected as continuous, and determines how many discrete bins the data will be split up in to.
+
+- You can set it to a single number, and all columns will use that number of bins. Or you can set it to a list of numbers to specify a different number of bins for each column.
+
+- For the example above, where we selected c3 and c4 as continuous, we could set::
+ 
+      Bin sizes=5,6
+
+- which would split the Age column (c3) into 5 bins, and the Sample date column (c4) into 6 bins.
+
+-----
+
+**Batch name**
+
+- The output file will look exactly the same as the input, except an additional column will be added indicated which batch each sample should belong to. You can specify the name of that column here.
+
+-----
+
+**Random number seed**
+
+- This will not be need to be changed in general, but if you want to force the use of a different seed, you can.
+
+
+
+
+</help>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/galaxy_arts_score.xml	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,84 @@
+<tool id="ARTSscore" name="ARTS Score">
+  <description>compute the score for a study randomization</description>
+  <command interpreter="perl">ARTS.pl -i $input -p $batch -c "$column" -cc $conts -cd $dates -cb $bins -mmi -v l > $out </command>
+  <inputs>
+    <param name="input" type="data" format="tabular" label="Input traits per sample" help="Ensure input is formatted as tabular"/>
+    <param name="batch" type="data_column" data_ref="input" multiple="False" numerical="False" label="Batch column to use" help="Select which column corresponds to the batching you want to score." />
+    <param name="column" type="data_column" data_ref="input" multiple="True" numerical="False" label="Trait columns" help="Multi-select list - hold the appropriate key while clicking to select multiple columns." />
+    <param name="conts" type="data_column" data_ref="input" multiple="True" numerical="False" optional="True" label="Continuous- and date-valued columns for binning (if any)" help="Multi-select list. Values should be numbers." />
+    <param name="dates" type="data_column" data_ref="input" multiple="True" numerical="False" optional="True" label="Date-valued columns for binning (if any)" help="Multi-select list. Dates should be M/D/Y, where M, D, and Y are all integers (e.g., 7/9/1985)." />
+    <param name="bins" type="text" size="40" label="Bin sizes (for continuously-valued columns)" value="5" optional="False" help="Set to a single number, or a comma-delimited list. If given as a list, will be used in same order as continuous columns."/>
+  </inputs>
+  <outputs>
+    <data format="tabular" name="out" />
+  </outputs>
+  <help>
+  
+**Purpose**
+
+This tool computes the score for a completed study randomization (e.g., by ARTS) for a selected number of traits over the samples in your data, and a particular column giving the batch assignments. The output here is identical to the stdout obtained from a standard ARTS run.
+
+-----
+
+**Input traits per sample**
+
+- A list of traits associated with each sample, including a header line giving the name of each type of trait, and a batch column. For example::
+     
+       ID      Sex    Age  Sample date  Diseased  Batch
+       Sample1   M     15     6/7/2011         Y      1
+       Sample2   M     25     8/5/2012         Y      2
+       Sample3   F     23    1/30/2012         N      1
+       Sample4   F     45     4/1/2013         N      1
+       Sample5   M     52    3/21/2011         Y      2
+       Sample6   F     37    3/12/2013         N      2
+       Sample7   M     31    7/17/2011         N      2
+
+-----
+
+**Batch column to use**
+
+- Which column indicate the batch assignment. In the example above, this would be c6 (batch).
+
+-----
+
+**Traits to randomize**
+
+- Which traits should be randomized. On Macs, hold command to multi-select. You do not need to select all columns (it would be silly, for example, to randomize over sample ID).
+
+- Note missing values for traits will be treated as an additional trait value (i.e., empty).
+
+- For the example above, we would select c2, c3, c4, and c5 (Sex, Age, Sample date, and Diseased). Not all traits need be selected, just the relevant ones (we may not care about Sample date, for example).
+
+-----
+
+**Continuous- and date-valued columns (optional)**
+
+- Use if you have columns with continuous values (e.g., age, blood pressure) or dates. They will be discretized prior to running.
+
+- For the example above, we would select c3 and c4 (Age, Sample date).
+
+-----
+
+**Date-valued columns (optional)**
+
+- Use if any of the columns selected as continuous are dates (MUST be formatted M/D/Y, where month is a number, for example 7/9/1985).
+
+- For the example above, we would select c4 (Sample date).
+
+-----
+
+**Bin sizes**
+
+- This only relates to any columns selected as continuous, and determines how many discrete bins the data will be split up in to.
+
+- You can set it to a single number, and all columns will use that number of bins. Or you can set it to a list of numbers to specify a different number of bins for each column.
+
+- For the example above, where we selected c3 and c4 as continuous, we could set::
+ 
+      Bin sizes=5,6
+
+- which would split the Age column (c3) into 5 bins, and the Sample date column (c4) into 6 bins.
+
+
+</help>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ARTS/sample_data.txt	Wed Nov 13 16:13:17 2013 -0500
@@ -0,0 +1,31 @@
+Sample ID	Age	Sex	Collection date	Disease
+sample1	25	M	3/28/2012	Y
+sample2	37	F	4/27/2013	N
+sample3	36	F	3/10/2013	N
+sample4	52	M	7/1/2012	Y
+sample5	48	M	8/13/2011	Y
+sample6	60	M	9/21/2011	N
+sample7	31	F	10/22/2010	Y
+sample8	28	F	1/15/2010	N
+sample9	26	M	1/7/2012	N
+sample10	44	F	4/5/2012	Y
+sample11	33	M	5/18/2012	N
+sample12	25	F	7/27/2013	N
+sample13	28	M	1/20/2013	Y
+sample14	30	F	8/11/2012	Y
+sample15	51	M	11/23/2011	N
+sample16	22	M	12/21/2011	N
+sample17	28	M	9/26/2010	Y
+sample18	19	F	1/18/2010	Y
+sample19	35	M	2/10/2012	N
+sample20	38	F	2/17/2012	N
+sample21	25	F	4/28/2012	Y
+sample22	55	M	1/7/2013	Y
+sample23	33	F	6/30/2013	N
+sample24	24	M	7/1/2012	Y
+sample25	42	M	2/15/2011	N
+sample26	60	M	5/21/2011	N
+sample27	34	F	10/23/2010	Y
+sample28	37	F	12/18/2010	Y
+sample29	41	F	11/7/2012	N
+sample30	50	F	2/15/2012	Y