<jupyter_start><jupyter_text>Module/Variable/Data setup<jupyter_code>%run ../src/python/helpers.py

%matplotlib inline
from numpy import nan, arange

from pandas import read_feather
import seaborn as sns
import ipywidgets as w

from quilt.data.hsiaoyi0504 import aeolus_top5drugs


#VARIABLES
cl = ['atc_1st','atc_2nd','atc_3rd','atc_4th','drug_concept_name']

data = read_feather(aeolus_top5drugs.aeolus_top5drugs._data())

plot_settings()<jupyter_output>/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
  return f(*args, **kwds)<jupyter_text>For a drug class, how many unique adverse reactions are reported?<jupyter_code>d = dropdown(cl)
d<jupyter_output><empty_output><jupyter_text>classes in above chosen drug class<jupyter_code>out= 'outcome_concept_name'
grpd = data.groupby([d.label,out])[out].count().sort_values(ascending=False)
grpd.name = 'n'
grpd2 = grpd.groupby(level=d.label)
series = grpd2.count()
p = plot(series,kind='barh')
q = p.set_title(p.get_ylabel().upper(),rotation=0,weight='bold')
q = p.set_ylabel("")
q = p.set_xlabel("Number of unique adverse reactions",weight="bold")<jupyter_output><empty_output><jupyter_text>What are the top adverse reactions in the chosen drug class?<jupyter_code>ds = dropdown(series.index)
ds
i = w.IntSlider(min=1,max=10,step=1,value=5)
i<jupyter_output><empty_output><jupyter_text>indices for most frequent ADRs<jupyter_code>sub = data.query('{0} in @ds.label'.format(d.label)).groupby([d.label,out])[out].count().sort_values(ascending=False).head(i.value)
sub.name= "n"
sub = sub.reset_index()
p = sns.barplot(y=d.label,x='n',hue=out,data=sub,orient='h')
p.legend(bbox_to_anchor=(1.7,1))
q = p.set_ylabel('')<jupyter_output><empty_output><jupyter_text>How do the ADRs break down by report year?<jupyter_code>outs = sub.iloc[:,1].values
sub2 = data.query('({0}==@ds.label) & ({1} in @outs)'.format(d.label,out))
series2 = freqXbyY(sub2,'report_year','id')
p = plot(series2,kind='bar')
q = p.set_title(p.get_ylabel().upper(),rotation=0,weight='bold')
q = p.set_ylabel(p.get_ylabel(),rotation=0)
q = p.set_xlabel("Number of Reports",weight="bold")<jupyter_output><empty_output><jupyter_text>subset data by chosen year(s)<jupyter_code>labels = series2.index
mds = w.SelectMultiple(options = labels ,value = tuple(labels))
mds<jupyter_output><empty_output><jupyter_text>How many are reported within these ADRs across the sexes?<jupyter_code>#plot variables for filtering/wrangling
bars = 'gender_code'
x = 'report_year'
count = 'id'
dat = clean_gender(sub2).query('report_year in @mds.label')

#main
sub_dat = dat[[bars,x,count]]
plot_sub_dat = sub_dat.groupby([bars,x]).count().reset_index(level=bars).pivot(columns=bars)
plot_sub_dat.columns = plot_sub_dat.columns.droplevel(level=0)
plot_sub_dat.plot.bar()<jupyter_output><empty_output><jupyter_text>How many are reported within this class across ages?<jupyter_code>#plot variables for filtering/wrangling
grp = 'age_cat'

#main
dat[[d.label,grp]].groupby([grp]).count().plot.bar()<jupyter_output><empty_output><jupyter_text>How many are reported within this class across ages for each sex?<jupyter_code>#plot variables for filtering/wrangling
bars = 'gender_code'
x = 'age_cat'
count = 'id'

#want to filter dataset for M/F gender and if report year was clicked or selected
sub_dat = clean_gender(dat)[[bars,x,count]]

#main
plot_sub_dat = sub_dat.groupby([bars,x]).count().reset_index(level=bars).pivot(columns=bars)
plot_sub_dat.columns = plot_sub_dat.columns.droplevel(level=0)
plot_sub_dat.plot.bar()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.149527665317139, 'fraction_numerical': 0.013765182186234818, 'mean_word_length': 8.150617283950618, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '44224', 'license': 'MIT', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1415, 'n_words': 241, 'path': 'sandbox/feature_drugs_and_outcomes.ipynb', 'repo_name': 'hsiaoyi0504/SafeDrugs', 'size': '3705'}