-
Notifications
You must be signed in to change notification settings - Fork 1
/
xp_vpCollector.py
executable file
·171 lines (142 loc) · 5.32 KB
/
xp_vpCollector.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import pdb
import math
import sys
import getopt
import stats
import sanxot
import os
from time import strftime
import pprint
def X_VpCollector(dataFiles,relationsFile):
#w=open("m_peptideMwoQ2proteins_relations.txt","w")
mod=[]
dic={}
for line1 in open(dataFiles):
if line1!="\n":
splits1=line1.split("\t")
seqData=splits1[0].strip()
#pdb.set_trace()
xp=splits1[1].strip()
vp=splits1[2].strip()
if seqData not in dic:
dic[seqData]=[xp,vp]
#file1=open("R_peptide2proteins_relations_peptideMwoQ2proteins_relations.txt")
for line in open(relationsFile):
if line!="\n":
splits=line.split("\t")
seq=splits[1].strip()
# pdb.set_trace()
for s in dic:
if seq ==s:
x=dic[seq][0]
v=dic[seq][1]
mod.append([str(seq), x,v])
return mod
##########
def printHelp(version=None, advanced=False):
print """%s
As the name suggest, this programme collects the Xp Vp values from data file
for any given relation files.
For example:
-h, --help Display this help and exit.
-a, --analysis=string
Use a prefix for the output files. If this is not
provided, then the prefix will be garnered from the data
file.
-o, --outputfile=string
The new outstasts file containing ALL peptides.
-r, --relfile=string
The SanXoT relations file for peptides to proteins.
-d, --dataFile=string
The SanXoT logFile containing the variance of an
integration from NONMODIFIED peptide to PROTEIN.
-p, --place, --folder=foldername
To use a different common folder for the output files.
If this is not provided, the the folder used will be the
same as the input folder.
""" % version
#-------------------------------------------------------
def main(argv):
version = "v0.01"
analysisName = ""
analysisFolder = ""
relationsFile = ""
dataFiles = ""
outputFile = ""
defaultOutput = "OutStats"
defaultOutputInfo = "infoFile"
defaultRelationsFile = "rels"
defaultDataFiles = "datafile"
defaultTableExtension = ".xls"
defaultTextExtension = ".txt"
defaultGraphExtension = ".png"
defaultAnalysisName = "xpvpAnalysis"
infoFile = ""
logList = [["XVpCollector " + version], ["Start: " + strftime("%Y-%m-%d %H:%M:%S")]]
try:
opts, args = getopt.getopt(argv, "a:p:r:o:d:h",
["analysis=", "folder=", "relfile=", "outputfile=", "dataFile=", "help"])
except getopt.GetoptError:
logList.append(["Error while getting parameters."])
stats.saveFile(infoFile, logList, "INFO FILE")
sys.exit(2)
if len(opts) == 0:
printHelp(version)
sys.exit()
for opt, arg in opts:
if opt in ("-a", "--analysis"):
analysisName = arg
if opt in ("-p", "--place", "--folder"):
analysisFolder = arg
if opt in ("-r", "--relfile"):
relationsFile = arg
if opt in ("-o", "--outputfile"):
outputFile = arg
if opt in ("-d", "--dataFile"):
dataFiles = arg
elif opt in ("-h", "--help"):
printHelp(version)
# REGION: FILE NAMES SETUP
if len(analysisName) == 0:
if len(dataFiles) > 0:
analysisName = os.path.splitext(os.path.basename(dataFiles))[0]
else:
analysisName = defaultAnalysisName
if len(os.path.dirname(analysisName)) > 0:
analysisNameFirstPart = os.path.dirname(analysisName)
analysisName = os.path.basename(analysisName)
if len(analysisFolder) == 0:
analysisFolder = analysisNameFirstPart
if len(dataFiles) > 0 and len(analysisFolder) == 0:
if len(os.path.dirname(dataFiles)) > 0:
analysisFolder = os.path.dirname(dataFiles)
# input
if len(dataFiles) == 0:
dataFiles = os.path.join(analysisFolder, analysisName + "_" + defaultDataFiles + defaultTableExtension)
if len(os.path.dirname(dataFiles)) == 0 and len(analysisFolder) > 0:
dataFiles = os.path.join(analysisFolder, dataFiles)
if len(relationsFile) == 0:
relationsFile = os.path.join(analysisFolder, analysisName + "_" + defaultRelationsFile + defaultTableExtension)
if len(os.path.dirname(relationsFile)) == 0 and len(analysisFolder) > 0:
relationsFile = os.path.join(analysisFolder, relationsFile)
# output
if len(outputFile) == 0:
outputFile = os.path.join(analysisFolder, analysisName + "_" + defaultOutput + defaultTableExtension)
else:
if len(os.path.dirname(outputFile)) == 0:
outputFile = os.path.join(analysisFolder, outputFile)
if len(infoFile) == 0:
infoFile = os.path.join(analysisFolder, analysisName + "_" + defaultOutputInfo + defaultTableExtension)
logList.append(["Input dataFiles " + str(dataFiles)])
logList.append(["Input relations file: " + relationsFile])
logList.append(["Input dataFile: " + dataFiles])
logList.append(["Output stats file: " + outputFile])
logList.append(["Output info file: " + infoFile])
outputList = X_VpCollector(dataFiles=dataFiles,relationsFile=relationsFile)
header = "idsup\tX'sup,\t,V'sup" #"Sequence\tFASTAProteinDescription\tXp\tVp\tcount\tZp" "idsup\tX'sup,\t,V'sup"
#######("Fix the header for Xp and Vp")
stats.saveFile(outputFile, outputList, header)
if len(infoFile) > 0:
stats.saveFile(infoFile, logList, "INFO FILE")
if __name__ == "__main__":
main(sys.argv[1:])