changeset 2:92ddf4f7c0c6 draft

Uploaded
author dereeper
date Thu, 02 Jul 2015 04:13:46 -0400
parents 78b98120be91
children 9f6977aae93a
files admixture/Admixture.pl admixture/admixture.sh admixture/admixture.xml admixture/tool_dependencies.xml tool_dependencies.xml
diffstat 5 files changed, 200 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/admixture/Admixture.pl	Thu Jul 02 04:13:46 2015 -0400
@@ -0,0 +1,112 @@
+#!/usr/bin/perl
+
+use strict;
+use Switch;
+use Getopt::Long;
+use Bio::SeqIO;
+use File::Basename;
+
+my $usage = qq~Usage:$0 <args> [<opts>]
+where <args> are:
+    -i, --input         <input basename (for PED, FAM, BIM)>
+    -o, --output        <output>
+    -k, --kmin          <K min. int>
+    -m, --maxK          <K max. int>
+    -d, --directory     <temporary directory>
+~;
+$usage .= "\n";
+
+my ($input,$output,$kmin,$kmax,$directory);
+
+
+GetOptions(
+	"input=s"      => \$input,
+	"output=s"     => \$output,
+	"kmin=s"       => \$kmin,
+	"maxK=s"       => \$kmax,
+	"directory=s"  => \$directory,
+);
+
+
+die $usage
+  if ( !$input || !$output || !$kmin || !$kmax || !$directory );
+
+if ($kmin =~/^(\d+)\s*$/){
+        $kmin = $1;
+}
+else{
+        die "Error: kmin must be an integer\n";
+}
+if ($kmax =~/^(\d+)\s*$/){
+        $kmax = $1;
+}
+else{
+        die "Error: kmax must be an integer\n";
+}
+
+
+
+open(my $P2,"$input.fam");
+my $n = 0;
+my $ind_num = 0;
+my @individus;
+while(<$P2>)
+{
+	my ($ind,$other) = split(/ /,$_);
+	push(@individus,$ind);
+}
+close($P2);
+
+my $basename = basename($input);
+
+###################################
+# launch admixture for different K
+###################################
+my %errors;
+for (my $k = $kmin; $k <= $kmax; $k++)
+{
+	system("admixture --cv $input.bed $k >>$directory/log.$k 2>&1");
+	my $cv_error_line = `grep -h CV $directory/log.$k`;
+	if ($cv_error_line =~/: (\d+\.*\d*)$/)
+	{
+		$errors{$1} = $k;
+	}
+	system("cat $directory/log.$k >>$directory/logs");
+	system("echo '\n\n====================================\n\n' >>$directory/logs");
+	system("cat $basename.$k.Q >>$directory/outputs.Q");
+	system("echo '\n\n====================================\n\n' >>$directory/outputs.Q");
+	system("cat $basename.$k.P >>$directory/outputs.P");
+	system("echo '\n\n====================================\n\n' >>$directory/outputs.P");
+}
+
+my @sorted_errors = sort {$a<=>$b} keys(%errors);
+my $best_K = $errors{@sorted_errors[0]};
+
+
+open(BEST1,"$basename.$best_K.Q");
+open(BEST2,">$directory/output");
+print BEST2 "<Covariate>\n";
+print BEST2 "<Trait>";
+for (my $j=1;$j<=$best_K;$j++)
+{
+	print BEST2 "	Q" . $j;
+}
+print BEST2 "\n";
+my $i = 0;
+while(<BEST1>)
+{
+	my $line = $_;
+	$line =~s/ /\t/g;
+	my $ind = $individus[$i];
+	print BEST2 "$ind	";
+	print BEST2 $line;
+	$i++;
+}
+close(BEST1);
+close(BEST2);
+
+system("cp -rf $directory/log.$best_K $directory/log");
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/admixture/admixture.sh	Thu Jul 02 04:13:46 2015 -0400
@@ -0,0 +1,26 @@
+#!/bin/bash
+bed=$1
+fam=$2
+bim=$3
+outputs=$4
+logs=$5
+best_k_output=$6
+best_k_logfile=$7
+kmin=$8
+kmax=$9
+
+directory=`dirname $0`
+mkdir tmpdir$$
+cp -rf $bed tmpdir$$/input.bed
+cp -rf $fam tmpdir$$/input.fam
+cp -rf $bim tmpdir$$/input.bim
+
+ 
+/usr/bin/perl $directory/Admixture.pl -i tmpdir$$/input -o $outputs -k $kmin -m $kmax -d tmpdir$$
+
+mv tmpdir$$/output $best_k_output
+mv tmpdir$$/log $best_k_logfile
+mv tmpdir$$/outputs.Q $outputs
+mv tmpdir$$/logs $logs
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/admixture/admixture.xml	Thu Jul 02 04:13:46 2015 -0400
@@ -0,0 +1,56 @@
+<tool id="admixture" name="Admixture" version="1.23">
+	<description>a population structure from large SNP genotype datasets</description>
+	<requirements>
+		<requirement type="package" version="1.23">admixture</requirement>
+	</requirements>
+	<command interpreter="bash">./admixture.sh $bed $fam $bim $outputs $logs $best_k_output $best_k_logfile $kmin $kmax
+    </command>
+	<inputs>
+		<param format="txt" name="bed" type="data" label="Allelic file in BED format" help="Allelic file in BED format"/>
+		<param format="txt" name="fam" type="data" label="Fam file" help="Fam file"/>
+		<param format="txt" name="bim" type="data" label="Bim file" help="Bim file"/>
+		<param type="text" name="kmin" label="K min" value="1"/>
+		<param type="text" name="kmax" label="K max" value="5"/>
+	</inputs>
+	<outputs>
+		<data format="txt" name="best_k_output" label="Best K Output"/>
+		<data format="txt" name="best_k_logfile" label="Best K Logfile"/>
+		<data format="txt" name="outputs" label="All Outputs"/>
+		<data format="txt" name="logs" label="All Logs"/>
+	</outputs>
+	<help>
+	
+
+.. class:: infomark
+
+**Program encapsulated in Galaxy by Southgreen**
+
+.. class:: infomark
+
+**Admixture version 1.23**
+
+-----
+
+==============
+ Please cite: 
+==============
+
+"Fast model-based estimation of ancestry in unrelated individuals.", **D.H. Alexander, J. Novembre, and K. Lange.**, Genome Research, 19:1655{1664, 2009.
+
+-----
+
+===========
+ Overview:
+===========
+
+ADMIXTURE is a program for estimating ancestry in a model-based manner from large autosomal SNP genotype datasets, where the individuals are unrelated (for example, the individuals in a case-control association study).
+
+-----
+
+For further informations, please visite the Admixture_ website.
+
+
+.. _Admixture: http://www.genetics.ucla.edu/software/admixture/index.html
+	</help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/admixture/tool_dependencies.xml	Thu Jul 02 04:13:46 2015 -0400
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<tool_dependency>
+    <package name="admixture" version="1.23">
+        <repository changeset_revision="61e04b2aa621" name="package_admixture_1_23" owner="dereeper" toolshed="https://toolshed.g2.bx.psu.edu/" />
+    </package>
+</tool_dependency>
--- a/tool_dependencies.xml	Thu Jul 02 04:08:56 2015 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-<?xml version="1.0"?>
-<tool_dependency>
-    <package name="admixture" version="1.23">
-        <repository changeset_revision="61e04b2aa621" name="package_admixture_1_23" owner="dereeper" toolshed="https://toolshed.g2.bx.psu.edu/" />
-    </package>
-</tool_dependency>