Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solutions of exercises through part 4.
- Loading branch information
1 parent
96c2f2d
commit 0c3e8f0
Showing
5 changed files
with
137 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#! /usr/bin/env python | ||
|
||
import os | ||
from os.path import abspath, basename | ||
import sys | ||
|
||
from gc3libs import Application | ||
from gc3libs.cmdline import SessionBasedScript | ||
|
||
|
||
if __name__ == '__main__': | ||
from ex4a import ColorizeScript | ||
ColorizeScript().run() | ||
|
||
|
||
class ColorizeScript(SessionBasedScript): | ||
""" | ||
Coloriye multiple images. | ||
""" | ||
def __init__(self): | ||
super(ColorizeScript, self).__init__(version='1.0') | ||
def setup_args(self): | ||
self.add_param('colors', nargs=3, help="Three colors") | ||
self.add_param('images', nargs='+', help="Images to colorize") | ||
def new_tasks(self, extra): | ||
col1, col2, col3 = self.params.colors | ||
apps_to_run = [] | ||
for input_file in self.params.images: | ||
input_file = abspath(input_file) | ||
apps_to_run.append(ColorizeApp(input_file, col1, col2, col3)) | ||
return apps_to_run | ||
|
||
|
||
from gc3libs.quantity import GB | ||
|
||
class ColorizeApp(Application): | ||
"""Add colors to a grayscale image.""" | ||
def __init__(self, img, col1, col2, col3): | ||
inp = basename(img) | ||
out = "color-" + inp | ||
Application.__init__( | ||
self, | ||
arguments=[ | ||
"convert", inp, | ||
"(", "xc:"+col1, "xc:"+col2, "xc:"+col3, "+append", ")", "-clut", | ||
out], | ||
inputs=[img], | ||
outputs=[out], | ||
# need to use a different output dir per set of | ||
# construction params, otherwise the output of one task | ||
# will be overwritten by another task's output ... | ||
output_dir="colorized-" + inp + ".d", | ||
stdout="stdout.txt", | ||
stderr="stderr.txt", | ||
# required for running on the cloud, see GC3Pie issue #559 | ||
requested_memory=1*GB) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#! /usr/bin/env python | ||
|
||
import os | ||
from os.path import abspath, basename | ||
import sys | ||
|
||
from gc3libs import Application | ||
from gc3libs.cmdline import SessionBasedScript | ||
|
||
|
||
if __name__ == '__main__': | ||
from ex4b import TopBlastScript | ||
TopBlastScript().run() | ||
|
||
|
||
class TopBlastScript(SessionBasedScript): | ||
""" | ||
Run BLAST on pairs of FAA files. | ||
""" | ||
def __init__(self): | ||
super(TopBlastScript, self).__init__(version='1.0') | ||
def setup_args(self): | ||
self.add_param('new_faa', help="Query FAA") | ||
self.add_param('known_faa', nargs='+', | ||
help="Samples to compare to the query") | ||
def setup_options(self): | ||
self.add_param('--e-value', '-e', | ||
type=float, help="Expectation value") | ||
self.add_param('--output-format', '-o', dest='output_fmt', | ||
type=int, help="Output format, int from 0 to 9") | ||
def new_tasks(self, extra): | ||
apps_to_run = [] | ||
for in_file2 in self.params.known_faa: | ||
in_file2 = abspath(in_file2) | ||
apps_to_run.append(BlastApp(self.params.new_faa, in_file2, | ||
self.params.e_value, self.params.output_fmt)) | ||
return apps_to_run | ||
|
||
|
||
from gc3libs.quantity import GB | ||
|
||
class BlastApp(Application): | ||
"""Run BLAST on two files.""" | ||
def __init__(self, input1, input2, e_value, output_fmt): | ||
inp1 = basename(input1) | ||
inp2 = basename(input2) | ||
Application.__init__( | ||
self, | ||
# NOTE: does not work as written! BLAST+ is required | ||
# to compare two FASTA files | ||
arguments=["blastpgp", "-i", inp1, "-d", inp2, | ||
"-e", e_value, "-m", output_fmt, "-o", "output.txt"], | ||
inputs=[input1, input2], | ||
outputs=["output.txt"], | ||
output_dir=("blast-" + inp1 + "-" + inp2 + ".d"), | ||
stdout="stdout.txt", | ||
stderr="stderr.txt", | ||
requested_memory=1*GB) |