changeset 1:8593828f91e7 default tip

Full galaxy wrapper
author diego
date Sat, 21 Apr 2012 21:36:15 -0400
parents d50638ebd809
children
files README lib/galaxy/datatypes/rtg.py rtg.py tools/rtg/cg2sdf.xml tools/rtg/cgmap.xml tools/rtg/cgsim.xml tools/rtg/coverage.xml tools/rtg/format_fasta.xml tools/rtg/format_fastq.xml tools/rtg/galaxy-rtg-map-wrapper.sh tools/rtg/galaxy-rtg-mapx-wrapper.sh tools/rtg/galaxy-rtg-sdf2fasta-wrapper.sh tools/rtg/galaxy-rtg-singleoutput-wrapper.sh tools/rtg/galaxy-rtg-snpintersect-wrapper.sh tools/rtg/galaxy-rtg-snpsim-wrapper.sh tools/rtg/galaxy-rtg-wrapper.sh tools/rtg/genomesim.xml tools/rtg/map.xml tools/rtg/mapf.xml tools/rtg/mapx.xml tools/rtg/readsim.xml tools/rtg/rtg-galaxy.cfg tools/rtg/sdf2fasta.xml tools/rtg/snp.xml tools/rtg/snpintersection.xml tools/rtg/snpsim.xml
diffstat 26 files changed, 1116 insertions(+), 239 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,56 @@
+RTG Galaxy tools
+----------------
+
+Install:
+
+Copy lib/galaxy/datatypes/rtg.py and the tools/rtg directory to the same locations in your galaxy distribution.
+
+Then edit the following files:
+
+galaxy_dist/tools/rtg/rtg-galaxy.cfg
+
+  change the rtg variable to point at the rtg file in your RTG installation directory
+    
+galaxy_dist/lib/galaxy/datatypes/registry.py
+  add
+    , rtg
+  to the list of imports beginning with data, tabular, interval...
+
+
+galaxy_dist/tool_conf.xml
+  Within the <toolbox> node, add
+  
+  <section name="Realtime Genomics" id="rtg">
+    <label text="Data formatting" id="formatting" />
+    <tool file="rtg/format_fasta.xml" />
+    <tool file="rtg/format_fastq.xml" />
+    <tool file="rtg/cg2sdf.xml" />
+    <tool file="rtg/sdf2fasta.xml" />
+    <label text="Read mapping" id="mapping" />
+    <tool file="rtg/map.xml" />
+    <tool file="rtg/cgmap.xml" />
+    <tool file="rtg/mapf.xml" />
+    <tool file="rtg/mapx.xml" />
+    <label text="Variant detection" id="variant" />
+    <tool file="rtg/snp.xml" />
+    <tool file="rtg/coverage.xml" />
+    <tool file="rtg/snpintersection.xml" />
+    <label text="Simulation" id="sim" />
+    <tool file="rtg/genomesim.xml" />
+    <tool file="rtg/cgsim.xml" />
+    <tool file="rtg/readsim.xml" />
+    <tool file="rtg/snpsim.xml" />
+  </section>
+
+galaxy_dist/datatypes_config.xml
+  Within the <datatypes><registration> node, add
+  
+        <!-- Start RTG Datatypes -->
+        <datatype extension="rtg_sdf" type="galaxy.datatypes.rtg:Sdf"/>
+        <datatype extension="tsvcg" type="galaxy.datatypes.rtg:Cgtsv" display_in_upload="true"/>
+        <datatype extension="samix" type="galaxy.datatypes.rtg:Samix" display_in_upload="true"/>
+        <!-- End RTG Datatypes -->
+
+  Within the <datatypes><sniffers> node, add
+        <sniffer type="galaxy.datatypes.rtg:Samix"/>
+        <sniffer type="galaxy.datatypes.rtg:Cgtsv"/>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/galaxy/datatypes/rtg.py	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,239 @@
+"""
+rtg datatypes
+"""
+
+import data
+from galaxy.datatypes import sequence
+import logging, os, sys, time, tempfile, shutil, string, glob, re, subprocess
+import galaxy.model
+from galaxy.datatypes import metadata
+from galaxy.datatypes.metadata import MetadataElement
+from galaxy import util
+from galaxy.datatypes.images import Html
+from galaxy.datatypes.sequence import Sequence
+from galaxy.datatypes.binary import Binary
+from sniff import *
+from pprint import pprint
+from ConfigParser import ConfigParser
+
+log = logging.getLogger(__name__)
+basepath = os.path.dirname(__file__)
+rtgcfg = os.path.abspath(os.path.join(basepath, "..", "..", "..", "tools", "rtg", "rtg-galaxy.cfg"))
+
+class FakeSecHead(object):
+    def __init__(self, fp):
+        self.fp = fp
+        self.sechead = '[asection]\n'
+    def readline(self):
+        if self.sechead:
+          try: return self.sechead
+          finally: self.sechead = None
+        else: return self.fp.readline()
+
+cfg = ConfigParser()
+cfg.readfp(FakeSecHead(open(rtgcfg)))
+
+class Sdf( Html ):
+    composite_type = 'auto_primary_file'
+    allow_datatype_change = False
+    file_ext = 'sdf'
+
+    MetadataElement(name="sdfId", desc="SDF Id", readonly="true", param=metadata.MetadataParameter)
+    MetadataElement(name="source", desc="Source", readonly="true", values=[('UNKNOWN', 'Unknown'), ('CG', 'Complete Genomics'), ('SOLEXA', 'Solexa')], param=metadata.SelectParameter)
+    MetadataElement(name="sequences", desc="Number of Sequences", readonly="true", param=metadata.MetadataParameter)
+    MetadataElement(name="hasQuality", desc="Has Quality", readonly="true", values=[('FALSE', 'False'), ('TRUE', 'True')], param=metadata.SelectParameter)
+    MetadataElement(name="type", desc="Type", readonly="true", values=[('DNA', 'DNA'), ('PROTEIN', 'Protein')], param=metadata.SelectParameter)
+    MetadataElement(name="paired", desc="Paired-End", readonly="true", values=[('FALSE', 'False'), ('TRUE', 'True')], param=metadata.SelectParameter)
+    MetadataElement(name="maxLength", desc="Maximum sequence length", readonly="true", param=metadata.MetadataParameter)
+    MetadataElement(name="minLength", desc="Minimum sequence length", readonly="true", param=metadata.MetadataParameter)
+
+    def __init__( self, **kwd ):
+        Html.__init__( self, **kwd )
+        log.debug( "Rtg log info  %s" % ' __init__')
+        self.add_composite_file( 'format.log', mimetype = 'text/plain', description = 'Log', substitute_name_with_metadata = None, is_binary = False )
+        self.add_composite_file( 'done', mimetype = 'text/plain', description = 'Completion', substitute_name_with_metadata = None, is_binary = False )
+        self.add_composite_file( 'progress', mimetype = 'text/plain', description = 'Progress', substitute_name_with_metadata = None, is_binary = False )
+        self.add_composite_file( 'mainIndex', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
+        self.add_composite_file( 'nameIndex0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
+        self.add_composite_file( 'namedata0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
+        self.add_composite_file( 'namepointer0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
+        self.add_composite_file( 'seqdata0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
+        self.add_composite_file( 'seqpointer0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
+
+    def generate_primary_file( self, dataset = None ):
+        log.debug( "Rtg log info  %s %s" % ('generate_primary_file',dataset))
+        rval = ['<html><head><title>RTG SDF Dataset </title></head><p/>']
+        rval.append('<div>This SDF dataset is composed of the following files:<p/><ul>')
+        for composite_name, composite_file in self.get_composite_files( dataset = dataset ).iteritems():
+            fn = composite_name
+            log.debug( "Rtg log info  %s %s %s" % ('generate_primary_file',fn,composite_file))
+            opt_text = ''
+            if composite_file.optional:
+                opt_text = ' (optional)'
+            if composite_file.get('description'):
+                rval.append( '<li><a href="%s" type="application/octet-stream">%s (%s)</a>%s</li>' % ( fn, fn, composite_file.get('description'), opt_text ) )
+            else:
+                rval.append( '<li><a href="%s" type="application/octet-stream">%s</a>%s</li>' % ( fn, fn, opt_text ) )
+        rval.append( '</ul></div></html>' )
+        return "\n".join( rval )
+
+    def regenerate_primary_file(self,dataset):
+        """
+        cannot do this until we are setting metadata 
+        """
+        log.debug( "Rtg log info  %s %s" % ('regenerate_primary_file',dataset))
+        bn = dataset.metadata.base_name
+        flist = os.listdir(dataset.extra_files_path)
+        rval = ['<html><head><title>Files for RTG SDF Dataset %s</title></head><p/>Comprises the following files:<p/><ul>' % (bn)]
+        for i,fname in enumerate(flist):
+            sfname = os.path.split(fname)[-1]
+            rval.append( '<li><a href="%s">%s</a>' % ( sfname, sfname ) )
+        rval.append( '</ul></html>' )
+        f = file(dataset.file_name,'w')
+        f.write("\n".join( rval ))
+        f.write('\n')
+        f.close()
+
+    def set_meta( self, dataset, **kwd ):
+        Html.set_meta( self, dataset, **kwd )
+        self.regenerate_primary_file(dataset)
+        if (os.path.isdir(dataset.extra_files_path + '/left')):
+            sdfDir = dataset.extra_files_path + '/left'
+            dataset.metadata.paired = 'TRUE'
+        else:
+            sdfDir = dataset.extra_files_path
+            dataset.metadata.paired = 'FALSE'
+        p = os.popen(cfg.get('asection', 'rtg') + ' sdfstats ' + sdfDir,"r")
+        while 1:
+            line = p.readline()
+            if not line: 
+                break
+            if line.startswith('SDF-ID'):
+              dataset.metadata.sdfId = line.split(':', 1)[1].strip()
+            elif line.startswith('Number of sequences'):
+                dataset.metadata.sequences = line.split(':', 1)[1].strip()
+            elif line.startswith('Type'):
+                dataset.metadata.type = line.split(':', 1)[1].strip()
+            elif line.startswith('Source'):
+                dataset.metadata.source = line.split(':', 1)[1].strip()
+            elif line.startswith('Quality scores available'):
+                dataset.metadata.hasQuality = 'TRUE'
+            elif line.startswith('Maximum length'):
+                dataset.metadata.maxLength = line.split(':', 1)[1].strip()
+            elif line.startswith('Minimum length'):
+                dataset.metadata.minLength = line.split(':', 1)[1].strip()
+        if dataset.metadata.hasQuality != 'TRUE':
+            dataset.metadata.hasQuality = 'FALSE'
+
+    if __name__ == '__main__':
+        import doctest, sys
+        doctest.testmod(sys.modules[__name__])
+
+class Cgtsv ( Sequence ):
+    """Class representing a generic CG TSV sequence"""
+    file_ext = "tsvcg"
+
+    def set_meta( self, dataset, **kwd ):
+        """
+        Set the number of sequences and the number of data lines
+        in dataset.
+        """
+        if self.max_optional_metadata_filesize >= 0 and dataset.get_size() > self.max_optional_metadata_filesize:
+            dataset.metadata.sequences = None
+            return
+        sequences = 0
+        for line in file( dataset.file_name ):
+            line = line.strip()
+            if line:
+                if len(line) == 0 or line.startswith( '#' ) or line.startswith( '>' ):
+                    # We don't count comment lines for sequence data types
+                    continue
+                sequences += 1
+        dataset.metadata.sequences = sequences
+    def sniff ( self, filename ):
+        """
+        Determines whether the file is in CG TSV format
+        For details, see http://media.completegenomics.com/documents/DataFileFormats.pdf
+        """
+        bases_regexp = re.compile( "^[NGTAC]*" )
+        headers = get_headers( filename, '\t' )
+        try:
+            count = 0
+            if len(headers) < 2:
+                return False
+            for hdr in headers:
+                if len( hdr ) > 1 and hdr[0]:
+                    if hdr[0].startswith( '#' ):
+                        continue
+                    if len(hdr) != 3:
+                        return False
+                    if  hdr[0].startswith( '>' ):
+                        if hdr[0] != ">flags":
+                            return False
+                        if hdr[1] != "reads":
+                            return False
+                    else:
+                        try:
+                            map( int, [hdr[0]] )
+                            if not bases_regexp.match(hdr[1]):
+                                return False
+                        except:
+                            return False
+                    count += 1
+                    if count >= 5:
+                        return True
+                # Do other necessary checking here...
+        except:
+            return False
+        # If we haven't yet returned False, then...
+        return True
+
+class Samix( Binary ):
+    """Class describing a tabix-ed SAM file"""
+    file_ext = "sam.gz"
+    MetadataElement( name="sam_index", desc="SAM Index File", param=metadata.FileParameter, readonly=True, no_value=None, visible=False, optional=True )
+    def init_meta( self, dataset, copy_from=None ):
+        Binary.init_meta( self, dataset, copy_from=copy_from )
+    def set_meta( self, dataset, overwrite = True, **kwd ):
+        """ Creates the index for the SAM file. """
+        # These metadata values are not accessible by users, always overwrite
+        #f = open('/home/alan/galtmp', 'w')
+
+        index_file = dataset.metadata.sam_index
+        if not index_file:
+            index_file = dataset.metadata.spec['sam_index'].param.new_file( dataset = dataset )
+         #   print >>f, 'idx file ', index_file, '\n'
+        # Create the Sam index
+        stderr_name = tempfile.NamedTemporaryFile( prefix = "sam_index_stderr" ).name
+        command = cfg.get('asection', 'rtg') + (' index -f sam %s' % ( dataset.file_name))
+        #print >>f, 'idx cmd ', command, '\n'
+        proc = subprocess.Popen( args=command, shell=True, stderr=open( stderr_name, 'wb' ) )
+        exit_code = proc.wait()
+        #Did index succeed?
+        stderr = open( stderr_name ).read().strip()
+        if stderr:
+            if exit_code != 0:
+                os.unlink( stderr_name ) #clean up
+                f.close();
+                raise Exception, "Error Setting tabix-ed SAM Metadata: %s" % stderr
+            else:
+                print stderr
+        #print >>f, 'move ', dataset.file_name, '.tbi to ', index_file.file_name
+        shutil.move(dataset.file_name + '.tbi', index_file.file_name)
+        dataset.metadata.sam_index = index_file
+       # f.close();
+        # Remove temp file
+        os.unlink( stderr_name )
+    def set_peek( self, dataset, is_multi_byte=False ):
+      if not dataset.dataset.purged:
+          dataset.peek  = "Tabix-ed sam alignments file"
+          dataset.blurb = data.nice_size( dataset.get_size() )
+      else:
+          dataset.peek = 'file does not exist'
+          dataset.blurb = 'file purged from disk'
+    def display_peek( self, dataset ):
+        try:
+            return dataset.peek
+        except:
+            return "Tabix-ed sam alignments file (%s)" % ( data.nice_size( dataset.get_size() ) )
+
--- a/rtg.py	Sat Apr 21 21:32:21 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,239 +0,0 @@
-"""
-rtg datatypes
-"""
-
-import data
-from galaxy.datatypes import sequence
-import logging, os, sys, time, tempfile, shutil, string, glob, re, subprocess
-import galaxy.model
-from galaxy.datatypes import metadata
-from galaxy.datatypes.metadata import MetadataElement
-from galaxy import util
-from galaxy.datatypes.images import Html
-from galaxy.datatypes.sequence import Sequence
-from galaxy.datatypes.binary import Binary
-from sniff import *
-from pprint import pprint
-from ConfigParser import ConfigParser
-
-log = logging.getLogger(__name__)
-basepath = os.path.dirname(__file__)
-rtgcfg = os.path.abspath(os.path.join(basepath, "..", "..", "..", "tools", "rtg", "rtg-galaxy.cfg"))
-
-class FakeSecHead(object):
-    def __init__(self, fp):
-        self.fp = fp
-        self.sechead = '[asection]\n'
-    def readline(self):
-        if self.sechead:
-          try: return self.sechead
-          finally: self.sechead = None
-        else: return self.fp.readline()
-
-cfg = ConfigParser()
-cfg.readfp(FakeSecHead(open(rtgcfg)))
-
-class Sdf( Html ):
-    composite_type = 'auto_primary_file'
-    allow_datatype_change = False
-    file_ext = 'sdf'
-
-    MetadataElement(name="sdfId", desc="SDF Id", readonly="true", param=metadata.MetadataParameter)
-    MetadataElement(name="source", desc="Source", readonly="true", values=[('UNKNOWN', 'Unknown'), ('CG', 'Complete Genomics'), ('SOLEXA', 'Solexa')], param=metadata.SelectParameter)
-    MetadataElement(name="sequences", desc="Number of Sequences", readonly="true", param=metadata.MetadataParameter)
-    MetadataElement(name="hasQuality", desc="Has Quality", readonly="true", values=[('FALSE', 'False'), ('TRUE', 'True')], param=metadata.SelectParameter)
-    MetadataElement(name="type", desc="Type", readonly="true", values=[('DNA', 'DNA'), ('PROTEIN', 'Protein')], param=metadata.SelectParameter)
-    MetadataElement(name="paired", desc="Paired-End", readonly="true", values=[('FALSE', 'False'), ('TRUE', 'True')], param=metadata.SelectParameter)
-    MetadataElement(name="maxLength", desc="Maximum sequence length", readonly="true", param=metadata.MetadataParameter)
-    MetadataElement(name="minLength", desc="Minimum sequence length", readonly="true", param=metadata.MetadataParameter)
-
-    def __init__( self, **kwd ):
-        Html.__init__( self, **kwd )
-        log.debug( "Rtg log info  %s" % ' __init__')
-        self.add_composite_file( 'format.log', mimetype = 'text/plain', description = 'Log', substitute_name_with_metadata = None, is_binary = False )
-        self.add_composite_file( 'done', mimetype = 'text/plain', description = 'Completion', substitute_name_with_metadata = None, is_binary = False )
-        self.add_composite_file( 'progress', mimetype = 'text/plain', description = 'Progress', substitute_name_with_metadata = None, is_binary = False )
-        self.add_composite_file( 'mainIndex', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
-        self.add_composite_file( 'nameIndex0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
-        self.add_composite_file( 'namedata0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
-        self.add_composite_file( 'namepointer0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
-        self.add_composite_file( 'seqdata0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
-        self.add_composite_file( 'seqpointer0', mimetype = 'application/octet-stream', description = 'Index', substitute_name_with_metadata = None, is_binary = True )
-
-    def generate_primary_file( self, dataset = None ):
-        log.debug( "Rtg log info  %s %s" % ('generate_primary_file',dataset))
-        rval = ['<html><head><title>RTG SDF Dataset </title></head><p/>']
-        rval.append('<div>This SDF dataset is composed of the following files:<p/><ul>')
-        for composite_name, composite_file in self.get_composite_files( dataset = dataset ).iteritems():
-            fn = composite_name
-            log.debug( "Rtg log info  %s %s %s" % ('generate_primary_file',fn,composite_file))
-            opt_text = ''
-            if composite_file.optional:
-                opt_text = ' (optional)'
-            if composite_file.get('description'):
-                rval.append( '<li><a href="%s" type="application/octet-stream">%s (%s)</a>%s</li>' % ( fn, fn, composite_file.get('description'), opt_text ) )
-            else:
-                rval.append( '<li><a href="%s" type="application/octet-stream">%s</a>%s</li>' % ( fn, fn, opt_text ) )
-        rval.append( '</ul></div></html>' )
-        return "\n".join( rval )
-
-    def regenerate_primary_file(self,dataset):
-        """
-        cannot do this until we are setting metadata 
-        """
-        log.debug( "Rtg log info  %s %s" % ('regenerate_primary_file',dataset))
-        bn = dataset.metadata.base_name
-        flist = os.listdir(dataset.extra_files_path)
-        rval = ['<html><head><title>Files for RTG SDF Dataset %s</title></head><p/>Comprises the following files:<p/><ul>' % (bn)]
-        for i,fname in enumerate(flist):
-            sfname = os.path.split(fname)[-1]
-            rval.append( '<li><a href="%s">%s</a>' % ( sfname, sfname ) )
-        rval.append( '</ul></html>' )
-        f = file(dataset.file_name,'w')
-        f.write("\n".join( rval ))
-        f.write('\n')
-        f.close()
-
-    def set_meta( self, dataset, **kwd ):
-        Html.set_meta( self, dataset, **kwd )
-        self.regenerate_primary_file(dataset)
-        if (os.path.isdir(dataset.extra_files_path + '/left')):
-            sdfDir = dataset.extra_files_path + '/left'
-            dataset.metadata.paired = 'TRUE'
-        else:
-            sdfDir = dataset.extra_files_path
-            dataset.metadata.paired = 'FALSE'
-        p = os.popen(cfg.get('asection', 'rtg') + ' sdfstats ' + sdfDir,"r")
-        while 1:
-            line = p.readline()
-            if not line: 
-                break
-            if line.startswith('SDF-ID'):
-              dataset.metadata.sdfId = line.split(':', 1)[1].strip()
-            elif line.startswith('Number of sequences'):
-                dataset.metadata.sequences = line.split(':', 1)[1].strip()
-            elif line.startswith('Type'):
-                dataset.metadata.type = line.split(':', 1)[1].strip()
-            elif line.startswith('Source'):
-                dataset.metadata.source = line.split(':', 1)[1].strip()
-            elif line.startswith('Quality scores available'):
-                dataset.metadata.hasQuality = 'TRUE'
-            elif line.startswith('Maximum length'):
-                dataset.metadata.maxLength = line.split(':', 1)[1].strip()
-            elif line.startswith('Minimum length'):
-                dataset.metadata.minLength = line.split(':', 1)[1].strip()
-        if dataset.metadata.hasQuality != 'TRUE':
-            dataset.metadata.hasQuality = 'FALSE'
-
-    if __name__ == '__main__':
-        import doctest, sys
-        doctest.testmod(sys.modules[__name__])
-
-class Cgtsv ( Sequence ):
-    """Class representing a generic CG TSV sequence"""
-    file_ext = "tsvcg"
-
-    def set_meta( self, dataset, **kwd ):
-        """
-        Set the number of sequences and the number of data lines
-        in dataset.
-        """
-        if self.max_optional_metadata_filesize >= 0 and dataset.get_size() > self.max_optional_metadata_filesize:
-            dataset.metadata.sequences = None
-            return
-        sequences = 0
-        for line in file( dataset.file_name ):
-            line = line.strip()
-            if line:
-                if len(line) == 0 or line.startswith( '#' ) or line.startswith( '>' ):
-                    # We don't count comment lines for sequence data types
-                    continue
-                sequences += 1
-        dataset.metadata.sequences = sequences
-    def sniff ( self, filename ):
-        """
-        Determines whether the file is in CG TSV format
-        For details, see http://media.completegenomics.com/documents/DataFileFormats.pdf
-        """
-        bases_regexp = re.compile( "^[NGTAC]*" )
-        headers = get_headers( filename, '\t' )
-        try:
-            count = 0
-            if len(headers) < 2:
-                return False
-            for hdr in headers:
-                if len( hdr ) > 1 and hdr[0]:
-                    if hdr[0].startswith( '#' ):
-                        continue
-                    if len(hdr) != 3:
-                        return False
-                    if  hdr[0].startswith( '>' ):
-                        if hdr[0] != ">flags":
-                            return False
-                        if hdr[1] != "reads":
-                            return False
-                    else:
-                        try:
-                            map( int, [hdr[0]] )
-                            if not bases_regexp.match(hdr[1]):
-                                return False
-                        except:
-                            return False
-                    count += 1
-                    if count >= 5:
-                        return True
-                # Do other necessary checking here...
-        except:
-            return False
-        # If we haven't yet returned False, then...
-        return True
-
-class Samix( Binary ):
-    """Class describing a tabix-ed SAM file"""
-    file_ext = "sam.gz"
-    MetadataElement( name="sam_index", desc="SAM Index File", param=metadata.FileParameter, readonly=True, no_value=None, visible=False, optional=True )
-    def init_meta( self, dataset, copy_from=None ):
-        Binary.init_meta( self, dataset, copy_from=copy_from )
-    def set_meta( self, dataset, overwrite = True, **kwd ):
-        """ Creates the index for the SAM file. """
-        # These metadata values are not accessible by users, always overwrite
-        #f = open('/home/alan/galtmp', 'w')
-
-        index_file = dataset.metadata.sam_index
-        if not index_file:
-            index_file = dataset.metadata.spec['sam_index'].param.new_file( dataset = dataset )
-         #   print >>f, 'idx file ', index_file, '\n'
-        # Create the Sam index
-        stderr_name = tempfile.NamedTemporaryFile( prefix = "sam_index_stderr" ).name
-        command = cfg.get('asection', 'rtg') + (' index -f sam %s' % ( dataset.file_name))
-        #print >>f, 'idx cmd ', command, '\n'
-        proc = subprocess.Popen( args=command, shell=True, stderr=open( stderr_name, 'wb' ) )
-        exit_code = proc.wait()
-        #Did index succeed?
-        stderr = open( stderr_name ).read().strip()
-        if stderr:
-            if exit_code != 0:
-                os.unlink( stderr_name ) #clean up
-                f.close();
-                raise Exception, "Error Setting tabix-ed SAM Metadata: %s" % stderr
-            else:
-                print stderr
-        #print >>f, 'move ', dataset.file_name, '.tbi to ', index_file.file_name
-        shutil.move(dataset.file_name + '.tbi', index_file.file_name)
-        dataset.metadata.sam_index = index_file
-       # f.close();
-        # Remove temp file
-        os.unlink( stderr_name )
-    def set_peek( self, dataset, is_multi_byte=False ):
-      if not dataset.dataset.purged:
-          dataset.peek  = "Tabix-ed sam alignments file"
-          dataset.blurb = data.nice_size( dataset.get_size() )
-      else:
-          dataset.peek = 'file does not exist'
-          dataset.blurb = 'file purged from disk'
-    def display_peek( self, dataset ):
-        try:
-            return dataset.peek
-        except:
-            return "Tabix-ed sam alignments file (%s)" % ( data.nice_size( dataset.get_size() ) )
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/cg2sdf.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,17 @@
+<tool id="rtg_cg2sdf" name="Format CG TSV">
+  <description>to SDF with rtg cg2sdf</description>
+  <command interpreter="bash">galaxy-rtg-wrapper.sh cg2sdf 
+$input1
+-o ${output.extra_files_path} >$output</command>
+  <inputs>
+        <param name="input1" type="data" format="tsvcg" label="Source CG TSV file" help=""/>
+  </inputs>
+  <outputs>
+    <data format="rtg_sdf" name="output" />
+  </outputs>
+
+  <help>
+This tool formats a CG TSV file to RTG SDF.
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/cgmap.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,36 @@
+<tool id="rtg_cgmap" name="CG map">
+  <description>reads with rtg cg map</description>
+  <command interpreter="bash">galaxy-rtg-map-wrapper.sh paired $output1 $output2 $__new_file_path__ 
+cgmap -t ${template.extra_files_path} 
+--repeat-freq ${repeat}
+-i ${reads.extra_files_path}
+--min-insert-size $minlength --max-insert-size $maxlength
+--max-mated-score $maxscore --max-unmated-score $maxuscore
+</command>
+  <inputs>
+    <param name="template" type="data" format="rtg_sdf" label="Reference SDF"/>
+    <param name="reads" type="data" format="rtg_sdf" label="Reads SDF"/>
+    <param name="repeat" type="text" value="90%" label="Repeat frequency">
+      <sanitizer sanitize="False"/>
+    </param>
+
+	<param name="maxscore" type="text" value="10%" label="Maximum alignment score for mated reads">
+	  <sanitizer sanitize="False"/>
+	</param>
+        <param name="maxuscore" type="text" value="10%" label="Maximum alignment score for umated reads">
+	  <sanitizer sanitize="False"/>
+	</param>
+        <param name="minlength" type="integer" value="0" label="Minimum insert size"/>
+	<param name="maxlength" type="integer" value="1000" label="Maximum insert size"/>
+
+  </inputs>
+  <outputs>
+    <data name="output1" format="samix" label="Cgmap mated on reads data ${reads.hid} and template data ${template.hid}"/>
+    <data name="output2" format="samix" label="Cgmap unmated on reads data ${reads.hid} and template data ${template.hid}"/>
+  </outputs>
+
+  <help>
+This tool performs a NGS read mapping using rtg cgmap
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/cgsim.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,43 @@
+<tool id="rtg_cgsim" name="Simulate CG reads">
+  <description>with RTG cgsim</description>
+  <command interpreter="bash">galaxy-rtg-wrapper.sh cgsim
+-t ${input.extra_files_path}
+#if $limit.sType == "numreads":
+-n $limit.n
+#else
+-c $limit.c
+#end if
+-m $m
+-M $M
+--seed $seed
+-o ${output.extra_files_path} >$output</command>
+  <inputs>
+
+    <param name="input" type="data" format="rtg_sdf" label="Source SDF"/>
+    <param name="m" type="integer" value="350" label="Minimum fragment length" help=""/>
+    <param name="M" type="integer" value="500" label="Maximum fragment length" help=""/>
+
+    <conditional name="limit">
+      <param name="sType" type="select" label="Select read limit">
+        <option value="numreads">Fixed number of reads</option>
+        <option value="coverage">Fixed coverage</option>
+      </param>
+      <when value="numreads">
+        <param name="n" type="integer" value="1000" label="Number of reads" help="Total number of reads"/>
+      </when>
+      <when value="coverage">
+        <param name="c" type="float" value="1" label="Coverage" help="Total coverage"/>
+      </when>
+    </conditional>	
+
+    <param name="seed" type="integer" label="Seed" value="42" help="Seed for the random number generator"/>
+  </inputs>
+  <outputs>
+    <data format="rtg_sdf" name="output" />
+  </outputs>
+
+  <help>
+This tool creates an SDF containing randomly generated CG reads.
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/coverage.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,26 @@
+<tool id="rtg_coverage" name="Coverage">
+  <description>coverage</description>
+  <command interpreter="bash">galaxy-rtg-singleoutput-wrapper.sh $output $output.id $__new_file_path__ coverage.bed
+coverage -t ${template.extra_files_path} 
+$input1
+#for $i in $inputs
+  ${i.input}
+#end for
+-Z
+</command>
+  <inputs>
+    <param name="template" type="data" format="rtg_sdf" label="Reference SDF"/>
+    <param name="input1" label="First SAM file" type="data" format="sam,samix" />
+    <repeat name="inputs" title="Input SAM Files">
+      <param name="input" label="Add file" type="data" format="sam,samix" />
+    </repeat>
+  </inputs>
+  <outputs>
+    <data name="output" format="bed"/>
+  </outputs>
+
+  <help>
+This tool calculates coverage using rtg coverage 
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/format_fasta.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,41 @@
+<tool id="rtg_format_fasta" name="Format FASTA">
+  <description>to SDF with rtg format</description>
+  <command interpreter="bash">galaxy-rtg-wrapper.sh format 
+#if $paired.sPaired == "paired":
+-l $paired.input1
+-r $paired.input2 
+#else:
+$paired.input1
+#end if
+#if str($protein) == "true":
+-p
+#end if
+-o ${output.extra_files_path} >$output</command>
+  <inputs>
+    <conditional name="paired">
+      <param name="sPaired" type="select" label="Are you formatting paired-end reads?">
+        <option value="single">Non-read data or single-end</option>
+        <option value="paired">Paired-end</option>
+      </param>
+      <when value="single">
+        <param name="input1" type="data" format="fasta" label="Source FASTA file"/>
+      </when>
+      <when value="paired">
+        <param name="input1" type="data" format="fasta" label="First of pair FASTA file"/>
+        <param name="input2" type="data" format="fasta" label="Second of pairFASTA file"/>
+      </when>
+    </conditional>
+    <param name="protein" type="select" label="Input consists of protein">
+      <option value="false" selected="true">False</option>	
+      <option value="true">True</option>	
+    </param>
+  </inputs>
+  <outputs>
+    <data format="rtg_sdf" name="output" />
+  </outputs>
+
+  <help>
+This tool formats a FASTA file to RTG SDF.
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/format_fastq.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,48 @@
+<tool id="rtg_format_fastq" name="Format FASTQ">
+  <description>to SDF with rtg format</description>
+  <command interpreter="bash">galaxy-rtg-wrapper.sh format
+-f fastq 
+#if $paired.sPaired == "paired":
+-l $paired.input1
+-r $paired.input2 
+#else:
+$paired.input1
+#end if
+#if str($protein) == "true":
+-p
+#end if
+-q $quality_format
+-o ${output.extra_files_path} >$output</command>
+  <inputs>
+    <conditional name="paired">
+      <param name="sPaired" type="select" label="Are you formatting paired-end reads?">
+        <option value="single">Non-read data or single-end</option>
+        <option value="paired">Paired-end</option>
+      </param>
+      <when value="single">
+        <param name="input1" type="data" format="fastq" label="Source FASTQ file"/>
+      </when>
+      <when value="paired">
+        <param name="input1" type="data" format="fastq" label="First of pair FASTA file"/>
+        <param name="input2" type="data" format="fastq" label="Second of pair FASTA file"/>
+      </when>
+    </conditional>
+    <param name="quality_format" type="select" label="Quality format">
+      <option value="sanger" selected="true">Sanger</option>
+      <option value="solexa">Solexa</option>
+      <option value="illumina">Illumina</option>
+    </param>	
+    <param name="protein" type="select" label="Input consists of protein">
+      <option value="false" selected="true">False</option>
+      <option value="true">True</option>
+    </param>
+  </inputs>
+  <outputs>
+    <data format="rtg_sdf" name="output" />
+  </outputs>
+
+  <help>
+This tool formats a FASTQ file to RTG SDF.
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/galaxy-rtg-map-wrapper.sh	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+source $DIR/rtg-galaxy.cfg
+
+# Temporary storage for STDERR
+# Temporary storage for mapping output
+TMP_STDERR=$(mktemp) || exit 1
+
+#echo "$(date) START $@" >>~/galaxy-rtg-wrapper.log
+
+paired=$1
+shift
+outputfile=$1
+shift
+if [ $paired == "paired" ]; then
+    outputfile2=$1
+fi
+shift
+outputdir=$1
+shift
+
+# Run the program, send STDERR to temporary file
+tmpout=$outputdir/tmpout$$
+$rtg "$@" -o $tmpout --legacy-cigars 2> $TMP_STDERR
+
+#check program's exit code
+if (( $? ));  then
+    #echo "$(date) FAIL $@" >>~/galaxy-rtg-wrapper.log
+    #cat $TMP_STDERR >>~/galaxy-rtg-wrapper.log
+    #Program failed, send STDERR to real STDERR
+    cat $TMP_STDERR >&2
+    rm $TMP_STDERR
+    rm -rf $tmpout
+    exit 1
+fi
+
+if [ -f $tmpout/mated.sam.gz ]; then
+    mv $tmpout/mated.sam.gz $outputfile
+    [ "$outputfile2" ] && mv $tmpout/unmated.sam.gz $outputfile2
+else
+    mv $tmpout/alignments.sam.gz $outputfile
+fi
+
+#echo "$(date) DONE $@" >>~/galaxy-rtg-wrapper.log
+
+#Program succeeded, delete STDERR file
+rm $TMP_STDERR
+rm -rf $tmpout
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/galaxy-rtg-mapx-wrapper.sh	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+source $DIR/rtg-galaxy.cfg
+
+# Temporary storage for STDERR
+# Temporary storage for mapping output
+TMP_STDERR=$(mktemp) || exit 1
+
+#echo "$(date) START $@" >>~/galaxy-rtg-wrapper.log
+
+outputfile=$1
+shift
+outputdir=$1
+shift
+
+# Run the program, send STDERR to temporary file
+tmpout=$outputdir/tmpout$$
+$rtg "$@" -Z -o $tmpout 2> $TMP_STDERR
+
+#check program's exit code
+if (( $? ));  then
+    #echo "$(date) FAIL $@" >>~/galaxy-rtg-wrapper.log
+    #cat $TMP_STDERR >>~/galaxy-rtg-wrapper.log
+    #Program failed, send STDERR to real STDERR
+    cat $TMP_STDERR >&2
+    rm $TMP_STDERR
+    rm -rf $tmpout
+    exit 1
+fi
+
+mv $tmpout/alignments.txt $outputfile
+
+#echo "$(date) DONE $@" >>~/galaxy-rtg-wrapper.log
+
+#Program succeeded, delete STDERR file
+rm $TMP_STDERR
+rm -rf $tmpout
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/galaxy-rtg-sdf2fasta-wrapper.sh	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+source $DIR/rtg-galaxy.cfg
+
+# Temporary storage for STDERR
+# Temporary storage for mapping output
+TMP_STDERR=$(mktemp) || exit 1
+
+#echo "$(date) START $@" >>~/galaxy-rtg-wrapper.log
+
+outputfile=$1
+shift
+outputid=$1
+shift
+outputdir=$1
+shift
+
+# Run the program, send STDERR to temporary file
+tmpout=$outputdir/tmpout$$
+$rtg sdf2fasta "$@" -o $tmpout 2> $TMP_STDERR
+
+#check program's exit code
+if (( $? ));  then
+    #echo "$(date) FAIL $@" >>~/galaxy-rtg-wrapper.log
+    #cat $TMP_STDERR >>~/galaxy-rtg-wrapper.log
+    #Program failed, send STDERR to real STDERR
+    cat $TMP_STDERR >&2
+    rm $TMP_STDERR
+    rm -rf $tmpout
+    exit 1
+fi
+
+if [ -f ${tmpout}_1.fasta ]; then
+    mv ${tmpout}_1.fasta $outputfile
+    mv ${tmpout}_2.fasta $outputdir/primary_${outputid}_output2_visible_fasta
+else
+    mv ${tmpout}.fasta $outputfile
+fi
+
+#echo "$(date) DONE $@" >>~/galaxy-rtg-wrapper.log
+
+#Program succeeded, delete STDERR file
+rm $TMP_STDERR
+rm -rf $tmpout
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/galaxy-rtg-singleoutput-wrapper.sh	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+source $DIR/rtg-galaxy.cfg
+
+# Temporary storage for STDERR
+# Temporary storage for mapping output
+TMP_STDERR=$(mktemp) || exit 1
+
+#echo "$(date) START $@" >>~/galaxy-rtg-wrapper.log
+
+outputfile=$1
+shift
+outputid=$1
+shift
+outputdir=$1
+shift
+outputfilename=$1
+shift
+
+# Run the program, send STDERR to temporary file
+tmpout=$outputdir/tmpout$$
+$rtg "$@" -o $tmpout 2> $TMP_STDERR
+
+#check program's exit code
+if (( $? ));  then
+    #echo "$(date) FAIL $@" >>~/galaxy-rtg-wrapper.log
+    #cat $TMP_STDERR >>~/galaxy-rtg-wrapper.log
+    #Program failed, send STDERR to real STDERR
+    cat $TMP_STDERR >&2
+    rm $TMP_STDERR
+    rm -rf $tmpout
+    exit 1
+fi
+
+mv $tmpout/$outputfilename $outputfile
+
+#echo "$(date) DONE $@" >>~/galaxy-rtg-wrapper.log
+
+#Program succeeded, delete STDERR file
+rm $TMP_STDERR
+rm -rf $tmpout
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/galaxy-rtg-snpintersect-wrapper.sh	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+source $DIR/rtg-galaxy.cfg
+
+# Temporary storage for STDERR
+TMP_STDERR=$(mktemp) || exit 1
+
+#echo "$(date) START $@" >>~/galaxy-rtg-wrapper.log
+# Run the program, send STDERR to temporary file
+$rtg snpintersect "$@" 2> $TMP_STDERR
+
+#check program's exit code
+if (( $? ));  then
+    #echo "$(date) FAIL $@" >>~/galaxy-rtg-wrapper.log
+    #cat $TMP_STDERR >>~/galaxy-rtg-wrapper.log
+    #Program failed, send STDERR to real STDERR
+    cat $TMP_STDERR >&2
+    rm $TMP_STDERR
+    exit 1
+fi
+#echo "$(date) DONE $@" >>~/galaxy-rtg-wrapper.log
+
+#Program succeeded, delete STDERR file
+rm $TMP_STDERR
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/galaxy-rtg-snpsim-wrapper.sh	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+source $DIR/rtg-galaxy.cfg
+
+# Temporary storage for STDERR
+# Temporary storage for mapping output
+TMP_STDERR=$(mktemp) || exit 1
+
+#echo "$(date) START $@" >>~/galaxy-rtg-wrapper.log
+
+snpfile=$1
+shift
+snpoutputdir=$1
+shift
+
+# Run the program, send STDERR to temporary file
+mkdir $snpoutputdir
+tmpout=$snpoutputdir/snps.vcf
+$rtg "$@" -s $tmpout -Z 2> $TMP_STDERR
+
+#check program's exit code
+if (( $? ));  then
+    #echo "$(date) FAIL $@" >>~/galaxy-rtg-wrapper.log
+    #cat $TMP_STDERR >>~/galaxy-rtg-wrapper.log
+    #Program failed, send STDERR to real STDERR
+    cat $TMP_STDERR >&2
+    rm $TMP_STDERR
+    rm -rf $tmpout
+    exit 1
+fi
+
+mv $tmpout $snpfile
+
+#echo "$(date) DONE $@" >>~/galaxy-rtg-wrapper.log
+
+#Program succeeded, delete STDERR file
+rm $TMP_STDERR
+rm -rf $snpoutputdir
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/galaxy-rtg-wrapper.sh	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+DIR="$( cd "$( dirname "$0" )" && pwd )"
+source $DIR/rtg-galaxy.cfg
+
+# Temporary storage for STDERR
+TMP_STDERR=$(mktemp) || exit 1
+
+#echo "$(date) START $@" >>~/galaxy-rtg-wrapper.log
+# Run the program, send STDERR to temporary file
+$rtg "$@" 2> $TMP_STDERR
+
+#check program's exit code
+if (( $? ));  then
+    #echo "$(date) FAIL $@" >>~/galaxy-rtg-wrapper.log
+    #cat $TMP_STDERR >>~/galaxy-rtg-wrapper.log
+    #Program failed, send STDERR to real STDERR
+    cat $TMP_STDERR >&2
+    rm $TMP_STDERR
+    exit 1
+fi
+#echo "$(date) DONE $@" >>~/galaxy-rtg-wrapper.log
+
+#Program succeeded, delete STDERR file
+rm $TMP_STDERR
+exit 0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/genomesim.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,20 @@
+<tool id="rtg_genomesim" name="Simulate a genome">
+  <description>with rtg genomesim</description>
+  <command interpreter="bash">galaxy-rtg-wrapper.sh genomesim
+--min-length $minlength --max-length $maxlength -n $numseqs --seed $seed
+-o ${output.extra_files_path} >$output</command>
+  <inputs>
+    <param name="minlength" type="integer" value="20000" label="Minimum contig length"/>
+    <param name="maxlength" type="integer" value="100000" label="Maximum contig length"/>
+    <param name="numseqs" type="integer" value="10" label="Number of contigs"/>
+    <param name="seed" type="integer" value="42" label="Seed" help="Seed for the random number generator"/>
+  </inputs>
+  <outputs>
+    <data format="rtg_sdf" name="output" />
+  </outputs>
+
+  <help>
+This tool creates an SDF containing randomly generated contigs representing a genome.
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/map.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,55 @@
+<tool id="rtg_map" name="Map">
+  <description>reads with rtg map</description>
+  <command interpreter="bash">galaxy-rtg-map-wrapper.sh $paired.sPaired $output1 $output2 $__new_file_path__
+map -t ${template.extra_files_path} 
+--repeat-freq ${repeat}
+-i ${reads.extra_files_path}
+#if $paired.sPaired == "paired":
+--min-insert-size $paired.minlength --max-insert-size $paired.maxlength
+--max-mated-score $paired.maxscore --max-unmated-score $paired.maxuscore
+#else:
+--max-alignment-score $paired.maxscore
+#end if
+</command>
+  <inputs>
+    <param name="template" type="data" format="rtg_sdf" label="Reference SDF"/>
+    <param name="reads" type="data" format="rtg_sdf" label="Reads SDF"/>
+    <param name="repeat" type="text" value="90%" label="Repeat frequency">
+      <sanitizer sanitize="False"/>
+    </param>
+
+    <conditional name="paired">
+      <param name="sPaired" type="select" label="Are you mapping paired-end reads?">
+        <option value="paired">Paired-end</option>
+        <option value="single">Single-end</option>
+      </param>
+      <when value="single">
+	<param name="maxscore" type="text" value="10%" label="Maximum alignment score for reads (percentages do not work ATM)">
+	  <sanitizer sanitize="False"/>
+	</param>
+      </when>
+      <when value="paired">
+	<param name="maxscore" type="text" value="10%" label="Maximum alignment score for mated reads">
+	  <sanitizer sanitize="False"/>
+	</param>
+        <param name="maxuscore" type="text" value="10%" label="Maximum alignment score for umated reads">
+	  <sanitizer sanitize="False"/>
+	</param>
+        <param name="minlength" type="integer" value="200" label="Minimum insert size"/>
+	<param name="maxlength" type="integer" value="400" label="Maximum insert size"/>
+      </when>
+    </conditional>	
+
+  </inputs>
+  <outputs>
+    <data name="output1" format="samix" />
+    <data name="output2" format="samix" >
+      <filter>paired['sPaired'] == "paired"</filter>
+    </data>
+  </outputs>
+
+  <help>
+This tool performs a NGS read mapping using rtg map
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/mapf.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,53 @@
+<tool id="rtg_mapf" name="Mapf">
+  <description>reads with rtg mapf</description>
+  <command interpreter="bash">galaxy-rtg-map-wrapper.sh $paired.sPaired $output1 $output2 $__new_file_path__ 
+mapf -t ${template.extra_files_path} 
+--repeat-freq ${repeat}
+-i ${reads.extra_files_path}
+#if $paired.sPaired == "paired":
+--min-insert-size $paired.minlength --max-insert-size $paired.maxlength
+--max-mated-score $paired.maxscore --max-unmated-score $paired.maxuscore
+#else:
+--max-alignment-score $paired.maxscore
+#end if
+--sam
+</command>
+  <inputs>
+    <param name="template" type="data" format="rtg_sdf" label="Reference SDF"/>
+    <param name="reads" type="data" format="rtg_sdf" label="Reads SDF"/>
+    <param name="repeat" type="text" value="90%" label="Repeat frequency">
+      <sanitizer sanitize="False"/>
+    </param>
+
+    <conditional name="paired">
+      <param name="sPaired" type="select" label="Are you mapping paired-end reads?">
+        <option value="paired">Paired-end</option>
+        <option value="single">Single-end</option>
+      </param>
+      <when value="single">
+	<param name="maxscore" type="text" value="10%" label="Maximum alignment score for reads (percentages do not work ATM)">
+	  <sanitizer sanitize="False"/>
+	</param>
+      </when>
+      <when value="paired">
+	<param name="maxscore" type="text" value="10%" label="Maximum alignment score for mated reads">
+	  <sanitizer sanitize="False"/>
+	</param>
+        <param name="maxuscore" type="text" value="10%" label="Maximum alignment score for umated reads">
+	  <sanitizer sanitize="False"/>
+	</param>
+        <param name="minlength" type="integer" value="200" label="Minimum insert size"/>
+	<param name="maxlength" type="integer" value="400" label="Maximum insert size"/>
+      </when>
+    </conditional>	
+
+  </inputs>
+  <outputs>
+    <data name="output1" format="samix" />
+  </outputs>
+
+  <help>
+This tool filters reads for contaminant sequences by mapping them against the contaminant template using rtg mapf
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/mapx.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,29 @@
+<tool id="rtg_mapx" name="MapX">
+  <description>protein reads with rtg mapx</description>
+  <command interpreter="bash">galaxy-rtg-mapx-wrapper.sh $output1 $__new_file_path__ 
+mapx -t ${template.extra_files_path} 
+--repeat-freq ${repeat}
+-i ${reads.extra_files_path}
+--max-alignment-score $maxscore
+</command>
+  <inputs>
+    <param name="template" type="data" format="rtg_sdf" label="Reference SDF"/>
+    <param name="reads" type="data" format="rtg_sdf" label="Reads SDF"/>
+    <param name="repeat" type="text" value="90%" label="Repeat frequency">
+      <sanitizer sanitize="False"/>
+    </param>
+
+	<param name="maxscore" type="text" value="10%" label="Maximum alignment score for reads (percentages do not work ATM)">
+	  <sanitizer sanitize="False"/>
+	</param>
+
+  </inputs>
+  <outputs>
+    <data name="output1" format="tabular" />
+  </outputs>
+
+  <help>
+This tool performs a NGS protein read mapping using rtg mapx
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/readsim.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,75 @@
+<tool id="rtg_readsim" name="Simulate reads">
+  <description>with RTG readsim</description>
+  <command interpreter="bash">galaxy-rtg-wrapper.sh readsim
+-t ${input.extra_files_path}
+#if str($input2) != "None":
+-T ${input2.extra_files_path}
+#end if
+#if $limit.sType == "numreads":
+-n $limit.n
+#else
+-c $limit.c
+#end if
+-m $m
+-M $M
+--machine $machine.sMachine
+#if $machine.sMachine == "illumina_se":
+-r $machine.r
+#else if $machine.sMachine == "illumina_pe":
+-L $machine.L
+-R $machine.R
+#else if $machine.sMachine == "454_pe":
+--454-min-total-size $machine.454-min
+--454-max-total-size $machine.454-max
+#end if
+--seed $seed
+-o ${output.extra_files_path} >$output</command>
+  <inputs>
+
+    <param name="input" type="data" format="rtg_sdf" label="SDF containing input genome"/>
+    <param name="input2" type="data" format="rtg_sdf" label="SDF with second genome for simulating diploid genomes" optional="true" />
+    <param name="m" type="integer" value="200" label="Minimum fragment length" help="Total number of reads"/>
+    <param name="M" type="integer" value="400" label="Minimum fragment length" help="Total number of reads"/>
+
+    <conditional name="limit">
+      <param name="sType" type="select" label="Select read limit">
+        <option value="numreads">Fixed number of reads</option>
+        <option value="coverage">Fixed coverage</option>
+      </param>
+      <when value="numreads">
+        <param name="n" type="integer" value="1000" label="Number of reads" help="Total number of reads"/>
+      </when>
+      <when value="coverage">
+        <param name="c" type="float" value="1" label="Coverage" help="Total coverage"/>
+      </when>
+    </conditional>	
+
+    <conditional name="machine">
+      <param name="sMachine" type="select" label="Select machine type">
+        <option value="illumina_pe">Illumina paired-end</option>
+        <option value="illumina_se">Illumina single-end</option>
+        <option value="454_pe">454 paired-end</option>
+      </param>
+      <when value="illumina_se">
+        <param name="r" type="integer" value="100" label="Read length" help="Target read length on left side"/>
+      </when>
+      <when value="illumina_pe">
+        <param name="L" type="integer" value="100" label="Left read length" help="Target read length on left side"/>
+        <param name="R" type="integer" value="100" label="Right read length" help="Target read length on right side"/>
+      </when>
+      <when value="454_pe">
+        <param name="454-min" type="integer" value="500" label="Minimum total length" help="Minimum sum of left and right read lengths"/>
+        <param name="454-max" type="integer" value="300" label="Maximum total length" help="Maximum sum of left and right read lengths"/>
+      </when>
+    </conditional>	
+    <param name="seed" type="integer" value="42" label="Seed" help="Seed for the random number generator"/>
+  </inputs>
+  <outputs>
+    <data format="rtg_sdf" name="output" />
+  </outputs>
+
+  <help>
+This tool creates an SDF containing randomly generated reads.
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/rtg-galaxy.cfg	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,2 @@
+rtg=/rtgshare/tools/rtg-latest/rtg
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/sdf2fasta.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,20 @@
+<tool id="rtg_sdf2fasta" name="Extract FASTA" force_history_refresh="True">
+  <description>from SDF with sdf2fasta</description>
+  <command interpreter="bash">galaxy-rtg-sdf2fasta-wrapper.sh $output1 $output1.id $__new_file_path__
+-l $l 
+-i ${input.extra_files_path}
+-Z
+</command>
+  <inputs>
+    <param name="input" type="data" format="rtg_sdf" label="Source SDF"/>
+    <param name="l" type="integer" value="80" label="Line length"/>
+  </inputs>
+  <outputs>
+    <data name="output1" format="fasta"/>
+  </outputs>
+
+  <help>
+This tool converts an RTG SDF to FASTA.
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/snp.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,37 @@
+<tool id="rtg_snp" name="Call SNPs">
+  <description>from SAM files with rtg snp</description>
+  <command interpreter="bash">galaxy-rtg-singleoutput-wrapper.sh $output $output.id $__new_file_path__ snps.vcf
+snp -t ${template.extra_files_path} 
+--max-as-mated $maxscore
+--max-as-unmated $maxuscore
+--machine-errors $machine
+$input1
+#for $i in $inputs
+  ${i.input}
+#end for
+-Z
+</command>
+  <inputs>
+    <param name="template" type="data" format="rtg_sdf" label="Reference SDF"/>
+    <param name="maxscore" type="integer" value="3" label="Maximum alignment score for mated reads"/>
+    <param name="maxuscore" type="integer" value="1" label="Maximum alignment score for umated reads"/>
+    <param name="machine" type="select" label="Select machine type">
+      <option value="illumina">Illumina</option>
+      <option value="cg">Complete Genomics</option>
+      <option value="454_se">454 single-end</option>
+      <option value="454_pe">454 paired-end</option>
+    </param>
+    <param name="input1" label="First tabix-ed SAM file" type="data" format="samix" />
+    <repeat name="inputs" title="Input tabix-ed SAM Files">
+      <param name="input" label="Add file" type="data" format="samix" />
+    </repeat>
+  </inputs>
+  <outputs>
+    <data name="output" format="vcf" />
+  </outputs>
+
+  <help>
+This tool calls snps from SAM files
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/snpintersection.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,19 @@
+<tool id="rtg_snpintersection" name="SNP intersection">
+  <description>with RTG SNP intersection</description>
+  <command interpreter="bash">galaxy-rtg-snpintersect-wrapper.sh 
+-Z -i ${input}
+-I ${input2}
+-o ${output.extra_files_path} >$output</command>
+  <inputs>
+    <param name="input" type="data" format="vcf" label="first SNPs input file"/>
+    <param name="input2" type="data" format="vcf" label="second SNPs input file" />
+  </inputs>
+  <outputs>
+    <data format="vcf" name="output" />
+  </outputs>
+
+  <help>
+This tool creates an SNP intersection.
+  </help>
+
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/rtg/snpsim.xml	Sat Apr 21 21:36:15 2012 -0400
@@ -0,0 +1,30 @@
+<tool id="rtg_snpsim" name="Simulate SNPs">
+  <description>with rtg snpsim</description>
+  <command interpreter="bash">galaxy-rtg-snpsim-wrapper.sh ${output3} ${output3.extra_files_path} snpsim
+ --seed $seed -i ${input.extra_files_path} 
+-o ${output.extra_files_path}
+#if $str($diploid) == "true":
+-O ${output2.extra_files_path}
+#end if
+>$output</command>
+  <inputs>
+    <param name="input" type="data" format="rtg_sdf" label="SDF containing input genome"/>
+    <param name="diploid" type="select" label="Generate diploid mutations">
+      <option value="true">Yes</option>
+      <option value="false" selected="true">No</option>
+    </param>
+    <param name="seed" type="integer" value="42" label="Seed" help="Seed for the random number generator"/>
+  </inputs>
+  <outputs>
+    <data format="rtg_sdf" name="output" label="Mutated genome on data ${input.hid}"/>
+    <data format="rtg_sdf" name="output2" label="Second mutated genome on data ${input.hid}">
+      <filter>diploid == "true"</filter>
+    </data>
+    <data format="vcf" name="output3" label="SNPs file generated on data ${input.hid}" />
+  </outputs>
+
+  <help>
+This tool creates a simulated mutation of a reference genome. Can generate either haploid or diploid mutations.
+  </help>
+
+</tool>