Skip to content

Commit

Permalink
Fix: JSON merging when not using --hrna
Browse files Browse the repository at this point in the history
  • Loading branch information
persalteas committed Aug 17, 2021
1 parent 1eae2e9 commit 149243a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 42 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Contents:
* [Database tables documentation](doc/Database.md)
* [FAQ](doc/FAQ.md)
* [Troubleshooting](#troubleshooting)
* [Known Issues and Feature Requests](doc/KnownIssues.md)
* [Contact](#contact)

## Cite us
Expand Down
90 changes: 49 additions & 41 deletions geometric_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ def gmm_hrna_basepair_type(type_LW, ntpair, data, scan):
setproctitle(f"GMM (HiRE-RNA {type_LW} {ntpair} basepairs) finished")

@trace_unhandled_exceptions
def merge_jsons():
def merge_jsons(do_hrna):
"""
Reads the tons of JSON files produced by the geometric analyses, and compiles them into fewer files.
It is simple concatenation of the JSONs.
Expand All @@ -1744,55 +1744,62 @@ def merge_jsons():
bonds = [ runDir + "/results/geometry/json/" + x + ".json" for x in bonds ]
concat_jsons(bonds, runDir + "/results/geometry/json/all_atom_distances.json")


# All atom torsions
torsions = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Xhi", "Zeta"]
torsions = [ runDir + "/results/geometry/json/" + x + ".json" for x in torsions ]
concat_jsons(torsions, runDir + "/results/geometry/json/all_atom_torsions.json")

# HiRE-RNA distances
hrnabonds = [r"P-O5'", r"O5'-C5'", r"C5'-C4'", r"C4'-C1'", r"C1'-B1", r"B1-B2", r"C4'-P"]
hrnabonds = [ runDir + "/results/geometry/json/" + x + ".json" for x in hrnabonds ]
concat_jsons(hrnabonds, runDir + "/results/geometry/json/hirerna_distances.json")

# HiRE-RNA angles
hrnaangles = [r"P-O5'-C5'", r"O5'-C5'-C4'", r"C5'-C4'-C1'", r"C4'-C1'-B1", r"C1'-B1-B2", r"C4'-P-O5'", r"C5'-C4'-P", r"C1'-C4'-P"]
hrnaangles = [ runDir + "/results/geometry/json/" + x + ".json" for x in hrnaangles ]
concat_jsons(hrnaangles, runDir + "/results/geometry/json/hirerna_angles.json")

# HiRE-RNA torsions
hrnators = [r"P-O5'-C5'-C4'", r"O5'-C5'-C4'-C1'", r"C5'-C4'-C1'-B1", r"C4'-C1'-B1-B2", r"C4'-P°-O5'°-C5'°", r"C5'-C4'-P°-O5'°", r"C1'-C4'-P°-O5'°", r"O5'-C5'-C4'-P°"]
hrnators = [ runDir + "/results/geometry/json/" + x + ".json" for x in hrnators ]
concat_jsons(hrnators, runDir + "/results/geometry/json/hirerna_torsions.json")

# HiRE-RNA basepairs
for nt1 in ['A', 'C', 'G', 'U']:
for nt2 in ['A', 'C', 'G', 'U']:
bps = glob.glob(runDir + f"/results/geometry/json/*{nt1}{nt2}*.json")
concat_jsons(bps, runDir + f"/results/geometry/json/hirerna_{nt1}{nt2}_basepairs.json")

# Delete previous files
for f in bonds + torsions + hrnabonds + hrnaangles + hrnators:
try:
os.remove(f)
except FileNotFoundError:
pass
for f in glob.glob(runDir + "/results/geometry/json/t*.json"):
try:
os.remove(f)
except FileNotFoundError:
pass
for f in glob.glob(runDir + "/results/geometry/json/c*.json"):
try:
os.remove(f)
except FileNotFoundError:
pass
for f in glob.glob(runDir + "/results/geometry/json/*tips_distance.json"):
for f in bonds + torsions:
try:
os.remove(f)
except FileNotFoundError:
pass

if do_hrna:
# HiRE-RNA distances
hrnabonds = [r"P-O5'", r"O5'-C5'", r"C5'-C4'", r"C4'-C1'", r"C1'-B1", r"B1-B2", r"C4'-P"]
hrnabonds = [ runDir + "/results/geometry/json/" + x + ".json" for x in hrnabonds ]
concat_jsons(hrnabonds, runDir + "/results/geometry/json/hirerna_distances.json")

# HiRE-RNA angles
hrnaangles = [r"P-O5'-C5'", r"O5'-C5'-C4'", r"C5'-C4'-C1'", r"C4'-C1'-B1", r"C1'-B1-B2", r"C4'-P-O5'", r"C5'-C4'-P", r"C1'-C4'-P"]
hrnaangles = [ runDir + "/results/geometry/json/" + x + ".json" for x in hrnaangles ]
concat_jsons(hrnaangles, runDir + "/results/geometry/json/hirerna_angles.json")

# HiRE-RNA torsions
hrnators = [r"P-O5'-C5'-C4'", r"O5'-C5'-C4'-C1'", r"C5'-C4'-C1'-B1", r"C4'-C1'-B1-B2", r"C4'-P°-O5'°-C5'°", r"C5'-C4'-P°-O5'°", r"C1'-C4'-P°-O5'°", r"O5'-C5'-C4'-P°"]
hrnators = [ runDir + "/results/geometry/json/" + x + ".json" for x in hrnators ]
concat_jsons(hrnators, runDir + "/results/geometry/json/hirerna_torsions.json")

# HiRE-RNA basepairs
for nt1 in ['A', 'C', 'G', 'U']:
for nt2 in ['A', 'C', 'G', 'U']:
bps = glob.glob(runDir + f"/results/geometry/json/*{nt1}{nt2}*.json")
concat_jsons(bps, runDir + f"/results/geometry/json/hirerna_{nt1}{nt2}_basepairs.json")

# Delete previous files
for f in hrnabonds + hrnaangles + hrnators:
try:
os.remove(f)
except FileNotFoundError:
pass
for f in glob.glob(runDir + "/results/geometry/json/t*.json"):
try:
os.remove(f)
except FileNotFoundError:
pass
for f in glob.glob(runDir + "/results/geometry/json/c*.json"):
try:
os.remove(f)
except FileNotFoundError:
pass
for f in glob.glob(runDir + "/results/geometry/json/*tips_distance.json"):
try:
os.remove(f)
except FileNotFoundError:
pass

@trace_unhandled_exceptions
def concat_worker(bunch):
"""
Expand Down Expand Up @@ -1876,8 +1883,9 @@ def concat_jsons(flist, outfilename):

result = []
for f in flist:
# if not os.path.isfile(f):
# continue:
if not os.path.isfile(f):
warn("Unable to find "+f)
continue
with open(f, "rb") as infile:
result.append(json.load(infile))

Expand Down
2 changes: 1 addition & 1 deletion statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,6 @@ def process_jobs(joblist):
if DO_WADLEY_ANALYSIS:
joblist.append(Job(function=gmm_pyle, args=(RESCAN_GMM_COMP_NUM, res_thr)))
process_jobs(joblist)
merge_jsons()
merge_jsons(DO_HIRE_RNA_MEASURES)


0 comments on commit 149243a

Please sign in to comment.