qiime2 / q2-demux

BSD 3-Clause "New" or "Revised" License
0 stars 20 forks source link

emp_single fails when the `ec_details` list is empty #98

Closed johnchase closed 5 years ago

johnchase commented 5 years ago

emp_single fails when the ec_details list is empty. This looks to be the case when golay_error_correction=False because ec_details will not be appended. In emp_single if the details data frame that is returned by the function is empty the transformer that converts the dataframe to ErrorCorrectionDetailsFmt fails with ValueError: Metadata must contain at least one ID.

If the details dataframe on this line is empty: https://github.com/qiime2/q2-demux/blob/9d4d4f6860c7922ed3d1e8959f3678bd5a3908b0/q2_demux/_demux.py#L347

The output type of emp_single is an empty dataframe. When the transformer is called to convert this to ErrorCorrectionDetailsFmt it fails

from qiime2 import Metadata
from q2_demux._format import ErrorCorrectionDetailsFmt
import pandas as pd

columns = ['id',
           'sample',
           'barcode-sequence-id',
           'barcode-uncorrected',
           'barcode-corrected',
           'barcode-errors']
details = pd.DataFrame([], columns=columns).set_index('id')

ff = ErrorCorrectionDetailsFmt()
Metadata(details).save(str(ff))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-262a0b5c8838> in <module>
     12 
     13 ff = ErrorCorrectionDetailsFmt()
---> 14 Metadata(details).save(str(ff))

~/miniconda3/envs/qiime2-2019.4/lib/python3.6/site-packages/qiime2/metadata/metadata.py in __init__(self, dataframe)
    360                 "%r" % (self.__class__.__name__, type(dataframe)))
    361 
--> 362         super().__init__(dataframe.index)
    363 
    364         self._dataframe, self._columns = self._normalize_dataframe(dataframe)

~/miniconda3/envs/qiime2-2019.4/lib/python3.6/site-packages/qiime2/metadata/metadata.py in __init__(self, index)
     91         if index.empty:
     92             raise ValueError(
---> 93                 "%s must contain at least one ID." % self.__class__.__name__)
     94 
     95         id_header = index.name

ValueError: Metadata must contain at least one ID.
thermokarst commented 5 years ago

Ugh, bummer, good catch @johnchase. Stay tuned...

thermokarst commented 5 years ago

We are going to patch this and push up a 2019.4.1 version of q2-demux, hopefully later today (I am working on patch now). I am planning on updating the golay-disabled branch to write out the same barcode correction info, sans the last two columns (well, the columns will be there, just empty).

thermokarst commented 5 years ago

The patched version of this plugin is now available in the 2019.4 environments. Thanks @johnchase!