Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix annotate metadata with numeric strains #952

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
python-version: "3.9"
- run: pip install cram nextstrain-augur
- run: cram --shell=/bin/bash tests/sanitize-metadata.t
- run: cram --shell=/bin/bash tests/sanitize-metadata.t tests/annotate_metadata_with_index.t
huddlej marked this conversation as resolved.
Show resolved Hide resolved

docs:
uses: nextstrain/.github/.github/workflows/docs-ci.yaml@master
Expand Down
7 changes: 3 additions & 4 deletions scripts/annotate_metadata_with_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,21 @@
index = pd.read_csv(
args.sequence_index,
sep="\t",
dtype={"strain": "string"},
index_col="strain",
).drop(
columns=["length"],
)
index["length"] = index.loc[:, ["A", "C", "G", "T"]].sum(axis=1)
new_columns = {
column: f"_{column}"
for column in index.columns
if column != "strain"
}
index = index.rename(columns=new_columns)

metadata.merge(
metadata.join(
index,
on="strain",
).to_csv(
args.output,
sep="\t",
index=False,
)
28 changes: 28 additions & 0 deletions tests/annotate_metadata_with_index.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Test script to annotate metadata with sequence index.

$ pushd "$TESTDIR" > /dev/null

Annotate metadata with an index where strains have numeric names.

$ python3 ../scripts/annotate_metadata_with_index.py \
> --metadata numeric_strains/metadata.tsv \
> --sequence-index numeric_strains/sequence_index.tsv \
> --output "$TMP/metadata_with_index.tsv"
$ wc -l "$TMP/metadata_with_index.tsv"
\s*3 .* (re)

$ rm -f "$TMP/metadata_with_index.tsv"

Annotate metadata with an index where metadata uses the "name" column for strain names.
This should produce the same result as above, except with a "name" column in the output.

$ python3 ../scripts/annotate_metadata_with_index.py \
> --metadata numeric_strains/metadata_by_name.tsv \
> --sequence-index numeric_strains/sequence_index.tsv \
> --output "$TMP/metadata_with_index.tsv"
$ wc -l "$TMP/metadata_with_index.tsv"
\s*3 .* (re)

$ rm -f "$TMP/metadata_with_index.tsv"

$ popd > /dev/null
3 changes: 3 additions & 0 deletions tests/numeric_strains/metadata.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
strain virus gisaid_epi_isl genbank_accession date region country division location region_exposure country_exposure division_exposure segment length host age sex originating_lab submitting_lab authors url title date_submitted
1 ncov ? MT450922 2020-03-05 Oceania Australia Victoria Oceania Australia Victoria genome 29812 Homo sapiens ? ? ? ? Seemann et al https://www.ncbi.nlm.nih.gov/nuccore/MT450922 Severe acute respiratory syndrome coronavirus 2 isolate SARS-CoV-2/human/AUS/VIC05/2020 ORF1ab polyprotein (ORF1ab), ORF1a polyprotein (ORF1ab), surface glycoprotein (S), ORF3a protein (ORF3a), envelope protein (E), membrane glycoprotein (M), ORF6 protein (ORF6), ORF7a protein (ORF7a), ORF7b (ORF7b), ORF8 protein (ORF8), nucleocapsid phosphoprotein (N), and ORF10 protein (ORF10) genes, complete cds 2020-05-11
2 ncov ? MT451684 2020-03-31 Oceania Australia Victoria Oceania Australia Victoria genome 29806 Homo sapiens ? ? ? ? Seemann et al https://www.ncbi.nlm.nih.gov/nuccore/MT451684 Severe acute respiratory syndrome coronavirus 2 isolate SARS-CoV-2/human/AUS/VIC1000/2020, complete genome 2020-05-11
3 changes: 3 additions & 0 deletions tests/numeric_strains/metadata_by_name.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name virus gisaid_epi_isl genbank_accession date region country division location region_exposure country_exposure division_exposure segment length host age sex originating_lab submitting_lab authors url title date_submitted
1 ncov ? MT450922 2020-03-05 Oceania Australia Victoria Oceania Australia Victoria genome 29812 Homo sapiens ? ? ? ? Seemann et al https://www.ncbi.nlm.nih.gov/nuccore/MT450922 Severe acute respiratory syndrome coronavirus 2 isolate SARS-CoV-2/human/AUS/VIC05/2020 ORF1ab polyprotein (ORF1ab), ORF1a polyprotein (ORF1ab), surface glycoprotein (S), ORF3a protein (ORF3a), envelope protein (E), membrane glycoprotein (M), ORF6 protein (ORF6), ORF7a protein (ORF7a), ORF7b (ORF7b), ORF8 protein (ORF8), nucleocapsid phosphoprotein (N), and ORF10 protein (ORF10) genes, complete cds 2020-05-11
2 ncov ? MT451684 2020-03-31 Oceania Australia Victoria Oceania Australia Victoria genome 29806 Homo sapiens ? ? ? ? Seemann et al https://www.ncbi.nlm.nih.gov/nuccore/MT451684 Severe acute respiratory syndrome coronavirus 2 isolate SARS-CoV-2/human/AUS/VIC1000/2020, complete genome 2020-05-11
3 changes: 3 additions & 0 deletions tests/numeric_strains/sequence_index.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
strain length A C G T N other_IUPAC - ? invalid_nucleotides
1 29812 8825 5433 5812 9498 242 2 0 0 0
2 29806 8876 5461 5849 9558 62 0 0 0 0