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

Bioconductor Support #570

Merged
merged 80 commits into from
Nov 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
8b735ed
Added bioconductor_skeleton and cmd_bioc_tool_init.py
nturaga Apr 29, 2016
ea68333
reshuffle some code
nturaga May 5, 2016
46ef4bc
This makes the bioconductor_skeleton.py compatible with python 2
nturaga May 14, 2016
4518033
Add bioconda helper functions,
nturaga May 27, 2016
f33d6d7
Add bioconda path to bioc_tool_init , deprecated commit, do NOT use.
nturaga May 31, 2016
fbadda7
minor changes
nturaga May 31, 2016
a0ee9f4
Update requirements for bioc_tool_init work; it'd be nice to eliminat…
dannon May 31, 2016
9980c76
Merge pull request #1 from dannon/add_bioc_tool_init
nturaga May 31, 2016
ce408c4
Get version from bioconda
nturaga May 31, 2016
dc9e306
typo fix bioconda
dannon May 31, 2016
f5ee6ef
Merge pull request #2 from dannon/biconda_bioconda
nturaga May 31, 2016
b3ae28f
IO error
nturaga May 31, 2016
ed5ca75
Removed print statements, need to add package_url, package_help from …
nturaga Jun 2, 2016
461e187
Add help from bioconductor directly
nturaga Jun 2, 2016
7d2d5c3
Removed print statements, this commit, now has working versions of c…
nturaga Jun 2, 2016
28175eb
rename command line tool, conda_recipe_init to bionconductor_conda_re…
nturaga Jun 2, 2016
c63768d
another name change
nturaga Jun 2, 2016
4732a87
Removed bioconda_path requirement
nturaga Jun 7, 2016
1bf6a38
Multiple libraries not being parsed, need to skip getopt as part of r…
nturaga Jun 25, 2016
bcddac0
Working version of rscript_parse for GCC 2016
nturaga Jun 26, 2016
3ad38e6
Merge remote-tracking branch 'galaxyproject/master' into add_bioc_too…
jmchilton Jun 27, 2016
dcd1f80
Merge upstream updates to branch
nturaga Sep 16, 2016
6c47093
Remove unused variabe in bioc_tool_builder.py.
jmchilton Sep 19, 2016
afb9585
Import instead of copy and paste TOOL_TEMPLATE in btb.py...
jmchilton Sep 19, 2016
157f129
Import instead of copy and paste MACROS_TEMPLATE in btb.py...
jmchilton Sep 19, 2016
12637f3
Import more stuff from tool_builder in btb instead copy/paste.
jmchilton Sep 19, 2016
d276b08
Opps pull UrlCitation out of both files in last refactoring.
jmchilton Sep 19, 2016
2a322c3
More de-duplicating between btb and tb.
jmchilton Sep 19, 2016
d2c7501
Remove unused Container class in btb.
jmchilton Sep 19, 2016
fae22f0
Remove now unused import in btb.py.
jmchilton Sep 19, 2016
82eb237
Remove more duplication between tb.py and btb.py.
jmchilton Sep 19, 2016
ef78d08
Remove more duplication between tb.py and btb.py.
jmchilton Sep 19, 2016
0ff81c7
Remove duplication in bioc id option.
jmchilton Sep 19, 2016
a3c35fa
Remove duplication related to tool init options and names.
jmchilton Sep 19, 2016
108ff23
De-duplication of tool init name handling options.
jmchilton Sep 19, 2016
d8e9e3f
Remove duplicate tool init handling for three more options.
jmchilton Sep 19, 2016
803cf19
De-duplicate four more tool init options.
jmchilton Sep 19, 2016
c30fe91
Eliminate more copy-paste betweeen cmd_bti and cmd_ti.
jmchilton Sep 19, 2016
dcaf7a0
De-duplication of 4 more options between cbti and cti.
jmchilton Sep 19, 2016
8da932b
Fix unused import in cmd_tool_init.
jmchilton Sep 19, 2016
e6e9315
De-duplicate the usage of three more options between tool init flavors.
jmchilton Sep 19, 2016
31b5819
Capture more of tool_init's options in planemo/options.py.
jmchilton Sep 19, 2016
270227d
Reuse more of tool init's options with different help in bioc_ti.
jmchilton Sep 19, 2016
67f71ee
Rearrange comments related to tool init commands.
jmchilton Sep 19, 2016
2fca59c
Fix two problems I introduced in planemo/options.py.
jmchilton Sep 19, 2016
c7a74fc
Merge branch 'master' into add_bioc_features
nturaga Sep 19, 2016
1f17056
remove container options
nturaga Sep 19, 2016
ea14a85
add updates to bioconductor_skeleton.py file, remove unused dependencies
nturaga Sep 19, 2016
861b6c7
replace - to _, to follow planemo conventions, next version can have …
nturaga Sep 20, 2016
0632646
Put bioconductor_skeleton.py in a new directory called 'bioconda_scri…
nturaga Sep 21, 2016
dc027b4
Merge branch 'master' into add_bioc_features
nturaga Sep 21, 2016
9880049
merge upstream/master to add_bioc_features
nturaga Oct 12, 2016
f22797a
conda add requirements
nturaga Oct 12, 2016
3a97d8c
add git
nturaga Oct 12, 2016
8e61381
fixed tool naming in cmd_bioc_tool_init.py
malloryfreeberg Oct 17, 2016
e6d6e71
Merge pull request #3 from malloryfreeberg/add_bioc_features_mallory
nturaga Oct 17, 2016
8ee635f
Bioconductor tool builder edits
malloryfreeberg Oct 24, 2016
b50a7df
This patch fixes the missing $ signs in front of the parameters
nturaga Oct 24, 2016
b257673
Merge pull request #5 from malloryfreeberg/add_bioc_features_mallory
nturaga Oct 24, 2016
76a2627
Prepare version 0.34.1.
jmchilton Oct 12, 2016
2674a2c
Version 0.34.1
jmchilton Oct 12, 2016
9ffa3a9
Starting work on 0.35.0
jmchilton Oct 12, 2016
287ad41
moved bioconda recipe generation to conda_recipes.py
nturaga Oct 14, 2016
18ab8d3
Adds the option --rversion so the user to specify an R version.
nturaga Oct 25, 2016
2644e6b
Fix lint issues from travis.
nturaga Oct 25, 2016
09826a7
Reordered bioc_skeleton
nturaga Oct 25, 2016
1e65e4f
Flake 8 fixes
nturaga Oct 25, 2016
912d746
typo in pyaml
nturaga Oct 25, 2016
d128b1d
Fix linting issues
nturaga Oct 25, 2016
83da92b
Py3 lint fix
nturaga Oct 25, 2016
58c2a26
Py3 unused variable
nturaga Oct 25, 2016
b53e794
Importanize the order of packages for Py27 lint check
nturaga Oct 26, 2016
94b3fb0
i100 errors on py27
nturaga Oct 26, 2016
29d14a8
Class too complex issue should be resolved with this commit
nturaga Oct 26, 2016
e7cce75
pylint
nturaga Oct 26, 2016
e5c8d7a
Pylint 27
nturaga Oct 26, 2016
2799e1b
Final pylint 2.7 issue
nturaga Oct 26, 2016
c632a91
Fix doctest for bioconductor_skeleton.py
nturaga Oct 26, 2016
9dd7dd8
merge master into feature branch
nturaga Nov 8, 2016
65cc053
add pyyaml to requirements file
nturaga Nov 11, 2016
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
252 changes: 252 additions & 0 deletions planemo/bioc_tool_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
"""Tool builder for R-bioc tools."""

