import re import os import glob # Python 2.7.11 written by Ali Khalighifar on July 31, 2017 # This script generates the summary table for all the outputs of EstimateS # It selects the last line of each table (the number of tables is 2100) home = 'Working Directory' finalDir = home + '\\outputs' os.chdir(finalDir) # Making a new table to add the summaries of 2100 tables table = open('table.txt', 'w') table.write('Rep\t'+'Abund Error\t'+'Mean Abund\t'+'Days\t'+ 'Individuals (computed)\t'+'S(est)\t'+'S(est) 95% CI Lower Bound\t' +'S(est) 95% CI Upper Bound\t'+'S(est) SD\t'+'S Mean (runs)\t' +'Singletons Mean\t'+'Singletons SD (runs)\t'+'Doubletons Mean\t' +'Doubletons SD (runs)\t'+'Uniques Mean\t'+'Uniques SD (runs)\t' +'Duplicates Mean\t'+'Duplicates SD (runs)\t'+'ACE Mean\t' +'ACE SD (runs)\t'+'ICE Mean\t'+'ICE SD (runs)\t'+'Chao 1 Mean\t' +'Chao 1 95% CI Lower Bound\t'+'Chao 1 95% CI Upper Bound\t' +'Chao 1 SD (analytical)\t'+'Chao 2 Mean\t'+'Chao 2 95% CI Lower Bound\t' +'Chao 2 95% CI Upper Bound\t'+'Chao 2 SD (analytical)\t'+'Jack 1 Mean\t' +'Jack 1 SD (analytical)\t'+'Jack 2 Mean\t'+'Jack 2 SD (runs)\t' +'Bootstrap Mean\t'+'Bootstrap SD (runs)\t'+'MMRuns Mean\t' +'MMMeans (1 run)\t'+'Cole Rarefaction\t'+'Cole SD (analytical)\t' +'Alpha Mean\t'+'Alpha SD (analytical)\t'+'Shannon Mean\t' +'Shannon SD (runs)\t'+'Shannon Exponential Mean\t' +'Shannon Exponential SD (runs)\t'+'Simpson Inv Mean\t' +'Simpson Inv SD (runs)\n') os.chdir(baseDir) files = [txt_file for txt_file in glob.iglob ('*.txt')] for txtFile in files: abund_type = ', '.join(re.findall(r'(High)', txtFile)) err_type = ', '.join(re.findall(r'^(nine)', txtFile)) days = ', '.join(re.findall(r'(\d{1,4}days)', txtFile)) days = ', '.join(re.findall(r'(\d{1,4})', days)) rep = ', '.join(re.findall(r'(Rep\d{1,3})', txtFile)) rep = ', '.join(re.findall(r'(\d{1,3})', rep)) lines = open(txtFile, 'r').readlines()[int(days)+2] lines = re.split(r'^''\d{1,4}\t', lines) del lines[0] lines = ', '.join(lines) table.write(rep + '\t' + err_type + '\t' + abund_type + '\t' + days + '\t' + lines) table.close()