Repository navigation
Expand file tree
/
Copy pathepisurf.py
More file actions
119 lines (99 loc) · 2.87 KB
/
Copy pathepisurf.py
File metadata and controls
119 lines (99 loc) · 2.87 KB
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
## EPISURF
## GOAL: LABEL THE EPITOPE BASED ON ACCESSIBILITY ON THE PARENTAL PROTEIN
# IMPORTS
import sys
import csv
import os.path
from pathlib import Path
import pandas as pd
# HELP
h = '''
To right usage of this script:
$ python3 episurf.py
The files in use have to be provided by stating "location/file_name.csv"
to the input questions that appear in the console.
<file_name> should be a .csv separated by ";"
You have to provide coma separated buried positions
For example: 0,16,32,64
The script returns a <file_name>_out.xlsx as output.
You need python 3 installed in your computer!!!
'''
# FILE CHECK
def fileExist(file):
if file!="":
if Path(file).is_file():
return True
elif file=='-h':
print(h)
else:
print("\n>>>>>>> "+file + " File not exist or is not accessible\n")
return False
else:
return False
num_args=len(sys.argv)
if num_args>=2:
data_file = sys.argv[1]
if num_args==3:
inputaccess = sys.argv[2]
if num_args==4:
outpath = sys.argv[3]
# VARIABLES
data_file=""
inputaccess=""
access=""
outpath=""
# FILE NOT EXIST
while not fileExist(data_file):
data_file = input(''' Provide location and name of the file dataset.
For example: brewpitopes/F_epiglycan/glycan_extracted.csv
(-h for help)
Here: ''')
print("Input file:" + data_file)
# FILE NOT EXIST
while not os.path.exists(outpath):
outpath = input(''' Provide the desired output path.
For example: brewpitopes/G_episurf
(-h for help)
Here: ''')
print("Input file:" + outpath)
# OPEN READ FILE
extension = os.path.splitext(data_file)[1]
lenextension=len(extension)
nameOutFile=outpath+"/access_extracted"+extension
# GLYCAN INPUT
while not fileExist(inputaccess):
inputaccess = input(''' Provide location and name of the file dataset.
For example: brewpitopes/G_episurft/buried_positions_list.csv
(-h for help)
Here: ''')
print("Input file:" + inputaccess)
## READ DATA
data = pd.read_csv(data_file, sep = ",")
#data
## READ MOLSOFT EXTRACTED RESULTS (single column file titled "buried" and containing buried positions separated by rows")
access_df = pd.read_csv(inputaccess, sep = ",")
#access_df
## DF TO LIST
access = access_df["buried"]
#access
## LOOP TO EXTRACT access
z = []
for index, row in data.iterrows():
for ac in access:
y = "Accessible"
if int(ac) >= row["Start"] and int(ac) <= row["Start"] + row["Length"] - 1:
y = "Buried"
z.append(y)
break
if y == "Accessible":
z.append(y)
#print(z)
#len(z)
## APPEND GLYCOSILATION TO DF
data['accessibility_icm'] = z
#data
## EXPORT DATA
data.to_csv(path_or_buf= nameOutFile,
index = False) #index_label = "Rank")
### FINAL PRINT
print("Find your output file at: " + nameOutFile)