view karyotype/karyotype_plot.xml @ 0:b1e0bf394aa9 draft

Imported from capsule None
author devteam
date Thu, 22 Jan 2015 10:40:48 -0500
parents
children 88ecf2b559a0
line wrap: on
line source

<tool id="karyotype_Plot_1" name="Karyotype Plotting tool" version="1.0.0">
  <description>for multiple series </description>
  <command interpreter="bash">\$R_SCRIPT_PATH/r_wrapper.sh $script_file</command>

  <inputs>
    <param name="main" type="text" value="" size="30" label="Plot Title"/>
    <param name="xlab" type="text" value="" size="30" label="Label for x axis"/>
    <param name="ylab" type="text" value="" size="30" label="Label for y axis"/>
    <param name="lty" type="select" label="Backbone Line Type">
	    <option value="1">Solid</option>
	    <option value="2">Dashed</option>
	    <option value="3">Dotted</option>
	</param>
	<param name="col" type="select" label="Backbone Line Color">
	    <option value="1">Black</option>
	    <option value="2">Red</option>
	    <option value="3">Green</option>
	    <option value="4">Blue</option>
	    <option value="5">Cyan</option>
	    <option value="6">Magenta</option>
	    <option value="7">Yellow</option>
	    <option value="8">Gray</option>
	</param>
	<param name="lwd" type="float" label="Backbone Line Width" value="1.0"/>
	
	<conditional name="legend">
        <param name="status" type="select" label="Include legend?">
          <option value="yes" selected="true">Yes</option>
          <option value="no">No</option>
        </param>
	<when value="yes">
		<param name="leg_title" type="text" value="" size="30" label="Legend title"/>
		<param name="leg_pos" type="select" label="Legend position">
          <option value="top" selected="true">top</option>
          <option value="topright">topright</option>
          <option value="topleft">topleft</option>
          <option value="bottom">bottom</option>
          <option value="bottomright">bottomright</option>
          <option value="bottomleft">bottomleft</option>
          <option value="left">left</option>
          <option value="right">right</option>
          <option value="center">center</option>
        </param>	
	</when>
	<when value="no">
    </when>
    </conditional>
    
    <repeat name="series" title="Series">
      <param name="input" type="data" format="tabular" label="Dataset"/>
      <param name="chrcolumn" type="data_column" data_ref="input" label="Chromosome Column"/>
      <param name="startcolumn" type="data_column" data_ref="input" numerical="True" label="Start Column"/>
      <param name="endcolumn" type="data_column" data_ref="input" numerical="True" label="End Column"/>
      <param name="fpch" type="select" label="Point Type">
        <option value="1">Circle (hollow)</option>
        <option value="2">Triangle (hollow)</option>
        <option value="3">Cross</option>
        <option value="4">Diamond (hollow)</option>
        <option value="15">Square (filled)</option>
        <option value="16">Circle (filled)</option>
        <option value="17">Triangle (filled)</option>  
      </param>
      <param name="fcol" type="select" label="Point Color">
        <option value="1">Black</option>
        <option value="2">Red</option>
        <option value="3">Green</option>
        <option value="4">Blue</option>
        <option value="5">Cyan</option>
        <option value="6">Magenta</option>
        <option value="7">Yellow</option>
        <option value="8">Gray</option>
      </param>
      <param name="fcex" type="float" label="Point Scale" value="1.0"/>
      <param name="leg_text" type="text" value="" size="30" label="Legend text" help="Will be printed only if Include Legend option is set to Yes"/>
    </repeat>       
  </inputs>

  <configfiles>
    <configfile name="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() 
    </configfile>
  </configfiles>

  <outputs>
    <data format="pdf" name="out_file1" />
  </outputs>
  
  <requirements>
    	<requirement type="set_environment">R_SCRIPT_PATH</requirement>
    	<requirement type="package" version="2.15.0">R</requirement>
  </requirements>
	
<help>
.. 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

</help>
</tool>