import os
import yaml
from planemo.conda_recipes import write_bioconda_recipe
from planemo.tool_builder import (
_find_command,
_handle_help,
_handle_tests,
_render,
_replace_file_in_command,
Input,
MACROS_TEMPLATE,
TestCase,
ToolDescription,
UrlCitation,
)


def build(**kwds):
"""Build up a :func:`ToolDescription` from supplid arguments."""
test_case = TestCase()
command = _find_command(kwds)
# process raw cite urls
cite_urls = kwds.get("cite_url", [])
del kwds["cite_url"]
citations = map(UrlCitation, cite_urls)
kwds["bibtex_citations"] = citations

# process raw inputs
# inputs are in a list
inputs = kwds.get("input", [])
del kwds["input"]

# TODO: DEPRICATE HANDLING OF EXAMPLE INPUT
example_inputs = kwds["example_input"]
del kwds["example_input"]

rscript_data = kwds["rscript_data"]

# Rscript inputs
if bool(rscript_data):
input_dict = rscript_data.get('inputs') # dictionary of input parameters
inputs = input_dict.values()[0]

def edit_params(iodata):
return iodata.split("/")[-1]
inputs = map(edit_params, inputs)
param_set = inputs
inputs = list(map(Input, inputs or []))

# TODO: DEPRICATE HANDLING OF EXAMPLE INPUT
if not bool(rscript_data) and example_inputs:
'''If no Rscript data is found but example_inputs are given - this should not happen'''
for i, input_file in enumerate(example_inputs or []):
name = "input%d" % (i + 1)
inputs.append(Input(input_file, name=name))
test_case.params.append((name, input_file))
command = _replace_file_in_command(command, input_file, name)

# handle raw outputs (from_work_dir ones) as well as named_outputs
outputs = kwds.get("output", [])
del kwds["output"]

if bool(rscript_data):
output_dict = rscript_data.get('outputs')
outputs = output_dict.values()[0]
# Add all parameters to a list called param_set
outputs = map(edit_params, outputs)
param_set.extend(outputs)

outputs = list(map(Output, outputs or []))

