def createTaskHtml(self, tags, htmlLink=None): """ Create html file for the task Arg: tags: dict with the following keys to parse the html template subject, taskInfo, taskName, parseHtmlTables, parseVersionTables Script fills missing keys """ versions = '' if self.getName() == 'qa': print self.logDir print self.get('general', 'versions_file_name') versions = minidom.parse( os.path.join(self.logDir, self.get('general', 'versions_file_name'))) versions = versions.toprettyxml() if htmlLink == None: htmlLink = self.qaHtml # Fill missing keys baseTags = { 'jqueryFile': self.config.get('qa', 'jquery'), 'subject': self.subject.getName(), 'taskName': self.getName(), 'taskInfo': '', 'parseHtmlTables': '', 'parseVersionTables': versions, } for key, value in baseTags.iteritems(): if not tags.has_key(key): tags[key] = value # Parse template and create html file htmlCode = self.parseTemplate(tags, self.qaHtmlTemplate) util.createScript(htmlLink, htmlCode)
def createTaskHtml(self, tags, htmlLink=None): """ Create html file for the task Arg: tags: dict with the following keys to parse the html template subject, taskInfo, taskName, parseHtmlTables, parseVersionTables Script fills missing keys """ versions = minidom.parse(os.path.join( self.logDir, self.get('general','versions_file_name'))) if htmlLink == None: htmlLink = self.qaHtml # Fill missing keys baseTags = { 'jqueryFile': self.config.get('qa', 'jquery'), 'subject': self.subject.getName(), 'taskName': self.getName(), 'taskInfo': '', 'parseHtmlTables': '', 'parseVersionTables': versions.toprettyxml() } for key, value in baseTags.iteritems(): if not tags.has_key(key): tags[key] = value # Parse template and create html file htmlCode = self.parseTemplate(tags, self.qaHtmlTemplate) util.createScript(htmlLink, htmlCode)
def __createSegmentationScript(self, source, options): """Create a file which contains all necessary instruction to launch a segmentation with spm Args: source: the input image file name options: an array of nine integer elements representing Boolean. See config.cfg for the meaning of the elements Returns: The resulting script file name """ scriptName = os.path.join( self.workingDir, os.path.basename(source).replace(".nii", ".m")) self.info("Creating spm segmentation script {}".format(scriptName)) tags = { 'source': source, 'gm1': options[0], 'gm2': options[1], 'gm3': options[2], 'csf1': options[3], 'csf2': options[4], 'csf3': options[5], 'wm1': options[6], 'wm2': options[7], 'wm3': options[8] } template = self.parseTemplate( tags, os.path.join(self.toadDir, "templates/files/segment.tpl")) util.createScript(scriptName, template) return scriptName
def createQaReport(self, images): """create html report for a task with qaSupplier implemented Args: images : an Images object """ mainTemplate = os.path.join(self.qaDir, self.get('qa', 'subject_template')) tableTemplate = os.path.join(self.toadDir, 'templates', 'files', 'qa.table.tpl') taskInfo = images.getInformation() imagesDir = os.path.join(self.qaDir, self.config.get('qa', 'images_dir')) tablesCode = '' print "createQaReport images =", images for imageLink, legend in images: if imageLink: path, filename = os.path.split(imageLink) classType = 'large_view' if any(_ in filename for _ in ['_translations', '_rotations', '_vectors', '_sigma']): classType = 'small_view' shutil.copyfile(imageLink, os.path.join(imagesDir, filename)) relativeLink = os.path.join(self.config.get('qa', 'images_dir'), filename) tags = { 'imageLink':relativeLink, 'legend':legend, 'class':classType, } tablesCode += self.parseTemplate(tags, tableTemplate) else: tags = {'imageLink':'', 'legend':legend} tablesCode += self.parseTemplate(tags, tableTemplate) tags = {'taskInfo':taskInfo,'parseHtmlTables':tablesCode} htmlCode = self.parseTemplate(tags, mainTemplate) htmlFile = os.path.join(self.qaDir,'{}.html'.format(self.getName())) util.createScript(htmlFile, htmlCode)
def __createLpcaScript(self, source, target): scriptName = os.path.join(self.workingDir, "{}.m".format(self.get("script_name"))) self.info("Creating denoising script {}".format(scriptName)) tags = { 'source': source, 'target': target, 'workingDir': self.workingDir, 'beta': self.get('beta'), 'rician': self.get('rician'), 'nbthreads': self.getNTreads() } if self.get("algorithm") == "aonlm": template = self.parseTemplate( tags, os.path.join(self.toadDir, "templates/files/denoise_aonlm.tpl")) else: template = self.parseTemplate( tags, os.path.join(self.toadDir, "templates/files/denoise_lpca.tpl")) util.createScript(scriptName, template) return scriptName
def createMethoHtml(self): templateDir = os.path.join(self.toadDir, 'templates', 'files') jinja2Env = Environment(loader=FileSystemLoader(templateDir), trim_blocks=True) tpl = jinja2Env.get_template('metho.tpl') tags_softwares = self.__getVersions() tags_metho = self.__getTags(tags_softwares) # print tags_metho htmlCode = tpl.render(**tags_metho) util.createScript(os.path.join(self.qaDir, 'metho.html'), htmlCode)
def createMethoHtml(self): templateDir = os.path.join(self.toadDir, 'templates', 'files') jinja2Env = Environment( loader=FileSystemLoader(templateDir), trim_blocks=True) tpl = jinja2Env.get_template('metho.tpl') tags_softwares = self.__getVersions() tags_metho = self.__getTags(tags_softwares) # print tags_metho htmlCode = tpl.render(**tags_metho) util.createScript(os.path.join(self.qaDir,'metho.html'), htmlCode)
def __createIndexFile(self, dimensions): """Create the file that will contain the index Args: dimensions: the number of direction into the B0 images Returns: The resulting file name """ target = os.path.join(self.workingDir, self.get('index_filename')) self.info("Creating index file {}".format(target)) text = "" for i in range(0, dimensions): text += "1 " util.createScript(target, text) return target
def __createLpcaScript(self, source, target): scriptName = os.path.join(self.workingDir, "{}.m".format(self.get("script_name"))) self.info("Creating denoising script {}".format(scriptName)) tags={ 'source': source, 'target':target, 'workingDir': self.workingDir, 'beta': self.get('beta'), 'rician': self.get('rician'), 'nbthreads': self.getNTreads()} if self.get("algorithm") == "aonlm": template = self.parseTemplate(tags, os.path.join(self.toadDir, "templates/files/denoise_aonlm.tpl")) else: template = self.parseTemplate(tags, os.path.join(self.toadDir, "templates/files/denoise_lpca.tpl")) util.createScript(scriptName, template) return scriptName
def __createAcquisitionParameterFile(self, type): """Create the acquire parameter (--acqp) file for topup or eddy For topup, the image will concatenate b0AP first then b0PA #A>>P, 0 -1 0 #P>>A, 0 1 0 #R>>L, 1 0 0 #L>>R, -1 0 0 Args: type: algorithm this file is create for. Valid value are: topup, eddy Returns: the acquisition parameter file name """ try: phaseEncDir = int(self.get('phase_enc_dir')) except ValueError: self.error("Cannot determine the phase encoding direction") try: echoSpacing = float(self.get('echo_spacing')) epiFactor = float(self.get('epi_factor')) factor = (epiFactor - 1) * (echoSpacing / 1000) except ValueError: self.warning("Cannot find suitable Echo Spacing value, will use a factor of 0.1") factor = "0.1" if type == 'topup': parameter = 'acqp_topup' text = "" for nDim in range(self.dimB0s[0]): text += "0 1 0 {}\n".format(factor) for nDim in range(self.dimB0s[1]): text += "0 -1 0 {}\n".format(factor) elif type == 'eddy': parameter = 'acqp_eddy' text = "0 1 0 {}\n".format(factor) else: self.error("Type must be of value: topup or eddy") return False target = os.path.join(self.workingDir, self.get(parameter)) if not util.createScript(target, text): self.error("Unable to create script {}".format(target)) return target
def __createSegmentationScript(self, source, options): """Create a file which contains all necessary instruction to launch a segmentation with spm Args: source: the input image file name options: an array of nine integer elements representing Boolean. See config.cfg for the meaning of the elements Returns: The resulting script file name """ scriptName = os.path.join(self.workingDir, os.path.basename(source).replace(".nii",".m")) self.info("Creating spm segmentation script {}".format(scriptName)) tags={ 'source': source, 'gm1': options[0], 'gm2': options[1], 'gm3': options[2], 'csf1': options[3], 'csf2': options[4], 'csf3': options[5], 'wm1': options[6], 'wm2': options[7], 'wm3': options[8]} template = self.parseTemplate(tags, os.path.join(self.toadDir, "templates/files/segment.tpl")) util.createScript(scriptName, template) return scriptName
def __createAcquisitionParameterFile(self, type): """Create the acquire parameter (--acqp) file for topup or eddy For topup, the image is always concatenate b0AP first then b0PA #A>>P, 0 -1 0 #P>>A, 0 1 0 #R>>L, 1 0 0 #L>>R, -1 0 0 Args: type: algorithm this file is create for. Valid value are: topup, eddy Returns: the acquisition parameter file name """ try: phaseEncDir = int(self.get('phase_enc_dir')) except ValueError: self.error("Cannot determine the phase encoding direction") try: echoSpacing = float(self.get('echo_spacing')) epiFactor = int(self.get('epi_factor')) factor = (epiFactor-1) * (echoSpacing/1000) except ValueError: self.warning("Cannot find suitable Echo Spacing value, will use a factor of 0.1") factor = "0.1" if type=='topup': parameter='acqp_topup' text = "0 -1 0 {}\n0 1 0 {}\n".format(factor, factor) elif type=='eddy': parameter='acqp_eddy' if phaseEncDir==0: #P>>A text = "0 1 0 {}\n".format(factor) elif phaseEncDir==1: #A>>P text = "0 -1 0 {}\n".format(factor) else: self.error("Cannot determine the phase encoding direction, got value of: {}".format(phaseEncDir)) else: self.error("Type must be of value: topup or eddy") return False target = os.path.join(self.workingDir, self.get(parameter)) if not util.createScript(target, text): self.error("Unable to create script {}".format(target)) return target
def implement(self): mainTemplate = os.path.join(self.toadDir, 'templates', 'files', 'qa.main.tpl') imagesDir = os.path.join(self.workingDir, self.get('qa', 'images_dir')) if not os.path.exists(imagesDir): os.makedirs(imagesDir) #Copy style.css styleTemplate = os.path.join(self.toadDir, 'templates', 'files', 'qa.style.tpl') util.copy(styleTemplate, self.workingDir, 'style.css') #Create menu.html only for tasks with implemented QA menuTemplate = os.path.join(self.toadDir, 'templates', 'files', 'qa.menu.tpl') util.copy(menuTemplate, self.workingDir, 'menu.html') #Create index.html tags = { 'subject':self.__subject.getName(), 'taskInfo':'', 'parseHtmlTables':'', } htmlCode = self.parseTemplate(tags, mainTemplate) util.createScript('index.html', htmlCode)
def implement(self): mainTemplate = os.path.join(self.toadDir, 'templates', 'files', 'qa.main.tpl') imagesDir = os.path.join(self.workingDir, self.get('qa', 'images_dir')) if not os.path.exists(imagesDir): os.makedirs(imagesDir) #Create menu links only for tasks with implemented QA menuHtml = "" menuLinkTemplate = "\n<li><a id=\"{0}\" href=\"{0}.html\">{0}</a></li>" qaTasksList = [] for task in sorted(self.tasksAsReferences): if "qaSupplier" in dir(task): qaTasksList.append(task.getName()) for taskName in qaTasksList: menuHtml += menuLinkTemplate.format(taskName) #Create temporary html for each task message = "Task is being processed. Refresh to check completion." for taskName in qaTasksList: htmlTaskFileName = "{}.html".format(taskName) if not os.path.exists(htmlTaskFileName): tags = { 'subject':self.__subject.getName(), 'menuHtml':menuHtml, 'taskInfo':'', 'parseHtmlTables':message, } htmlCode = self.parseTemplate(tags, mainTemplate) util.createScript(htmlTaskFileName, htmlCode) #Create template specific to the subject tags = { 'subject':self.__subject.getName(), 'menuHtml':menuHtml, } htmlCode = self.parseTemplate(tags, mainTemplate) util.createScript(self.get('qa', 'subject_template'), htmlCode) #Create index.html tags = { 'subject':self.__subject.getName(), 'menuHtml':menuHtml, 'taskInfo':'', 'parseHtmlTables':'', } htmlCode = self.parseTemplate(tags, mainTemplate) util.createScript('index.html', htmlCode)