Repository 'sam_pileup'
hg clone https://toolshed.g2.bx.psu.edu/repos/devteam/sam_pileup

Changeset 4:a3b4ad6858ff (2020-02-06)
Previous changeset 3:890d97772e2a (2014-01-09)
Commit message:
"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/sam_pileup commit 8301d37348be25a038b3c63b049b1178d05f5003"
modified:
sam_pileup.xml
removed:
sam_pileup.py
tool_dependencies.xml
b
diff -r 890d97772e2a -r a3b4ad6858ff sam_pileup.py
--- a/sam_pileup.py Thu Jan 09 14:28:39 2014 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
[
@@ -1,146 +0,0 @@
-#!/usr/bin/env python
-
-"""
-Creates a pileup file from a bam file and a reference.
-
-usage: %prog [options]
-   -p, --input1=p: bam file
-   -o, --output1=o: Output pileup
-   -R, --ref=R: Reference file type
-   -n, --ownFile=n: User-supplied fasta reference file
-   -b, --bamIndex=b: BAM index file
-   -g, --index=g: Path of the indexed reference genome
-   -s, --lastCol=s: Print the mapping quality as the last column
-   -i, --indels=i: Only output lines containing indels
-   -M, --mapCap=M: Cap mapping quality
-   -c, --consensus=c: Call the consensus sequence using MAQ consensu model
-   -T, --theta=T: Theta paramter (error dependency coefficient)
-   -N, --hapNum=N: Number of haplotypes in sample
-   -r, --fraction=r: Expected fraction of differences between a pair of haplotypes
-   -I, --phredProb=I: Phred probability of an indel in sequencing/prep
-
-"""
-
-import os, shutil, subprocess, sys, tempfile
-from galaxy import eggs
-import pkg_resources; pkg_resources.require( "bx-python" )
-from bx.cookbook import doc_optparse
-
-def stop_err( msg ):
-    sys.stderr.write( '%s\n' % msg )
-    sys.exit()
-
-def __main__():
-    #Parse Command Line
-    options, args = doc_optparse.parse( __doc__ )
-    # output version # of tool
-    try:
-        tmp = tempfile.NamedTemporaryFile().name
-        tmp_stdout = open( tmp, 'wb' )
-        proc = subprocess.Popen( args='samtools 2>&1', shell=True, stdout=tmp_stdout )
-        tmp_stdout.close()
-        returncode = proc.wait()
-        stdout = None
-        for line in open( tmp_stdout.name, 'rb' ):
-            if line.lower().find( 'version' ) >= 0:
-                stdout = line.strip()
-                break
-        if stdout:
-            sys.stdout.write( 'Samtools %s\n' % stdout )
-        else:
-            raise Exception
-    except:
-        sys.stdout.write( 'Could not determine Samtools version\n' )
-    #prepare file names 
-    tmpDir = tempfile.mkdtemp()
-    tmpf0 = tempfile.NamedTemporaryFile( dir=tmpDir )
-    tmpf0_name = tmpf0.name
-    tmpf0.close()
-    tmpf0bam_name = '%s.bam' % tmpf0_name
-    tmpf0bambai_name = '%s.bam.bai' % tmpf0_name
-    tmpf1 = tempfile.NamedTemporaryFile( dir=tmpDir )
-    tmpf1_name = tmpf1.name
-    tmpf1.close()
-    #link bam and bam index to working directory (can't move because need to leave original)
-    os.symlink( options.input1, tmpf0bam_name )
-    os.symlink( options.bamIndex, tmpf0bambai_name )
-    #get parameters for pileup command
-    if options.lastCol == 'yes':
-        lastCol = '-s'
-    else:
-        lastCol = ''
-    if options.indels == 'yes':
-        indels = '-i'
-    else:
-        indels = ''
-    opts = '%s %s -M %s' % ( lastCol, indels, options.mapCap )
-    if options.consensus == 'yes':
-        opts += ' -c -T %s -N %s -r %s -I %s' % ( options.theta, options.hapNum, options.fraction, options.phredProb )
-    #prepare basic pileup command
-    cmd = 'samtools pileup %s -f %s %s > %s'
-    try:
-        # have to nest try-except in try-finally to handle 2.4
-        try:
-            #index reference if necessary and prepare pileup command
-            if options.ref == 'indexed':
-                if not os.path.exists( "%s.fai" % options.index ):
-                    raise Exception, "Indexed genome %s not present, request it by reporting this error." % options.index
-                cmd = cmd % ( opts, options.index, tmpf0bam_name, options.output1 )
-            elif options.ref == 'history':
-                os.symlink( options.ownFile, tmpf1_name )
-                cmdIndex = 'samtools faidx %s' % ( tmpf1_name )
-                tmp = tempfile.NamedTemporaryFile( dir=tmpDir ).name
-                tmp_stderr = open( tmp, 'wb' )
-                proc = subprocess.Popen( args=cmdIndex, shell=True, cwd=tmpDir, stderr=tmp_stderr.fileno() )
-                returncode = proc.wait()
-                tmp_stderr.close()
-                # get stderr, allowing for case where it's very large
-                tmp_stderr = open( tmp, 'rb' )
-                stderr = ''
-                buffsize = 1048576
-                try:
-                    while True:
-                        stderr += tmp_stderr.read( buffsize )
-                        if not stderr or len( stderr ) % buffsize != 0:
-                            break
-                except OverflowError:
-                    pass
-                tmp_stderr.close()
-                #did index succeed?
-                if returncode != 0:
-                    raise Exception, 'Error creating index file\n' + stderr
-                cmd = cmd % ( opts, tmpf1_name, tmpf0bam_name, options.output1 )
-            #perform pileup command
-            tmp = tempfile.NamedTemporaryFile( dir=tmpDir ).name
-            tmp_stderr = open( tmp, 'wb' )
-            proc = subprocess.Popen( args=cmd, shell=True, cwd=tmpDir, stderr=tmp_stderr.fileno() )
-            returncode = proc.wait()
-            tmp_stderr.close()
-            #did it succeed?
-            # get stderr, allowing for case where it's very large
-            tmp_stderr = open( tmp, 'rb' )
-            stderr = ''
-            buffsize = 1048576
-            try:
-                while True:
-                    stderr += tmp_stderr.read( buffsize )
-                    if not stderr or len( stderr ) % buffsize != 0:
-                        break
-            except OverflowError:
-                pass
-            tmp_stderr.close()
-            if returncode != 0:
-                raise Exception, stderr
-        except Exception, e:
-            stop_err( 'Error running Samtools pileup tool\n' + str( e ) )
-    finally:
-        #clean up temp files
-        if os.path.exists( tmpDir ):
-            shutil.rmtree( tmpDir )
-    # check that there are results in the output file
-    if os.path.getsize( options.output1 ) > 0:
-        sys.stdout.write( 'Converted BAM to pileup' )
-    else:
-        stop_err( 'The output file is empty. Your input file may have had no matches, or there may be an error with your input file or settings.' )
-
-if __name__ == "__main__" : __main__()
b
diff -r 890d97772e2a -r a3b4ad6858ff sam_pileup.xml
--- a/sam_pileup.xml Thu Jan 09 14:28:39 2014 -0500
+++ b/sam_pileup.xml Thu Feb 06 07:11:33 2020 -0500
[
b'@@ -1,124 +1,126 @@\n-<tool id="sam_pileup" name="Generate pileup" version="1.1.2">\n-  <description>from BAM dataset</description>\n-  <requirements>\n-    <requirement type="package" version="0.1.16">samtools</requirement>\n-  </requirements>\n-  <command interpreter="python">\n-    sam_pileup.py\n-      --input1=$input1\n-      --output=$output1\n-      --ref=$refOrHistory.reference\n-      #if $refOrHistory.reference == "history":\n-        --ownFile=$refOrHistory.ownFile\n-      #else:\n-        --index=${refOrHistory.index.fields.path}\n-      #end if\n-       --bamIndex=${input1.metadata.bam_index}\n-       --lastCol=$lastCol\n-       --indels=$indels\n-       --mapCap=$mapCap\n-       --consensus=$c.consensus\n-      #if $c.consensus == "yes":\n-        --theta=$c.theta\n-        --hapNum=$c.hapNum\n-        --fraction=$c.fraction\n-        --phredProb=$c.phredProb\n-       #else:\n-        --theta="None"\n-        --hapNum="None"\n-        --fraction="None"\n-        --phredProb="None"\n-      #end if\n-  </command>\n-  <inputs>\n-    <conditional name="refOrHistory">\n-      <param name="reference" type="select" label="Will you select a reference genome from your history or use a built-in index?">\n-        <option value="indexed">Use a built-in index</option>\n-        <option value="history">Use one from the history</option>\n-      </param>\n-      <when value="indexed">\n-        <param name="input1" type="data" format="bam" label="Select the BAM file to generate the pileup file for">\n-           <validator type="unspecified_build" />\n-           <validator type="dataset_metadata_in_data_table" table_name="fasta_indexes" metadata_name="dbkey" metadata_column="1" message="Sequences are not currently available for the specified build." />\n-\n-        </param>\n-        <param name="index" type="select" label="Using reference genome">\n-          <options from_data_table="fasta_indexes">\n-            <filter type="data_meta" ref="input1" key="dbkey" column="1" />\n-            <validator type="no_options" message="No reference genome is available for the build associated with the selected input dataset" />\n-          </options>\n+<tool id="sam_pileup" name="Generate pileup" version="1.1.3" profile="16.04">\n+    <description>from BAM dataset</description>\n+    <requirements>\n+        <requirement type="package" version="0.1.16">samtools</requirement>\n+    </requirements>\n+    <command><![CDATA[\n+ln -s \'$input1\' input1.bam &&\n+ln -s \'${input1.metadata.bam_index}\' \'input1.bam.bai\' &&\n+#if $refOrHistory.reference == \'history\':\n+    ln -s \'$refOrHistory.ownFile\' reference.fasta &&\n+    samtools faidx reference.fasta &&\n+#end if\n+samtools pileup\n+#if $lastCol == \'yes\':\n+    -s\n+#end if\n+#if $indels == \'yes\':\n+    -i\n+#end if\n+-M $mapCap\n+#if $c.consensus == \'yes\':\n+    -c\n+    -T $c.theta\n+    -N $c.hapNum\n+    -r $c.fraction\n+    -I $c.phredProb\n+#end if\n+-f\n+#if $refOrHistory.reference == \'indexed\':\n+    \'${refOrHistory.index.fields.path}\'\n+#else:\n+    reference.fasta\n+#end if\n+input1.bam\n+> \'$output1\'\n+    ]]></command>\n+    <inputs>\n+        <conditional name="refOrHistory">\n+            <param name="reference" type="select" label="Will you select a reference genome from your history or use a built-in index?">\n+                <option value="indexed">Use a built-in index</option>\n+                <option value="history">Use one from the history</option>\n+            </param>\n+            <when value="indexed">\n+                <param name="input1" type="data" format="bam" label="Select the BAM file to generate the pileup file for">\n+                    <validator type="unspecified_build" />\n+                    <validator type="dataset_metadata_in_data_table" table_name="fasta_indexes" metadata_name="dbkey" metadata_column="1" message="Sequences are not currently available for the specified build." />\n+                </param>\n+                <param name="index" type="select" label="Using reference genome">\n+                <options from_data_table="fasta_inde'..b'>\n+                <param name="hapNum" argument="-N" type="integer" value="2" label="Number of haplotypes in the sample" help="Greater than or equal to 2" />\n+                <param name="fraction" argument="-r" type="float" value="0.001" label="Expected fraction of differences between a pair of haplotypes" />\n+                <param name="phredProb" argument="-I" type="integer" value="40" label="Phred probability of an indel in sequencing/prep" />\n+            </when>\n+        </conditional>\n+    </inputs>\n+    <outputs>\n+        <data name="output1" format="tabular" label="${tool.name} on ${on_string}: converted pileup" />\n+    </outputs>\n+    <tests>\n+        <test>\n+            <!--\n+            Bam to pileup command:\n+            samtools faidx chr_m.fasta\n+            samtools pileup -M 60 -f chr_m.fasta test-data/sam_pileup_in1.bam > sam_pileup_out1.pileup\n+            chr_m.fasta is the prefix of the index\n+            -->\n+            <param name="reference" value="history" />\n+            <param name="input1" value="sam_pileup_in1.bam" ftype="bam" />\n+            <param name="ownFile" value="chr_m.fasta" ftype="fasta" dbkey="equCab2" />\n+            <param name="lastCol" value="no" />\n+            <param name="indels" value="no" />\n+            <param name="mapCap" value="60" />\n+            <param name="consensus" value="no" />\n+            <output name="output1" file="sam_pileup_out1.pileup" />\n+        </test>\n+        <!--\n+        <test>\n+            Bam to pileup command:\n+            samtools pileup -M 60 -c -T 0.85 -N 2 -r 0.001 -I 40 -f chr_m.fasta test-data/sam_pileup_in1.bam > sam_pileup_out2.pileup\n+            chr_m.fasta is the prefix of the index\n+            <param name="reference" value="indexed" />\n+            <param name="input1" value="sam_pileup_in1.bam" ftype="bam" dbkey="equCab2" />\n+            <param name="index" value="chr_m" />\n+            <param name="lastCol" value="no" />\n+            <param name="indels" value="no" />\n+            <param name="mapCap" value="60" />\n+            <param name="consensus" value="yes" />\n+            <param name="theta" value="0.85" />\n+            <param name="hapNum" value="2" />\n+            <param name="fraction" value="0.001" />\n+            <param name="phredProb" value="40" />\n+            <output name="output1" file="sam_pileup_out2.pileup" />\n+        </test>\n+        -->\n+    </tests>\n+    <help><![CDATA[\n **What it does**\n \n Uses SAMTools_\' pileup command to produce a pileup dataset from a provided BAM dataset. It generates two types of pileup datasets depending on the specified options. If *Call consensus according to MAQ model?* option is set to **No**, the tool produces simple pileup. If the option is set to **Yes**, a ten column pileup dataset with consensus is generated. Both types of datasets are briefly summarized below.\n@@ -141,7 +143,7 @@\n  chrM  413  G  4     ..t,     IIIH\n  chrM  414  C  4     ...a     III2\n  chrM  415  C  4     TTTt     III7\n-   \n+\n where::\n \n   Column Definition\n@@ -152,7 +154,7 @@\n        4 Coverage (# reads aligning over that position)\n        5 Bases within reads where (see Galaxy wiki for more info)\n        6 Quality values (phred33 scale, see Galaxy wiki for more)\n-       \n+\n **Ten column pileup**\n \n The `ten-column` (consensus_) pileup incorporates additional consensus information generated with *-c* option of *samtools pileup* command::\n@@ -182,15 +184,8 @@\n \n \n .. _consensus: http://samtools.sourceforge.net/cns0.shtml\n-\n-------\n-\n-**Citation**\n-\n-For the underlying tool, please cite `Li H, Handsaker B, Wysoker A, Fennell T, Ruan J, Homer N, Marth G, Abecasis G, Durbin R; 1000 Genome Project Data Processing Subgroup. The Sequence Alignment/Map format and SAMtools. Bioinformatics. 2009 Aug 15;25(16):2078-9. &lt;http://www.ncbi.nlm.nih.gov/pubmed/19505943&gt;`_\n-\n-\n-  </help>\n+    ]]></help>\n+    <citations>\n+        <citation type="doi">10.1093/bioinformatics/btp352</citation>\n+    </citations>\n </tool>\n-\n-\n'
b
diff -r 890d97772e2a -r a3b4ad6858ff tool_dependencies.xml
--- a/tool_dependencies.xml Thu Jan 09 14:28:39 2014 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
b
@@ -1,6 +0,0 @@
-<?xml version="1.0"?>
-<tool_dependency>
-    <package name="samtools" version="0.1.16">
-        <repository changeset_revision="75367f13eb3c" name="package_samtools_0_1_16" owner="devteam" toolshed="http://toolshed.g2.bx.psu.edu" />
-    </package>
-</tool_dependency>