# HG changeset patch # User devteam # Date 1421941248 18000 # Node ID b1e0bf394aa970a21447c30b482527cd7e36edf7 Imported from capsule None diff -r 000000000000 -r b1e0bf394aa9 karyotype/karyotype_plot.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/karyotype/karyotype_plot.xml Thu Jan 22 10:40:48 2015 -0500 @@ -0,0 +1,178 @@ + + for multiple series + \$R_SCRIPT_PATH/r_wrapper.sh $script_file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ## Setup R error handling to go to stderr + options( show.error.messages=F, + error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) }, + warn = -1 ) + ## Determine range of all series in the plot + library('gtools') + chrlist = c() + coordrange = c( NULL, NULL ) + #for $i, $s in enumerate( $series ) + s${i} = read.table( "${s.input.file_name}" ) + chrlist = union( chrlist, as.character(unique(s${i}[,${s.chrcolumn}])) ) + coordrange = range( coordrange, range(s${i}[,${s.startcolumn}]), range(s${i}[,${s.endcolumn}]) ) + #end for + chrlist=mixedsort(chrlist) + coordrange_byChr=list() + length(coordrange_byChr) = length(chrlist)*2 + dim(coordrange_byChr) = c(length(chrlist),2) + ci=1 + for (chr in chrlist) { + #for $i, $s in enumerate( $series ) + s${i} = read.table( "${s.input.file_name}" ) + if (nrow(s${i}[s${i}[,${s.chrcolumn}]==chr,]) > 0) { + coordrange_byChr[ci,]=range(coordrange_byChr[ci,], s${i}[s${i}[,${s.chrcolumn}]==chr,c(${s.startcolumn},${s.endcolumn})]) + } + #end for + ci=ci+1 + } + ## Open output PDF file + pdf( "${out_file1}" ) + ## Dummy plot for axis / labels + plot( NULL, type="n", xlim=c(1,length(chrlist)), ylim=coordrange, axes=F, main="${main}", xlab="${xlab}", ylab="${ylab}" ) + box() + axis(1,at=1:length(chrlist),labels=chrlist,cex.axis=0.9, las=2) + axis(2,at=seq(coordrange[1],coordrange[2], length.out=10)) + ## Plot backbone lines for each chr + ci=1 + for (chr in chrlist) { + lines(c(ci,ci),coordrange_byChr[ci,],lty=${lty},col=${col},lwd=${lwd}) + ci=ci+1 + } + + legend_text=c() + pchlist=c() + colorlist=c() + ## Plot each series + #for $i, $s in enumerate( $series ) + chrs=as.character(s${i}[,${s.chrcolumn}]) + xvals=sapply(chrs,function(x) which(chrlist==x)) + points(xvals, s${i}[,${s.startcolumn}], pch=${s.fpch}, cex=${s.fcex}, col=${s.fcol} ) + legend_text[${i}+1] = "${s.leg_text}" + pchlist[${i}+1] = ${s.fpch} + colorlist[${i}+1] = ${s.fcol} + #end for + + #if $legend['status'] == "yes" + legend_title = "$legend.leg_title" + legend_pos = "$legend.leg_pos" + legend(legend_pos, title=legend_title, legend=legend_text, pch=pchlist, col=colorlist) + #end if + + ## Close the PDF file + devname = dev.off() + + + + + + + + + R_SCRIPT_PATH + R + + + +.. class:: infomark + +**What it does** + +This tool allows you to paint genomic regions of interest on chromosomes arranged in a karyotype-like fashion. It also allows you to have multiple series in a plot, with each series corresponding to a different feature/dataset. + +----- + +.. class:: warningmark + +Chromosome lengths (backbone line) are determined based on min and max co-ordinates (by chromosome) in start and end columns respectively. For the series, only the co-ordiantes in start column are used for plotting. + +----- + +**Example** + +Below is an example of a two series karyotype plot: + +.. image:: ./static/operation_icons/karyotype_output.png + :height: 540 + :width: 540 + + + diff -r 000000000000 -r b1e0bf394aa9 karyotype/r_wrapper.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/karyotype/r_wrapper.sh Thu Jan 22 10:40:48 2015 -0500 @@ -0,0 +1,23 @@ +#!/bin/sh + +### Run R providing the R script in $1 as standard input and passing +### the remaining arguments on the command line + +# Function that writes a message to stderr and exits +function fail +{ + echo "$@" >&2 + exit 1 +} + +# Ensure R executable is found +which R > /dev/null || fail "'R' is required by this tool but was not found on path" + +# Extract first argument +infile=$1; shift + +# Ensure the file exists +test -f $infile || fail "R input file '$infile' does not exist" + +# Invoke R passing file named by first argument to stdin +R --vanilla --slave $* < $infile diff -r 000000000000 -r b1e0bf394aa9 karyotype/static/operation_icons/karyotype_output.png Binary file karyotype/static/operation_icons/karyotype_output.png has changed diff -r 000000000000 -r b1e0bf394aa9 karyotype/tool_dependencies.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/karyotype/tool_dependencies.xml Thu Jan 22 10:40:48 2015 -0500 @@ -0,0 +1,21 @@ + + + + $REPOSITORY_INSTALL_DIR + + + + + http://CRAN.R-project.org/src/base/R-2/R-2.15.0.tar.gz + ./configure --prefix=$INSTALL_DIR + make + + $INSTALL_DIR/bin + + + + +You need a FORTRAN compiler or perhaps f2c in addition to a C compiler to build R. + + +