<jupyter_start><jupyter_text>Find titers by strain passage historyI need to find the number of titer measurements for which: * both test and reference strains are unpassaged * only the test strain is unpassaged * the test strain is passaged Given the above, here is where the data live:  * titers: `dist/fauna/data/h3n2_who_hi_cell_titers.tsv` * list of (potentially or definitely) passaged strains: `outliers/non_reference_passaged_strains.txt`<jupyter_code>import pandas as pd
%matplotlib inline
# Open list of passaged strains.
with open("../outliers/non_reference_passaged_strains.txt", "r") as fh:
    passaged_strains = set([line.rstrip().split("|")[0] for line in fh])
len(passaged_strains)
titers = pd.read_table(
    "../dist/fauna/data/h3n2_who_hi_cell_titers.tsv",
    header=None,
    index_col=False,
    names=["test", "reference", "serum", "source", "titer", "assay"]
)
list(passaged_strains)[:10]
def get_passage_status(record):
    test_unpassaged = record["test"] not in passaged_strains
    ref_unpassaged = record["reference"] not in passaged_strains
    
    if test_unpassaged and ref_unpassaged:
        return "unpassaged"
    elif test_unpassaged:
        return "test_unpassaged"
    elif ref_unpassaged:
        return "ref_unpassaged"
    else:
        return "passaged"
titers["passage_status"] = titers.apply(get_passage_status, axis=1)
titers.shape
titers["passage_status"].value_counts()
distinct_unpassaged_viruses = titers[titers["passage_status"] == "unpassaged"].loc[:, ["test", "reference", "serum"]].drop_duplicates()
distinct_unpassaged_viruses["test"].apply(lambda virus: int(virus.split("/")[-1].replace("-egg", ""))).value_counts()
distinct_passaged_viruses = titers[titers["passage_status"] != "unpassaged"].loc[:, ["test", "reference", "serum"]].drop_duplicates()
passaged_measurements_per_year = distinct_passaged_viruses["test"].apply(
    lambda virus: int(virus.split("/")[-1].replace("-egg", ""))
).value_counts().reset_index()
passaged_measurements_per_year
ax = passaged_measurements_per_year[(passaged_measurements_per_year["index"] > 2005) & (passaged_measurements_per_year["index"] < 2019)].plot(
    x="index",
    y="test",
    kind="bar",
    legend=False
)
ax.set_xlabel("Year")
ax.set_ylabel("Titer measurements")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13900955690703737, 'fraction_numerical': 0.007819287576020852, 'mean_word_length': 6.021341463414634, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '574618', 'license': 'MIT', 'n_tokens_mistral': 805, 'n_tokens_neox': 778, 'n_words': 156, 'path': 'analyses/2018-10-26-find-titers-by-strain-passage-history.ipynb', 'repo_name': 'blab/flu-forecasting', 'size': '2302'}