diff --git a/docs/_writing_scripts.rst b/docs/_writing_scripts.rst index 30495ec37..5e695da30 100644 --- a/docs/_writing_scripts.rst +++ b/docs/_writing_scripts.rst @@ -5,10 +5,10 @@ Many common bioinformatics applications are available on the `Tool Shed`_ already and so a common development task is to integrate scripts of various complexity into Galaxy. -Consider the following small Perl script. +Consider the following small Python script. -.. literalinclude:: writing/gc_content.pl - :language: perl +.. literalinclude:: writing/gc_content.py + :language: python One can build a tool for this script as follows and place the script in the same directory as the tool XML file itself. The special value diff --git a/docs/writing/gc_content.pl b/docs/writing/gc_content.pl deleted file mode 100644 index 686afd9c5..000000000 --- a/docs/writing/gc_content.pl +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/perl -w - -# usage : perl toolExample.pl - -open (IN, "<$ARGV[0]"); -open (OUT, ">$ARGV[1]"); -while () { - chop; - if (m/^>/) { - s/^>//; - if ($. > 1) { - print OUT sprintf("%.3f", $gc/$length) . "\n"; - } - $gc = 0; - $length = 0; - } else { - ++$gc while m/[gc]/ig; - $length += length $_; - } -} -print OUT sprintf("%.3f", $gc/$length) . "\n"; -close( IN ); -close( OUT ); diff --git a/docs/writing/gc_content.py b/docs/writing/gc_content.py new file mode 100644 index 000000000..c761d081f --- /dev/null +++ b/docs/writing/gc_content.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python2 +import sys + +# usage : python gc_content.py + +name = None +with open(sys.argv[1]) as infile: + with open(sys.argv[2], 'w') as outfile: + for line_raw in infile: + line = line_raw.rstrip('\r\n') + if line.startswith('>'): + if name is not None: + outfile.write(name+': '+str(gc/float(total))+'\n') + name = line[1:] + gc = 0 + total = 0 + else: + gc += line.count('G') + line.count('C') + total += len(line) + outfile.write(name+': '+str(gc/float(total))+'\n') diff --git a/docs/writing/gc_content.xml b/docs/writing/gc_content.xml index dd2cd5805..9e9d8a0a7 100644 --- a/docs/writing/gc_content.xml +++ b/docs/writing/gc_content.xml @@ -1,6 +1,6 @@ for each sequence in a file - perl $__tool_directory__/gc_content.pl $input output.tsv + python $__tool_directory__/gc_content.py $input output.tsv