1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module containing functions for handling XEasy files."""
25
26
27
28 from lib.errors import RelaxError
29 from lib.io import strip
30
31
32 -def read_list(peak_list=None, file_data=None, int_col=None):
33 """Extract the peak intensity information from the XEasy file.
34
35 @keyword peak_list: The peak list object to place all data into.
36 @type peak_list: lib.spectrum.objects.Peak_list instance
37 @keyword file_data: The data extracted from the file converted into a list of lists.
38 @type file_data: list of lists of str
39 @keyword int_col: The column containing the peak intensity data (for a non-standard formatted file).
40 @type int_col: int
41 @raises RelaxError: When the expected peak intensity is not a float.
42 """
43
44
45 w1_col = 3
46 w2_col = 2
47 ass_w1_col = 7
48 ass_w2_col = 4
49 if int_col == None:
50 int_col = 10
51
52
53 num = 0
54 for line in file_data:
55
56 try:
57 intensity = float(line[int_col])
58 except ValueError:
59 num = num + 1
60 except IndexError:
61 num = num + 1
62 else:
63 break
64 print("Number of header lines found: " + repr(num))
65
66
67 file_data = file_data[num:]
68
69
70 file_data = strip(file_data)
71
72
73 for line in file_data:
74
75 if line[ass_w1_col] == 'inv.' or line[ass_w2_col] == 'inv.':
76 continue
77
78
79 try:
80 res_num = int(line[5])
81 except:
82 raise RelaxError("Improperly formatted XEasy file, cannot read the line %s." % line)
83
84
85 name1 = line[ass_w1_col]
86 name2 = line[ass_w2_col]
87
88
89 try:
90 w1 = float(line[w1_col])
91 except ValueError:
92 raise RelaxError("The w1 chemical shift from the line %s is invalid." % line)
93 try:
94 w2 = float(line[w2_col])
95 except ValueError:
96 raise RelaxError("The w2 chemical shift from the line %s is invalid." % line)
97
98
99 try:
100 intensity = float(line[int_col])
101 except ValueError:
102 raise RelaxError("The peak intensity value from the line %s is invalid." % line)
103
104
105 peak_list.add(res_nums=[res_num, res_num], spin_names=[name1, name2], shifts=[w1, w2], intensity=intensity)
106