Package biana :: Package BianaObjects :: Module BianaReport
[hide private]
[frames] | no frames]

Source Code for Module biana.BianaObjects.BianaReport

  1  """ 
  2      BIANA: Biologic Interactions and Network Analysis 
  3      Copyright (C) 2009  Javier Garcia-Garcia, Emre Guney, Baldo Oliva 
  4   
  5      This program is free software: you can redistribute it and/or modify 
  6      it under the terms of the GNU General Public License as published by 
  7      the Free Software Foundation, either version 3 of the License, or 
  8      (at your option) any later version. 
  9   
 10      This program is distributed in the hope that it will be useful, 
 11      but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13      GNU General Public License for more details. 
 14   
 15      You should have received a copy of the GNU General Public License 
 16      along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 17   
 18  """ 
 19   
 20  # Class to manage/handle (create, analyze, operate vs..) networks  
 21  # from userEntities and available interaction data in BianaDB (using BianaDBaccess)  
 22  import sys 
 23   
24 -class BianaReport(object):
25 """ 26 A class to control BIANA reports 27 28 29 """ 30
31 - def __init__(self, title="BIANA report", streamOutputMethod=sys.stdout.write, format="html", url=""):
32 """ 33 34 title is the title that will be written on top of the report (default is 'BIANA report') 35 36 streamOutputMethod is the write method where the report will be written (e.g. file_object.write) 37 --> if no streamOutputMethod is given, report is written to stdout 38 39 format is the formatting that will be applied to the report 40 - 'html': report in html 41 - 'txt': report in raw text 42 43 url is the web address where the interface to BIANA is placed 44 45 46 """ 47 48 self.outmethod = streamOutputMethod 49 50 self.format = format 51 52 53 if self.format == 'txt': 54 self.outmethod("\n%s\n-----------------------------------------\n" %title) 55 56 elif self.format == "html": 57 self.outmethod("<html>\n<head>\n<title>%s</title>\n</head>\n" %(title)) 58 self.outmethod("<body>") 59 60 # Print the headers of the page: Biana logo, Grib logo, etc etc 61 self.outmethod("""<table class="default" border="0" cellpadding="0" cellspacing="0" width="100%">""") 62 self.outmethod(""" <tbody>""") 63 self.outmethod("""<tr><td>""") 64 self.outmethod("""<a href='%s'><img src='%s/images/biana_logo.png' border=0><font size=0></a></td>""" %(url,url)) 65 66 67 self.outmethod("""<td class="links" align="center"> """) 68 69 self.outmethod("""<a href="http://sbi.imim.es/staff.html" onmouseover="window.status='Who is who in Structural Bioinformatics Research Laboratory';">People</a> &nbsp;<font style="color: rgb(0, 80, 80);">|</font>&nbsp;""") 70 71 self.outmethod("""<a href="http://sbi.imim.es/research.html" onmouseover="window.status='Research at our Group';">Research</a> &nbsp;<font style="color: rgb(0, 80, 80);">|</font>&nbsp;""") 72 73 self.outmethod("""<a href="http://sbi.imim.es/resources.html" onmouseover="window.status='Software developed in our Group';">Resources</a>&nbsp;<font style="color: rgb(0, 80, 80);">|</font>&nbsp;""") 74 75 self.outmethod("""<a href="http://sbi.imim.es/publications.html" onmouseover="window.status='Publications by our Group';">Publications</a> &nbsp;<font style="color: rgb(0, 80, 80);">|</font>&nbsp;""") 76 77 self.outmethod("""<a href="http://sbi.imim.es/links.html" onmouseover="window.status='Interesting Links';">Links</a> &nbsp;<font style="color: rgb(0, 80, 80);">|</font>&nbsp;""") 78 79 self.outmethod("""</td>""") 80 self.outmethod("""<td><a href='http://grib.imim.es'><img src='%s/images/grib_logo.jpg' border=0></a></td>""" %(url)) 81 self.outmethod("""<td><a href='http://sbi.imim.es'><img src='%s/images/logo_sbi.gif' border=0></a></td>""" %(url)) 82 self.outmethod(""" </tr>""") 83 self.outmethod(""" <tr><td class="links" align="center"></td></tr>""") 84 self.outmethod(""" </tbody></table>""") 85 86 self.outmethod(""" <table cellspacing=0 cellpadding=3 border=0 width=99%%>""") 87 self.outmethod(""" <tr bgcolor="#eeedcd"><td></td></tr>""") 88 self.outmethod(""" </table>""") 89 90 # Print title of the report 91 self.outmethod("<br><br><center><table border=0 style='border: 0;border-collapse: collapse;background-color:#CCCCFF;width: 600px;cellpadding=20'><tr><td style='padding:5px'><p style='text-align:center;font-weight: bold;color: #330066;font: 18px arial, sans-serif;'>%s</p></td></tr></table></center>\n" %(title)) 92 93 self.outmethod("<center><table border=0 style='border: 0;border-collapse: collapse;background-color:#CCCCCC;width: 600px;cellpadding=20'><tr><td style='padding:5px'>\n") 94 95 96 return
97 98
99 - def closeReport(self, streamOutputMethod=sys.stdout.write, format="html"):
100 """ 101 102 Closes the Biana report. This method is in charge of writing the closing HTML tags of the report 103 104 "reportOutputMethod" is the write method where the report will be written (e.g. file_object.write) 105 --> if no streamOutputMethod is given, report is written to stdout 106 107 "reportFormat" is the formatting that will be applied to the report 108 - 'html': report in html 109 - 'txt': report in raw text 110 111 Attention!!! This method does not close the file object associated to the report. The user is responsible 112 for closing the file (if needed). 113 114 """ 115 if self.format == 'txt': 116 self.outmethod("\n") 117 118 elif self.format == "html": 119 self.outmethod("</td></tr></table></center>\n </body>\n</html>\n") 120 121 # END OF elif self.format == "html": 122 123 124 125 return
126 127
128 - def addText(self, theText=None, type="regular" ):
129 """ 130 This method adds text to the report. 131 132 Depending on the 'type' of text, it will be written one way or another 133 134 - 'regular' prints standard text 135 - 'title' prints a section title 136 137 """ 138 if self.format == 'txt': 139 140 if type=="regular": 141 self.outmethod("%s\n" %theText) 142 elif type =="title": 143 self.outmethod("%s\n\n" %(theText.upper())) 144 145 elif self.format == "html": 146 147 if type=="regular": 148 self.outmethod("%s\n" %(theText)) 149 elif type =="title": 150 self.outmethod("<h2>%s</h2>\n" %(theText)) 151 152 # END OF elif self.format == "html": 153 154 155 156 return
157 158
159 - def addResult(self, resultFileName=None, resultFilePath=None, associatedText=None, bulletedList=[] ):
160 """ 161 This method adds information to the resport about a result file. 162 163 'resultFileName' is the name you want to give to this result file 164 165 'resultFilePath' is the path (or URL) of the result file (e.g. http://localhost/this_file.html 166 167 'associatedText' is the text shown next to the results file name (i.e description of the file) 168 169 'bulletedList' is a list of strings that will be shown under the results name as a bulleted list 170 171 """ 172 if self.format == 'txt': 173 self.outmethod("==> %s: %s\n" %(resultFileName, associatedText)) 174 self.outmethod(" - located in %s\n" %(resultFilePath)) 175 176 for one_associatedText in associatedText: 177 self.outmethod(" - %s" %(associatedText)) 178 179 elif self.format == "html": 180 self.outmethod("<li><p style='text-align:left;font-weight: bold;color: #000000;font: 14px arial, sans-serif;'><a href='%s'>%s</a>: %s</p></li>\n\n" %(resultFilePath, resultFileName, associatedText)) 181 182 if bulletedList: 183 self.outmethod("<ul>\n") 184 for one_item in bulletedList: 185 self.outmethod("<li>%s</li>\n" %(one_item)) 186 self.outmethod("</ul>\n") 187 188 # END OF elif self.format == "html": 189 190 return
191