-
Notifications
You must be signed in to change notification settings - Fork 3
/
calc_relgrowthrates.py
34 lines (26 loc) · 1.15 KB
/
calc_relgrowthrates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pandas as pd
from freyja.utils import calc_rel_growth_rates
import numpy as np
np.random.seed(1)
#growth rate calc based on PL data
agg_df = pd.read_csv('PointLoma_sewage_seqs.csv',header=0,skipinitialspace=True,index_col='Date')
agg_df.index = pd.to_datetime(agg_df.index)
#drop VOC aggregations.
# agg_df = agg_df.drop(columns=['Alpha','Omicron','Delta'])
#restrict to more recent samples in case this gets big.
daysIncluded = 56 # Use last 8 weeks of sample data
import datetime
h = pd.to_datetime(agg_df.index[-1]-datetime.timedelta(days=daysIncluded))
agg_df = agg_df.loc[agg_df.index>h]
nboots = 1000
serial_interval = 3.1 #estimated omicron serial interval
agg_df = agg_df.loc[:,agg_df.sum(axis=0)>0]
agg_df['Other'] = 100.-agg_df.sum(axis=1)
calc_rel_growth_rates(agg_df,nboots,serial_interval,'rel_growth_rates.csv',daysIncluded,thresh=0.01)
df = pd.read_csv('rel_growth_rates.csv',index_col='Lineage')
if 'Other' in df.index:
df = df.drop(index=['Other'])
df['EA'] = df['Estimated Advantage'].apply(lambda x:x[0:len(x)-1]).astype(float)
df = df.sort_values(by='EA',ascending=False)
df= df.drop(columns=['EA'])
df.to_csv('rel_growth_rates.csv')