forked from fechitheodore/GenomeGit3.1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StoreAlignment.py
68 lines (57 loc) · 2.12 KB
/
StoreAlignment.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
#!/usr/bin/env python
# PYTHON FUNCTIONS REQUIRED IN THE REPOSITORY AUTO-UPDATES PART I: ALIGNMENT OBTENTION.
# Make the imports
import hashlib
import pickle
def store_variables(variables, alignment_pickle):
"""
Create a store_variables function to store the provided variables into a pickle
"""
# Open a pickle
with open("{}/pickle".format(alignment_pickle), "wb") as pickle_file:
# Store the variable list
pickle.dump(variables, pickle_file, protocol=1)
# Close the pickle
pickle_file.close()
def load_variables(alignment_pickle):
"""
Create a load_variables function to load variabled from a pickle file
"""
# Open the pickle
with open(alignment_pickle, "rb") as pickle_file:
# Load the alignment pickle.
variables = pickle.load(pickle_file)
# Close the pickle
pickle_file.close()
# Return the data
return variables
def obtain_alignment_pickle(old_assembly, new_assembly):
"""
Create a obtain_alignment_pickle to obtain the name of the pickle of two given assemblies
"""
# Initiate the content list
content = []
# Open the new assembly and loop through the lines
with open(new_assembly, "r") as new_assembly_file:
for line in new_assembly_file:
# Append the line to the content list
line = line.rstrip()
content.append(line)
# Close the file
new_assembly_file.close()
# Obtain the hash
new_assembly_hash = str(hashlib.sha1("".join(content).encode('utf-8')).hexdigest())
# Reinititate the content list
content = []
# Open the new assembly and loop through the lines
with open(old_assembly, "r") as old_assembly_file:
for line in old_assembly_file:
# Append the line to the content list
line = line.rstrip()
content.append(line)
# Close the file
old_assembly_file.close()
# Obtain the hash
old_assembly_hash = str(hashlib.sha1("".join(content).encode('utf-8')).hexdigest())
# Return the combination of both hashes
return str("./Delta/{}_{}".format(new_assembly_hash, old_assembly_hash))