Skip to content

Commit ae3e4a7

Browse files
committed
Allow to extract dates for list of samples
1 parent 1e20e18 commit ae3e4a7

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

amdirt/cli.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ def viewer(ctx, no_args_is_help=True, **kwargs):
169169
is_flag=True,
170170
help="Generate BibTeX file of all publications in input table",
171171
)
172+
@click.option(
173+
"--dates",
174+
is_flag=True,
175+
help="Generate AncientMetagenomeDir dates table of all samples in input table"
176+
)
172177
@click.option(
173178
"--curl",
174179
is_flag=True,

amdirt/convert/__init__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
prepare_aMeta_table,
99
is_merge_size_zero,
1010
prepare_taxprofiler_table,
11+
get_dates,
1112
get_libraries,
1213
get_remote_resources,
1314
get_json_path,
@@ -27,6 +28,7 @@ def run_convert(
2728
tables=None,
2829
output=".",
2930
bibliography=False,
31+
dates=False,
3032
librarymetadata=False,
3133
curl=False,
3234
aspera=False,
@@ -138,6 +140,22 @@ def run_convert(
138140
else:
139141
col_drop = ["archive_accession", "sample_host"]
140142

143+
if dates == True:
144+
if table_name not in remote_resources["dates"]:
145+
logger.error(f"No dates for {table_name} available in AncientMetagenomeDir at the moment.")
146+
else:
147+
tbl_file = f"{output}/AncientMetagenomeDir_filtered_dates.tsv"
148+
dates_tbl = pd.read_csv(remote_resources['dates'][table_name],
149+
sep="\t")
150+
logger.info(f"Writing filtered dates table to {tbl_file}")
151+
datesmetadata = get_dates(table_name, samples, dates_tbl)
152+
datesmetadata.to_csv(
153+
tbl_file,
154+
sep="\t",
155+
index=False,
156+
)
157+
158+
141159
if librarymetadata == True:
142160
tbl_file = f"{output}/AncientMetagenomeDir_filtered_libraries.tsv"
143161
logger.info(f"Writing filtered libraries table to {tbl_file}")

amdirt/core/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,40 @@ def doi2bib(doi: str) -> str:
141141
return r.text
142142

143143

144+
def get_dates(
145+
table_name: str,
146+
samples: pd.DataFrame,
147+
dates: pd.DataFrame
148+
):
149+
"""Get dates from the samples table
150+
151+
Args:
152+
table_name (str): Name of the table of the table to convert
153+
samples (pd.DataFrame): Sample table
154+
155+
Returns:
156+
pd.DataFrame: filtered dates table
157+
"""
158+
samples = (samples
159+
.rename({'archive_accession': 'archive_sample_accession'}, axis=1)
160+
)
161+
if table_name in [
162+
"ancientmetagenome-environmental",
163+
]:
164+
sel_col = ["archive_accession"]
165+
else:
166+
sel_col = ["project_name", "publication_year",
167+
"sample_name", "singlegenome_species",
168+
"archive_project", "archive_sample_accession"]
169+
selected_dates = dates.merge(
170+
samples.loc[:, sel_col],
171+
on=sel_col,
172+
how="inner"
173+
)
174+
175+
return selected_dates
176+
177+
144178
@st.cache_data
145179
def get_libraries(
146180
table_name: str,

0 commit comments

Comments
 (0)