<jupyter_start><jupyter_text>What is the Half-Life of a HGNC Gene Symbol?**Author:** [<NAME>](https://github.com/cthoyt)**Estimated Run Time:** 10 secondsHere's an interesting question from [<NAME>](https://github.com/johnbachman): what's the half-life of a gene symbol?<jupyter_code>import datetime
import getpass
import sys
import time

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

import bio2bel_hgnc
from bio2bel_hgnc.models import HumanGene
%matplotlib inline
print(sys.version)
print(time.asctime())
print(getpass.getuser())
m = bio2bel_hgnc.Manager()
m
# calculate 5 years ago
t = datetime.datetime.now() - datetime.timedelta(days=365 * 5)
t<jupyter_output><empty_output><jupyter_text>Number of genes never modified<jupyter_code>m.session.query(HumanGene).filter(HumanGene.date_symbol_changed.is_(None)).count()<jupyter_output><empty_output><jupyter_text>Number of genes modified before 5 years ago<jupyter_code>m.session.query(HumanGene).filter(HumanGene.date_symbol_changed < t).count()
gene = m.session.query(HumanGene).filter(HumanGene.date_symbol_changed < t).first()

for k, v in gene.to_dict().items():
    if v is None:
        continue
    print('{}: {}'.format(k, v))<jupyter_output>date_name_changed: 2012-08-15
name: A1BG antisense RNA 1
entrez: 503538
date_modified: 2013-06-27
location: 19q13.43
symbol: A1BG-AS1
date_symbol_changed: 2010-11-25
identifier: 37133
date_approved_reserved: 2009-07-20
status: Approved
ucsc: uc002qse.3
ensembl_gene: ENSG00000268895
uuid: 493c3ebd-8d78-49ef-b1aa-c3ba568a72e3
vega: OTTHUMG00000183508
locus_group: non-coding RNA
locus_type: RNA, long non-coding
locationsortable: 19q13.43<jupyter_text>Number of genes modified in the last 5 years<jupyter_code>m.session.query(HumanGene).filter(HumanGene.date_symbol_changed > t).count()
gene = m.session.query(HumanGene).filter(HumanGene.date_symbol_changed > t).first()

for k, v in gene.to_dict().items():
    if v is None:
        continue
    print('{}: {}'.format(k, v))<jupyter_output>date_name_changed: 2019-07-15
name: alanyl-tRNA synthetase 1
entrez: 16
date_modified: 2019-08-10
location: 16q22.1
symbol: AARS1
date_symbol_changed: 2019-07-15
identifier: 20
date_approved_reserved: 1995-07-11
status: Approved
ucsc: uc002eyn.2
ensembl_gene: ENSG00000090861
uuid: a5340f2d-e32d-4946-8973-aa5e3b940d51
orphanet: 232194
vega: OTTHUMG00000177042
locus_group: protein-coding gene
locus_type: gene with protein product
locationsortable: 16q22.1<jupyter_text>Histogram over frequency per year<jupyter_code>years = [
    int(date.year)
    for date, in m.session.query(HumanGene.date_symbol_changed)
    if date is not None
]
print(f'Number of years to plot: {len(years)}')
year_range = max(years) - min(years)
year_range
fix, ax = plt.subplots(1, 1, figsize=(9, 6))

sns.distplot(years, kde=False, bins=year_range // 2, ax=ax)
plt.xticks(list(range(min(years), max(years) + 1)), rotation=45)
plt.xlabel('Year')
plt.ylabel('Frequency')
plt.title('Gene Symbols Changed Over Time')
plt.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12145880820579616, 'fraction_numerical': 0.07294041028980788, 'mean_word_length': 6.3317422434367545, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '342703', 'license': 'Apache-2.0', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1134, 'n_words': 249, 'path': 'gene_symbol_half_life.ipynb', 'repo_name': 'bio2bel/bio2bel-notebooks', 'size': '3090'}