Exemplo n.º 1
0
def test1(): 

  import time
  
  cal_id = 3
  dep_id = 105
  t_start = 1407452400 
  t_end = 1407455985 - (59 * 60) 

  db_con = util.get_db('reader')
  sv = signal1.SteeringVectors(db_con, cal_id)
  signal = signal1.Signal(db_con, dep_id, t_start, t_end)

  sites = util.get_sites(db_con)
  (center, zone) = util.get_center(db_con)
  assert zone == util.get_utm_zone(db_con)
  
  start = time.time()
  pos = PositionEstimator(dep_id, sites, center, signal, sv, 
    method=signal1.Signal.MLE)
  print "Finished in {0:.2f} seconds.".format(time.time() - start)
 
  print compute_conf(pos.p, pos.num_sites, sites, pos.splines)
                 var_name='otu',
                 value_name='abun')
dflong = dflong.merge(meta[['site', 'subject_id']],
                      left_on='sample',
                      right_index=True)
# Remove any samples corresponding to second time point
# Fundo samples end in F2 (corresponding to patient X-F1)
# gastric/throat time points end in GI/GF or TI/TF
exclude = ['2', 'F', 'sick', 'F2T']
for s in exclude:
    dflong = dflong[~dflong['sample'].str.endswith(s)]
# And remove any lung transplant samples
dflong = dflong[~dflong['sample'].str.startswith('05')]

## Correlations
sites = util.get_sites()
res = []

## Set up the inputs to parallel code
fxn_data = []
print('Setting up input data...')
for n in range(args.nshuffle):
    print(n)
    # Shuffle patient IDs within site-OTU combination
    dflong['subject_id'] = dflong\
        .groupby(['site', 'otu'])['subject_id']\
        .transform(np.random.permutation)
    # This is very slow. I could probably make it faster somehow?
    for o, otudf in dflong.groupby('otu'):
        # For each pairwise site combo:
        for site1 in sites: