Skip to content

Commit

Permalink
account for time-/state-dependence of column naming
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed Jun 4, 2019
1 parent 578355d commit 4aa8341
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 6 additions & 1 deletion peppy/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,12 @@ def merge_sample(sample, sample_subann, data_sources=None,
return merged_attrs

if sample_colname not in sample_subann.columns:
raise KeyError("Subannotation requires column '{}'.".format(sample_colname))
alternative = SAMPLE_NAME_COLNAME
_LOGGER.debug("'{}' is not a subannotation column; trying {}".
format(sample_colname, alternative))
if alternative not in sample_subann.columns:
raise KeyError("Subannotation requires column '{}'.".format(sample_colname))
sample_colname = alternative

_LOGGER.debug("Merging Sample with data sources: {}".
format(data_sources))
Expand Down
8 changes: 5 additions & 3 deletions peppy/snake_project.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
""" Adapting Project for interop with Snakemake """

from copy import deepcopy
from .const import *
from .const import SNAKEMAKE_SAMPLE_COL
from .const import SAMPLE_NAME_COLNAME, SNAKEMAKE_SAMPLE_COL
from .project import Project, sample_table, subsample_table, MAIN_INDEX_KEY, \
SUBS_INDEX_KEY
from .utils import count_repeats, get_logger, type_check_strict
Expand Down Expand Up @@ -73,7 +72,10 @@ def _finalize_subsample_table(self, t):
def _get_sample_ids(df):
""" Return the sample identifiers in the given table. """
type_check_strict(df, DataFrame)
return df[SNAKEMAKE_SAMPLE_COL]
try:
return df[SNAKEMAKE_SAMPLE_COL]
except KeyError:
return df[SAMPLE_NAME_COLNAME]


def _rename_columns(t):
Expand Down

0 comments on commit 4aa8341

Please sign in to comment.