Skip to content

Commit

Permalink
Use 'with' to open files.
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Apr 6, 2017
1 parent 8a545e7 commit 273ae90
Showing 1 changed file with 37 additions and 48 deletions.
85 changes: 37 additions & 48 deletions human/scripts/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@
for z, fil in enumerate(files[:1]):
print(fil)
data = open(fil)
D = data.readlines()
data.close()
with open(fil) as data:
D = data.readlines()
# find frame with the lowest score
scores = {}
Expand Down Expand Up @@ -85,9 +84,8 @@
for z, fil in enumerate(files[:1]):
print(fil)
data = open(fil)
D = data.readlines()
data.close()
with open(fil) as data:
D = data.readlines()
# find frame with the lowest score
scores = {}
Expand Down Expand Up @@ -123,26 +121,24 @@
#####################################################

S = []
out = open('scores.out','w')
for z, fil in enumerate(files):

data = open(fil)
D = data.readlines()
data.close()

# find frame with the lowest score
scores = {}
H = eval(D[0].strip())
H = dict([(H[c],c) for c in H]) # creates reverse dictionary

for i,d in enumerate(D[1:]):
dct = eval(d.strip('\n'))
score = float(dct[H['SimplifiedModel_Total_Score_None']])
scores[score] = i
S.append(min(scores.keys()))
print(fil, min(scores.keys()))
out.write(fil+'\t'+str(min(scores.keys()))+'\n')
out.close()
with open('scores.out','w') as out:
for z, fil in enumerate(files):

with open(fil) as data:
D = data.readlines()

# find frame with the lowest score
scores = {}
H = eval(D[0].strip())
H = dict([(H[c],c) for c in H]) # creates reverse dictionary

for i,d in enumerate(D[1:]):
dct = eval(d.strip('\n'))
score = float(dct[H['SimplifiedModel_Total_Score_None']])
scores[score] = i
S.append(min(scores.keys()))
print(fil, min(scores.keys()))
out.write(fil+'\t'+str(min(scores.keys()))+'\n')
print(S, len(S))

import matplotlib
Expand All @@ -160,9 +156,8 @@
Scores=[]
for z, fil in enumerate(files):

data = open(fil)
D = data.readlines()
data.close()
with open(fil) as data:
D = data.readlines()

# find frame with the lowest score
scores = {}
Expand Down Expand Up @@ -206,9 +201,8 @@
print(V,len(V),'1111111')
pl.savefig('bar_xlink_violation_counts_run%d.png' % run_number)

ofile=open('violation_counts_alltopscoring_34A.txt','w')
ofile.write(str(V))
ofile.close()
with open('violation_counts_alltopscoring_34A.txt','w') as ofile:
ofile.write(str(V))

#exit()

Expand All @@ -219,9 +213,8 @@
Clusters = analysis.Clustering()
for cnt,fil in enumerate(files):

data = open(fil)
D = data.readlines()
data.close()
with open(fil) as data:
D = data.readlines()

# find frame with the lowest score
H = eval(D[0].strip())
Expand Down Expand Up @@ -273,10 +266,9 @@

"""
# This is needed for the analysis steps that depend on clustering
infile = open('cluster_run%d.out' % run_number)
dominantClusterNumber=0 # this is true for both independent runs
Clusters = eval(infile.read())
infile.close()
with open('cluster_run%d.out' % run_number) as infile:
dominantClusterNumber=0 # this is true for both independent runs
Clusters = eval(infile.read())
import sys
files = [i.rsplit('.',1)[0] for i in Clusters[dominantClusterNumber][1]]
Expand All @@ -292,9 +284,8 @@
#####################################################
for z, fil in enumerate(files):
data = open(fil)
D = data.readlines()
data.close()
with open(fil) as data:
D = data.readlines()
# find frame with the lowest score
scores = {}
Expand Down Expand Up @@ -332,9 +323,8 @@

for z, fil in enumerate(files):

data = open(fil)
D = data.readlines()
data.close()
with open(fil) as data:
D = data.readlines()

# find frame with the lowest score
scores = {}
Expand Down Expand Up @@ -412,9 +402,8 @@

for z, fil in enumerate(files):

data = open(fil)
D = data.readlines()
data.close()
with open(fil) as data:
D = data.readlines()

# find frame with the lowest score
H = eval(D[0].strip())
Expand Down

0 comments on commit 273ae90

Please sign in to comment.