named_outputs = kwds.get("named_output", [])
del kwds["named_output"]
for named_output in (named_outputs or []):
outputs.append(Output(name=named_output))

# DEPRICATED HANDLING OF EXAMPLE OUTPUT
# TODO: handle example outputs
# if kwds.get("example_ouput"):
# example_outputs = kwds["example_output"]
# del kwds["example_output"]

kwds['inputs'] = inputs
kwds["outputs"] = outputs

# handle requirements and containers
if bool(rscript_data):
if not type([rscript_data.get('library')]) is list:
kwds['requirements'] = [rscript_data.get('library')]
else:
kwds['requirements'] = rscript_data.get('library')
_handle_requirements(kwds)
# Add help from requirements
if not bool(rscript_data):
req = kwds['requirements'][0]
command_help = req.package_help + "\n \n" + req.package_url
kwds['help_text'] = command_help

# Handle help
_handle_help(kwds)

# Edit command before sending it into the kwds dictionary
command = _parse_command_rbioc(command, param_set)
kwds["command"] = command

# finally wrap up tests
tests, test_files = _handle_tests(kwds, test_case)
kwds["tests"] = tests

# Render tool content from template.
contents = _render(kwds)
macro_contents = None
if kwds["macros"]:
macro_contents = _render(kwds, MACROS_TEMPLATE)

return ToolDescription(
contents,
macro_contents,
test_files=test_files
)


def _parse_command_rbioc(command, param_set):
"""
Parse command in Rbioc.

Find a r-bioc command and replace the inputs and
outputs with appropriate galaxy template.
"""
cmd = command.split(" ")
count = 0
for i in range(len(cmd)):
if "--" in cmd[i]:
cmd[i + 1] = "$" + param_set[count].split(".")[0]
count = count + 1
return " ".join(cmd)


def _handle_requirements(kwds):
"""Handle Requirements in R-Bioc tools.

Convert requirements specified from the command-line
into abstract format for consumption by the template.
"""
requirements = kwds["requirements"]
# Handle Bioc/R requirements
if kwds.get('rversion') and kwds.get("requirements"):
rversion = kwds['rversion']
rversion = rversion.replace(" ", "@")
requirements.append(rversion)
requirements.reverse() # FIXME: Flips list so that R is the first in the requirements list
bioconda_path = kwds["bioconda_path"]
del kwds["requirements"]
requirements = requirements or []

requirements = [Requirement(req, bioconda_path=bioconda_path) for req in requirements]
kwds["requirements"] = requirements


class Output(object):
"""Output class for R bioc tools."""

def __init__(self, from_path=None, name=None, use_from_path=False):
"""Initialize Output class."""
if from_path:
parts = from_path.split(".")
name = name or parts[0]
if len(parts) > 1:
datatype = ".".join(parts[1:])
else:
datatype = "data"
else:
name = name
datatype = "data"

self.name = name
self.datatype = datatype
if use_from_path:
self.from_path = from_path
else:
self.from_path = None

def __str__(self):
"""Method override str function in Output class."""
if self.from_path:
return self._from_path_str()
else:
return self._named_str()

def _from_path_str(self):
template = '<data name="{0}" format="{1}" from_work_dir="{2}" />'
return template.format(self.name, self.datatype, self.from_path)

def _named_str(self):
template = '<data name="{0}" format="{1}" />'
return template.format(self.name, self.datatype)


class Requirement(object):
"""Requirements class for R-Bioc tools."""

def __init__(self, requirement, bioconda_path=None, update=False):
"""Initialize Requirements class for Bioc tool builder."""
parts = requirement.split("@", 1)
# Get version from requirements, if version not given
if len(parts) > 1:
name = parts[0]
version = "@".join(parts[1:])
else:
name = parts[0]
version = None
if name == "R":
self.name = name
self.version = version
else:
# Write biconda recipe with given requirement
if bioconda_path is None:
bioconda_path = os.path.expanduser("~")
write_bioconda_recipe(name, True, update, bioconda_path)

recipe_path = os.path.join(bioconda_path,
"bioconda-recipes",
"recipes",
"bioconductor-" + name.lower(),
"meta.yaml")
if not os.path.exists(recipe_path):
recipe_path = os.path.join(bioconda_path,
"bioconda-recipes",
"recipes",
"r-" + name.lower(),
"meta.yaml")
with open(recipe_path, 'r') as f:
doc = yaml.load(f)
if not version:
version = doc["package"]["version"]
package_url = doc["about"]["home"]
package_help = doc["about"]["summary"]
self.name = name
self.version = version
self.package_url = package_url
self.package_help = package_help

def __str__(self):
"""Format requirements string with correct version and name."""
base = '<requirement type="package"{0}>{1}</requirement>'
if self.version is not None:
attrs = ' version="{0}"'.format(self.version)
else:
attrs = ''
return base.format(attrs, self.name)
Empty file.
Loading