Created
October 8, 2019 22:26
-
-
Save fedarko/05222da5b3f01ce9d77c6b989cf4d881 to your computer and use it in GitHub Desktop.
adds an ordinal date field based on a timestamp to a q2 metadata file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
from qiime2 import Metadata | |
from dateutil.parser import parse | |
from dateutil.relativedelta import relativedelta | |
m = Metadata.load("metadata-with-age.tsv") | |
m_df = m.to_dataframe() | |
m_df["ordinal-timestamp"] = 0 | |
for sample_id in m_df.index: | |
parsed_date = parse(m_df.loc[sample_id, "collection_timestamp"]) | |
parsed_date_ordinalstring = parsed_date.isoformat()[:10].replace("-", "") | |
m_df.loc[sample_id, "ordinal-timestamp"] = parsed_date_ordinalstring | |
Metadata(m_df).save("metadata-with-age-and-ordinal-timestamp.tsv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment