Skip to content

Commit

Permalink
Fix metadata setting for Otu datatypes
Browse files Browse the repository at this point in the history
I broke this in galaxyproject#4388.
I went through the other changes in that PR, and I believe this should be the
only error.
Figured out through the great detective work of @abernard.
  • Loading branch information
mvdbeek committed Nov 24, 2017
1 parent a7c8edb commit 15766de
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/galaxy/datatypes/mothur.py
Expand Up @@ -26,6 +26,24 @@ def __init__(self, **kwd):
super(Otu, self).__init__(**kwd)

def set_meta(self, dataset, overwrite=True, **kwd):
"""
Set metadata for Otu files.
>>> from galaxy.datatypes.sniff import get_test_fname
>>> from galaxy.util.bunch import Bunch
>>> dataset = Bunch()
>>> dataset.metadata = Bunch
>>> otu = Otu()
>>> dataset.file_name = get_test_fname( 'mothur_datatypetest_true.mothur.otu' )
>>> dataset.has_data = lambda: True
>>> otu.set_meta(dataset)
>>> dataset.metadata.columns
100
>>> len(dataset.metadata.labels) == 37
True
>>> len(dataset.metadata.otulabels) == 98
True
"""
super(Otu, self).set_meta(dataset, overwrite=overwrite, **kwd)

if dataset.has_data():
Expand All @@ -37,6 +55,8 @@ def set_meta(self, dataset, overwrite=True, **kwd):

headers = iter_headers(dataset.file_name, sep='\t', count=-1)
first_line = get_headers(dataset.file_name, sep='\t', count=1)
if first_line:
first_line = first_line[0]
# set otulabels
if len(first_line) > 2:
otulabel_names = first_line[2:]
Expand All @@ -49,6 +69,7 @@ def set_meta(self, dataset, overwrite=True, **kwd):
else:
comment_lines += 1
# Set the discovered metadata values for the dataset
dataset.metadata.first_line = first_line
dataset.metadata.data_lines = data_lines
dataset.metadata.columns = ncols
dataset.metadata.labels = list(label_names)
Expand Down

0 comments on commit 15766de

Please sign in to comment.