Skip to content

Commit

Permalink
Added metadata column selection to spiec-easi and flashweave
Browse files Browse the repository at this point in the history
  • Loading branch information
BenKaehler committed Sep 29, 2023
1 parent 715778a commit 75b3eb6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions q2_makarsa/_flashweave.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
def flashweave(
table: pd.DataFrame,
metadata: qiime2.Metadata = None,
metadata_column: list = None,
# defaults copied from FlashWeave.jl/src/learning.jl
heterogeneous: bool = False,
sensitive: bool = True,
Expand Down Expand Up @@ -64,6 +65,8 @@ def flashweave(
]
if metadata:
metadata = metadata.to_dataframe()
if metadata_column:
metadata = metadata[metadata_column]
if set(table.index) <= set(metadata.index):
metadata = metadata.reindex(table.index)
metadata_file = temp_dir / "meta-input-data.tsv"
Expand Down
8 changes: 6 additions & 2 deletions q2_makarsa/_spieceasi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
from ._run_commands import run_commands


def encode_metadata(sample_ids, metadata):
def encode_metadata(sample_ids, metadata, metadata_column):
encoded_metadata = []
for column in metadata.columns:
if metadata_column and column not in metadata_column:
continue
values = metadata.get_column(column)

is_numeric = isinstance(values, q2.NumericMetadataColumn)
Expand Down Expand Up @@ -61,6 +63,7 @@ def write_table(i, directory, table):
def spiec_easi(
table: biom.Table,
metadata: q2.Metadata = None,
metadata_column: list = None,
method: str = "glasso",
lambda_min_ratio: float = 1e-3,
nlambda: int = 20,
Expand All @@ -83,7 +86,8 @@ def spiec_easi(
table_files.append(write_table(i, temp_dir, one_table))
sample_ids = one_table.ids(axis='sample')
if metadata:
metadata_tables = encode_metadata(sample_ids, metadata)
metadata_tables = encode_metadata(
sample_ids, metadata, metadata_column)
metadata_columns = []
for i, one_table in enumerate(metadata_tables, i + 1):
table_files.append(write_table(i, temp_dir, one_table))
Expand Down
4 changes: 4 additions & 0 deletions q2_makarsa/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def _2(ff: NetworkFormat) -> Graph:
inputs={"table": List[FeatureTable[Frequency]]},
parameters={
"metadata": Metadata,
"metadata_column": List[Str],
"method": Str,
"lambda_min_ratio": Float,
"nlambda": Int,
Expand All @@ -94,6 +95,7 @@ def _2(ff: NetworkFormat) -> Graph:
},
parameter_descriptions={
"metadata": "path to sample metadata",
"metadata_column": "only use this or these column or columns",
"method": "Methods available for spieceasi,for example mb,glasso,slr",
"lambda_min_ratio": (
"Input parameter of spieceasi which represents "
Expand Down Expand Up @@ -130,6 +132,7 @@ def _2(ff: NetworkFormat) -> Graph:
inputs={"table": FeatureTable[Frequency]},
parameters={
"metadata": Metadata,
"metadata_column": List[Str],
"heterogeneous": Bool,
"sensitive": Bool,
"max_k": Int,
Expand Down Expand Up @@ -157,6 +160,7 @@ def _2(ff: NetworkFormat) -> Graph:
},
parameter_descriptions={
"metadata": "path to sample metadata",
"metadata_column": "only use this or these column or columns",
"heterogeneous": (
"enable heterogeneous mode for multi-habitat or"
"-protocol data with at least thousands of samples"
Expand Down

0 comments on commit 75b3eb6

Please sign in to comment.