Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writing_appliance script example: smiting perl from yet one more place #705

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/_writing_scripts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions docs/writing/gc_content.pl

This file was deleted.

20 changes: 20 additions & 0 deletions docs/writing/gc_content.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env python2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python2? why not python3? ;)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I'd love to, but I figured let's not go crazy here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this made me do some research.. can OS X people confirm whether python2 is on your PATH?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, no. At least only python is on the $PATH on macOS Sierra 10.12.5, not python2.

$ uname
Darwin
$ which python2
$ python2
-bash: python2: command not found
$ which python
/usr/bin/python
$ python --version
Python 2.7.10

import sys

# usage : python gc_content.py <FASTA file> <output file>

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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not case insensitive, unlike the perl version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, true. Didn't know if it was more important to be complete or keep it simple. I can make the edit if you guys want.

total += len(line)
outfile.write(name+': '+str(gc/float(total))+'\n')
2 changes: 1 addition & 1 deletion docs/writing/gc_content.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<tool id="gc_content" name="Compute GC content">
<description>for each sequence in a file</description>
<command>perl $__tool_directory__/gc_content.pl $input output.tsv</command>
<command>python $__tool_directory__/gc_content.py $input output.tsv</command>
<inputs>
<param format="fasta" name="input" type="data" label="Source file"/>
</inputs>
Expand Down