if not (1 <= tmp['fmin']['theta'] < com.S and \ 1e-50 <= tmp['fmin']['m'] < 1-1e-50): del (tmp['fmin']) # find the model with the higher likelihood: met = min(tmp, key=lambda x: tmp[x]['lnL']) # load it as 'etienne' model com.set_model(tmp[met]['model']) lrt = com.lrt('ewens', 'etienne') best = 'ewens' if lrt > 0.05 else 'etienne' print 'Best model by LRT was: ' + best com.generate_random_neutral_distribution(model=best) pval, neut_h = com.test_neutrality(model=best, gens=10000, full=True) #draw_shannon_distrib(neut_h, abd.shannon) draw_shannon_distrib(neut_h, com.shannon, outfile='Fulcaldea_stuessyi_log_shannon_dist.pdf', filetype='pdf') print 'P-value for neutrality test was: ', pval out = open('Fulcaldea_stuessyi_log_shannon_neutral_data.tsv', 'w') out.write('# shannon:' + str(com.shannon) + '\n') out.write('\n'.join([str(s for s in neut_h)]) + '\n') out.close() com.dump_community('Fulcaldea_stuessyi_log_ecolopy.pik')
print ' optimization failed: ' + e.args[0] # in case optimization by fmin failed to found correct values for theta and m: if not (1 <= tmp['fmin']['theta'] < com.S and \ 1e-50 <= tmp['fmin']['m'] < 1-1e-50): del (tmp['fmin']) # find the model with the higher likelihood: met = min(tmp, key=lambda x: tmp[x]['lnL']) # load it as 'etienne' model com.set_model(tmp[met]['model']) lrt = com.lrt('ewens', 'etienne') best = 'ewens' if lrt > 0.05 else 'etienne' print 'Best model by LRT was: ' + best com.generate_random_neutral_distribution(model=best) pval, neut_h = com.test_neutrality (model=best, gens=10000, full=True) #draw_shannon_distrib(neut_h, abd.shannon) draw_shannon_distrib(neut_h, com.shannon, outfile='Fulcaldea_stuessyi_log_shannon_dist.pdf', filetype='pdf') print 'P-value for neutrality test was: ', pval out = open('Fulcaldea_stuessyi_log_shannon_neutral_data.tsv', 'w') out.write('# shannon:' + str(com.shannon) + '\n') out.write('\n'.join([str(s for s in neut_h)]) + '\n') out.close() com.dump_community('Fulcaldea_stuessyi_log_ecolopy.pik')
# find the model with the higher likelihood: met = min(tmp, key=lambda x: tmp[x]['lnL']) # load it as 'etienne' model com.set_model(tmp[met]['model']) lrt = com.lrt('ewens', 'etienne') best = 'ewens' if lrt > 0.05 else 'etienne' print 'Best model by LRT was: ' + best com.generate_random_neutral_distribution(model=best) pval, neut_h = com.test_neutrality(model=best, gens=10000, full=True, method='shannon', n_cpus=4) draw_shannon_distrib(neut_h, com.shannon, outfile='test_log_shannon_dist.pdf', filetype='pdf') print 'P-value for neutrality test was: ', pval out = open('test_log_shannon_neutral_data.tsv', 'w') out.write('# shannon:' + str(com.shannon) + '\n') out.write('\n'.join([str(s) for s in neut_h]) + '\n') out.close() com.dump_community('test_log_ecolopy.pik')
except Exception as e: print ' optimization failed: ' + e.args[0] # in case optimization by fmin failed to found correct values for theta and m: if not (1 <= tmp['fmin']['theta'] < com.S and \ 1e-50 <= tmp['fmin']['m'] < 1-1e-50): del (tmp['fmin']) # find the model with the higher likelihood: met = min(tmp, key=lambda x: tmp[x]['lnL']) # load it as 'etienne' model com.set_model(tmp[met]['model']) lrt = com.lrt('ewens', 'etienne') best = 'ewens' if lrt > 0.05 else 'etienne' print 'Best model by LRT was: ' + best com.generate_random_neutral_distribution(model=best) pval, neut_h = com.test_neutrality (model=best, gens=10000, full=True, method='shannon', n_cpus=4) draw_shannon_distrib(neut_h, com.shannon, outfile='test_log_shannon_dist.pdf', filetype='pdf') print 'P-value for neutrality test was: ', pval out = open('test_log_shannon_neutral_data.tsv', 'w') out.write('# shannon:' + str(com.shannon) + '\n') out.write('\n'.join([str(s) for s in neut_h]) + '\n') out.close() com.dump_community('test_log_ecolopy.pik')