-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunParametersParser.py
More file actions
58 lines (51 loc) · 2.11 KB
/
RunParametersParser.py
File metadata and controls
58 lines (51 loc) · 2.11 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
'''
Created on 3 Nov 2015
@author: Sara
'''
class RunParametersParser(object):
'''
A series of methods to parse the runParameters file generated by Illumina sequencing instruments
'''
def __init__(self,filename): #,identifier
'''
In this method initial values for the internal data are created. The instance variables.
This is within the namespace of the class.
'''
#RunParameters
import xml.etree.ElementTree as ET
tree = ET.parse(filename)
root = tree.getroot()
self.tree = tree
self.root = root
#self.locate = identifier
def retrieveRPData(self,identifier):
#print self.locate
return (self.root.find(identifier).text)
def retrieveNestedRPData(self,outer_identifier,identifier):
#print self.locate
#Sometimes there is no serial number for the flow cell (strange) in the runparameters file- causes an error, need to handle this
#Return an empty string where there is no data in the runparameters file
try:
return (self.root.find(outer_identifier).find(identifier).text)
except:
return ' '
def returnElementInfo(self,identifier,subelm1,subelm2,subelm3):
'''
This is a bit specialised for the Reads circumstance, because of the Y,N becoming 1,0 for the database.
Could fix later if required
'''
ident = self.root.find(identifier)
ident_list = []
for subelement in ident:
ident_list.append(subelement.attrib.get(subelm1))
if (subelement.attrib.get(subelm2)) == 'Y':
ident_list.append('1')
elif (subelement.attrib.get(subelm2)) == 'N':
ident_list.append('0')
else:
raise Exception("Problem with subelement2")
ident_list.append(subelement.attrib.get(subelm3))
return ident_list
def getNumSubelements(self,identifier):
reads = self.root.find(identifier)
return len(reads) #No need to iterate through as this works just as well