<jupyter_start><jupyter_text>Data Priming<jupyter_code>is_test = False
msa_fp = '/valhalla/gisaid/sequences_2021-01-30_aligned.fasta'
meta_fp = '/valhalla/gisaid/metadata_2021-01-30_10-36.tsv.gz'
date = msa_fp.split('_')[1]
print(date)
print(msa_fp)
print(meta_fp)
# subs, _ = bm.identify_replacements_per_sample(msa_fp, meta_fp,  
#                                            bd.GENE2POS, data_src='gisaid', 
#                                            is_gzip=True, test=is_test)
# subs_fp = f'/valhalla/gisaid/subs_long_{date}.csv.gz'
# subs.to_csv(subs_fp, index=False, compression='gzip')
# dels, _ = bm.identify_deletions_per_sample(msa_fp, meta_fp,  
#                                            bd.GENE2POS, data_src='gisaid', 
#                                            min_del_len=1, is_gzip=True, 
#                                            test=is_test)
# dels_fp = f'/valhalla/gisaid/dels_long_{date}.csv.gz'
# dels.to_csv(dels_fp, index=False, compression='gzip')
# (dels.groupby(['mutation', 'absolute_coords', 'del_len', 'del_seq'])
#      .agg(num_samples=('idx', 'nunique'))
#      .reset_index()
#      .nlargest(50, 'num_samples'))
# df = pd.read_csv(meta_fp, sep='\t', compression='gzip')
cols = ['strain', 'pangolin_lineage', 'date', 'date_submitted', 'country', 'division', 'location']
# df.loc[(df['pangolin_lineage']=='P.1') & (df['country'].str.contains('USA'))][cols]<jupyter_output><empty_output><jupyter_text>Analysis Report Generation<jupyter_code>subs_fp = '/valhalla/gisaid/subs_long_2021-01-30.csv.gz'
# df = pd.read_csv(subs_fp, compression='gzip')
# feature = 'mutations'
# values = ['S:S13I', 'S:W152C', 'S:L452R']
feature = 'mutation'
# S:Q677H, M:A85S, N:D377Y,
values = ['ORF1a:I4205V', 'ORF1b:D1183Y', 'S:S13I', 'S:W152C', 'S:L452R']#['S:P681R', 'S:S254F', 'S:G769V'] 
input_params = {
    'date': '2021-01-30',
    'strain': 'CAVUI1',
    'gisaid_data_fp' : subs_fp,
    'gisaid_meta_fp': meta_fp,
    'msa_fp': Path(msa_fp),
    'sampling_type': 'random',
    'vocs': ['B.1.1.7', 'B.1.1.70'],
    'meta_fp' : Path('/home/al/code/HCoV-19-Genomics/metadata.csv'),
    'tree_fp' : Path('/home/al/analysis/alab_mutations_01-01-2021/alab/seqs_aligned.fa.treefile'),
    'subs_fp' : '/home/al/analysis/alab_mutations_01-01-2021/alab_substitutions_long_01-01-2021.csv',
    'countries_fp' : '/home/al/data/geojsons/countries.geo.json',
    'states_fp' : "/home/al/data/geojsons/us-states.json",
    'counties_fp' : '/home/al/data/geojsons/us-counties.json',
    'patient_zero' : 'NC_045512.2',
    'b117_meta' : '/home/al/analysis/b117/nextstrain_groups_neherlab_ncov_S.N501_metadata.tsv',
    'b117_tree': 'test_data/b117_seqs_aligned.fasta.treefile',
    'sample_sz': 300,
    'sampling_img_fp' : "/home/al/analysis/b117/figs/sars-cov-2_EM_v3.png"
}
results = br.generate_voc_data(feature, values, input_params)
html = br.generate_voc_html(feature, values, results, template_name='mut.html')
# br.save_html(html, f'test_data/orf1ab_i4205v_report.html')
br.save_html(html, f'test_data/cavui1_current_report.html')
# data = pd.read_csv(input_params['gisaid_data_fp'], compression='gzip')
runs = {'orf1b_d1183y': 'ORF1b:D1183Y', 
        's_s13i': 'S:S13I', 's_w152c': 'S:W152C', 's_l452r': 'S:L452R',
        's_n501y': 'S:N501Y', 's_p681h': 'S:P681H', 's_e484k': 'S:E484K'}
for name, mut in runs.items():
    input_params['strain'] = mut
    results = br.generate_voc_data(feature, [mut], input_params)
    html = br.generate_voc_html(feature, [mut], results, template_name='mut.html')
    br.save_html(html, f'test_data/{name}_current_report.html')
runs = {'s_p681r': 'S:P681R'}
for name, mut in runs.items():
    input_params['strain'] = mut
    results = br.generate_voc_data(feature, [mut], input_params)
    html = br.generate_voc_html(feature, [mut], results, template_name='mut.html')
    br.save_html(html, f'test_data/{name}_current_report.html')
# feature = 'mutations'
# values = ['S:S13I', 'S:W152C', 'S:L452R']
feature = 'mutation'
# S:Q677H, M:A85S, N:D377Y,
values = ['ORF1a:I4205V', 'ORF1b:D1183Y', 'S:S13I', 'S:W152C', 'S:L452R']#, 'S:L452R']#, 'S:W152C', 'S:L452R'] # 'ORF1ab:I4205V', 
input_params['strain'] = 'CAVUI1'
results = br.generate_voc_data(feature, values, input_params)
html = br.generate_voc_html(feature, values, results, template_name='mut.html')
# br.save_html(html, f'test_data/orf1ab_i4205v_report.html')
br.save_html(html, f'test_data/cavui1_current_report.html')
gisaid = pd.read_csv(input_params['gisaid_data_fp'], compression='gzip')
mutations = ['S:Q677H', 'M:A85S', 'N:D377Y']
m = gisaid.groupby(['country', 'division', 'strain']).agg(mutations=('mutation', 'unique')).reset_index()

m['is_vui'] = m['mutations'].apply(bv.is_vui, args=(set(mutations),))
m.loc[m['is_vui']==True, 'division'].value_counts()
# res = (gisaid.groupby(['date', 'country', 'division', 
#                                         'purpose_of_sequencing',
#                                         'location', 'pangolin_lineage', 'strain'])
#                        .agg(mutations=('mutation', 'unique')).reset_index())
# res['is_vui'] = res['mutations'].apply(bv.is_vui, args=(set(values),))

def get_mutations(data: pd.DataFrame, lineage: str='B.1.1.7'):
    mutations = set(data[data['pangolin_lineage']==lineage]['mutation'].unique().tolist())
    return mutations<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1887955182072829, 'fraction_numerical': 0.050793650793650794, 'mean_word_length': 4.302970297029703, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '225037', 'license': 'MIT', 'n_tokens_mistral': 2362, 'n_tokens_neox': 2190, 'n_words': 268, 'path': 'VoC.ipynb', 'repo_name': 'AlaaALatif/bjorn', 'size': '5355'}