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 """Module containing functions for handling XEasy files."""
26
27
28
29 from warnings import warn
30
31
32 from lib.errors import RelaxError
33 from lib.io import strip
34 from lib.warnings import RelaxWarning
35
36
37 -def read_list(peak_list=None, file_data=None, int_col=None):
38 """Extract the peak intensity information from the XEasy file.
39
40 @keyword peak_list: The peak list object to place all data into.
41 @type peak_list: lib.spectrum.objects.Peak_list instance
42 @keyword file_data: The data extracted from the file converted into a list of lists.
43 @type file_data: list of lists of str
44 @keyword int_col: The column containing the peak intensity data (for a non-standard formatted file).
45 @type int_col: int
46 @raises RelaxError: When the expected peak intensity is not a float.
47 """
48
49
50 w1_col = 3
51 w2_col = 2
52 ass_w1_col = 7
53 ass_w2_col = 4
54 res_name1_col = 9
55 res_name2_col = 5
56 if int_col == None:
57 int_col = 10
58
59
60 num = 0
61 for line in file_data:
62
63 try:
64 intensity = float(line[int_col])
65 except ValueError:
66 num = num + 1
67 except IndexError:
68 num = num + 1
69 else:
70 break
71 print("Number of header lines found: " + repr(num))
72
73
74 file_data = file_data[num:]
75
76
77 file_data = strip(file_data)
78
79
80 for line in file_data:
81
82 if line[ass_w1_col] == 'inv.' or line[ass_w2_col] == 'inv.':
83 continue
84
85
86 try:
87 res_num1 = int(line[8])
88 except:
89 raise RelaxError("Improperly formatted XEasy file, cannot process the residue number for dimension 1 in assignment: %s." % line)
90
91
92 try:
93 res_num2 = int(line[5])
94 except:
95 warn(RelaxWarning("Improperly formatted XEasy file, cannot process the residue number for dimension 2 in assignment: %s. Setting residue number to None." % line))
96 res_num2 = None
97
98
99 name1 = line[ass_w1_col]
100 name2 = line[ass_w2_col]
101
102
103 res_name1 = line[res_name1_col]
104 res_name2 = line[res_name2_col]
105
106
107 try:
108 w1 = float(line[w1_col])
109 except ValueError:
110 raise RelaxError("The w1 chemical shift from the line %s is invalid." % line)
111 try:
112 w2 = float(line[w2_col])
113 except ValueError:
114 raise RelaxError("The w2 chemical shift from the line %s is invalid." % line)
115
116
117 try:
118 intensity = float(line[int_col])
119 except ValueError:
120 raise RelaxError("The peak intensity value from the line %s is invalid." % line)
121
122
123 peak_list.add(res_nums=[res_num1, res_num2], res_names=[res_name1, res_name2], spin_names=[name1, name2], shifts=[w1, w2], intensity=intensity)
124