added parse LibInfo by FlowcellId and count reads. This allows us to report data...
authorRami Rauch <rrauch@stanford.edu>
Thu, 23 Apr 2009 22:44:13 +0000 (22:44 +0000)
committerRami Rauch <rrauch@stanford.edu>
Thu, 23 Apr 2009 22:44:13 +0000 (22:44 +0000)
htswfrontend/htswfrontend/htsw_reports/libinfopar.py

index 672af8468f36e9404da3034ecddad9815d84e95d..6d468806bf0f4852daf23345478ac42df5724c3b 100644 (file)
@@ -18,7 +18,6 @@ Example library node from LibraryInfo.xml:
 </Library>
 '''
 class LibInfoHandler(ContentHandler):
-
   def __init__ (self, searchTerm):
     self.searchTerm= searchTerm
     self.currlibid = ''
@@ -32,8 +31,6 @@ class LibInfoHandler(ContentHandler):
       elif name == 'Track' and self.searchTerm == self.currlibid:
         self.LanesCount += len(attrs.get('Lane',""))
         self.ReadsCount += int(attrs.get('Count',""))
-      #else:
-      #  self.Msg += ' | name = '+name+', currlibid = '+ self.currlibid
     except: 
       self.Msg = 'failed parsing xml file'
     return
@@ -44,14 +41,35 @@ class LibInfoHandler(ContentHandler):
   #def endElement(self, name):
     # return ..
 
+class LibInfoHandlerByFlowCell(ContentHandler):
+  def __init__ (self, searchTerm):
+    self.searchTerm = searchTerm
+    self.LanesCount, self.ReadsCount = 0, 0
+    self.Msg = 'OK'
+
+  def startElement(self, name, attrs):
+    try:
+      if name == 'Track' and attrs.get('Flowcell',"") == self.searchTerm:
+        self.LanesCount += len(attrs.get('Lane',""))
+        self.ReadsCount += int(attrs.get('Count',""))
+    except:
+      self.Msg = 'failed parsing xml file'
+    return
+
 
 ## TO DO: Change this to read the LibraryInfo.xml only ONCE per ReoprtRequest (do it in the models.py). + Read it directly from the analysis_server
 
-def getLibReads(libid):
-  searchTerm= libid
-  parser = make_parser()   
-  curHandler = LibInfoHandler(searchTerm)
+def getLibReads(search_term,search_by):
+  searchTerm= search_term
+  parser = make_parser() 
+
+  if search_by == 'ByLib':  
+    curHandler = LibInfoHandler(searchTerm)
+  elif search_by == 'ByFC':
+    curHandler = LibInfoHandlerByFlowCell(searchTerm)
+
   parser.setContentHandler(curHandler)
+
   folder_loc = '/htsworkflow/htswfrontend/htswfrontend'  # DEV
   #folder_loc = '/Library/WebServer/gaworkflow/gaworkflow/frontend'  # PROD
   parser.parse(open(folder_loc+'/htsw_reports/LibInfo/LibraryInfo.xml'))