-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_Calculate_Statistics_D2P2.py
135 lines (100 loc) · 5.17 KB
/
_Calculate_Statistics_D2P2.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import csv
import math
import os
import pandas as pd
import statistics
import numpy
def CalculateStatisticsD2P2(query, inputPath):
# Global Variables
columnLst = ['Position', 'Score']
capitalizeQuery = query.capitalize()
# Paths/Files/Input/Output #
corePathHuman = "{path}Core/_Human/".format(path=inputPath)
nonCorePathHuman = "{path}NonCore/_Human/".format(path=inputPath)
corePathCow = "{path}Core/_Cow/".format(path=inputPath)
nonCorePathCow = "{path}NonCore/_Cow/".format(path=inputPath)
corePathMouse = "{path}Core/_Mouse/".format(path=inputPath)
nonCorePathMouse = "{path}NonCore/_Mouse/".format(path=inputPath)
corePathZebrafish = "{path}Core/_Zebrafish/".format(path=inputPath)
nonCorePathZebrafish = "{path}NonCore/_Zebrafish/".format(path=inputPath)
corePathFly = "{path}Core/_Fly/".format(path=inputPath)
nonCorePathFly = "{path}NonCore/_Fly/".format(path=inputPath)
corePathWorm = "{path}Core/_Worm/".format(path=inputPath)
nonCorePathWorm = "{path}NonCore/_Worm/".format(path=inputPath)
corePathYeast = "{path}Core/_Yeast/".format(path=inputPath)
nonCorePathYeast = "{path}NonCore/_Yeast/".format(path=inputPath)
corePathFrog = "{path}Core/_Frog/".format(path=inputPath)
nonCorePathFrog = "{path}NonCore/_Frog/".format(path=inputPath)
outputPath = "{path}{studying}_Disorder_Statistics.csv".format(path=inputPath, studying=capitalizeQuery)
# Find all the files in each organism and open the csv
def CalculateStats(inputPaths, orgnName, coreOrNonCore):
# Search Files and Store as List
fileLst = []
for r, d, f in os.walk(inputPaths):
for file in f:
if file.endswith(".csv") and file.startswith("{studying}".format(studying=capitalizeQuery)):
fileLst.append(file)
# Open Files, Calculate Averages, and Store as list
avgLst = []
avgLstFirst = []
avgLstSecond = []
avgLstThird = []
for element in fileLst:
df = pd.read_csv("{inputPath}{element}".format(inputPath=inputPaths, element=element), usecols=columnLst)
scoreLst = df['Score'].tolist()
avgLst.append(statistics.mean(scoreLst))
splitScoreLst = numpy.array_split(scoreLst, 3)
avgLstFirst.append(statistics.mean(splitScoreLst[0].tolist()))
avgLstSecond.append(statistics.mean(splitScoreLst[1].tolist()))
avgLstThird.append(statistics.mean(splitScoreLst[2].tolist()))
# Calculate the Averages of the AverageLst
avgOfAvgs = statistics.mean(avgLst)
avgOfFirst = statistics.mean(avgLstFirst)
avgOfSecond = statistics.mean(avgLstSecond)
avgOfThird = statistics.mean(avgLstThird)
# Calculate the Standard Deviation of AverageLst divided by sqrt of number of samples
try:
stDevOfAvgs = statistics.stdev(avgLst) / (math.sqrt(len(fileLst)))
stdevOfFirst = statistics.stdev(avgLstFirst) / (math.sqrt(len(fileLst)))
stdevOfSecond = statistics.stdev(avgLstSecond) / (math.sqrt(len(fileLst)))
stdevOfThird = statistics.stdev(avgLstThird) / (math.sqrt(len(fileLst)))
except:
print("Cannot Calculate Variance for ", orgnName, "because variance requires at least two data points")
stDevOfAvgs = "Cannot Calculate"
stdevOfFirst = "Cannot Calculate"
stdevOfSecond = "Cannot Calculate"
stdevOfThird = "Cannot Calculate"
# Calculate the 1/3s of the disordered regions
# Write to CSV
dataLst = [orgnName, coreOrNonCore, avgOfAvgs, stDevOfAvgs, avgOfFirst, stdevOfFirst, avgOfSecond,
stdevOfSecond, avgOfThird, stdevOfThird]
WriteToCSV(outputPath, dataLst, 'a')
def WriteToCSV(pathOutput, row, fileMode):
with open(pathOutput, fileMode) as fd:
wr = csv.writer(fd, quoting=csv.QUOTE_ALL)
wr.writerow(row)
##----------- Execution ----------- ##
try:
os.remove(outputPath)
except:
pass
WriteToCSV(outputPath,
['Organism', 'Core or NonCore', 'Mean of Sample Mean', 'Standard Deviation', 'Mean of Sample Mean First',
'Std Dev First', 'Mean of Sample Mean Second', 'Std Dev Second', 'Mean of Sample Mean Third',
'Std Dev Third'], 'a')
CalculateStats(corePathHuman, "Human", "Core")
CalculateStats(nonCorePathHuman, "Human", "NonCore")
CalculateStats(corePathCow, "Cow", "Core")
CalculateStats(nonCorePathCow, "Cow", "NonCore")
CalculateStats(corePathMouse, "Mouse", "Core")
CalculateStats(nonCorePathMouse, "Mouse", "NonCore")
CalculateStats(corePathZebrafish, "Zebrafish", "Core")
CalculateStats(nonCorePathZebrafish, "Zebrafish", "NonCore")
CalculateStats(corePathFly, "Fly", "Core")
CalculateStats(nonCorePathFly, "Fly", "NonCore")
CalculateStats(corePathWorm, "Worm", "Core")
CalculateStats(nonCorePathWorm, "Worm", "NonCore")
CalculateStats(corePathYeast, "Yeast", "Core")
CalculateStats(nonCorePathYeast, "Yeast", "NonCore")
CalculateStats(corePathFrog, "Frog", "Core")
CalculateStats(nonCorePathFrog, "Frog", "NonCore")