diff options
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/auwerx/phewas_analysis.py | 39 | ||||
-rw-r--r-- | wqflask/wqflask/templates/phewas_analysis.html | 8 |
2 files changed, 38 insertions, 9 deletions
diff --git a/wqflask/wqflask/auwerx/phewas_analysis.py b/wqflask/wqflask/auwerx/phewas_analysis.py index 061d2bc8..db12ad98 100644 --- a/wqflask/wqflask/auwerx/phewas_analysis.py +++ b/wqflask/wqflask/auwerx/phewas_analysis.py @@ -23,24 +23,24 @@ from utility.tools import locate r_library = ro.r["library"] # Map the library function r_options = ro.r["options"] # Map the options function -r_load = ro.r["load"] # Map the load function r_write_table = ro.r["write.table"] # Map the write.table function r_head = ro.r["head"] # Map the head function +r_load = ro.r["load"] # Map the head function r_colnames = ro.r["colnames"] # Map the colnames function r_list = ro.r["list"] # Map the list function r_c = ro.r["c"] # Map the c (combine) function -r_rep = ro.r["rep"] # Map the rep (repeat) function +r_seq = ro.r["seq"] # Map the rep (repeat) function class PheWAS(object): def __init__(self): print("Initialization of PheWAS") # TODO: Loading the package should only be done once, since it is quite expensive print(r_library("auwerx")) # Load the auwerx package - self.r_download_BXD_geno = ro.r["download.BXD.geno"] # Map the create.Pheno_aligner function self.r_create_Pheno_aligner = ro.r["create.Pheno_aligner"] # Map the create.Pheno_aligner function - self.r_create_SNP_aligner = ro.r["create.SNP_aligner"] # Map the create.SNP_aligner function self.r_calculate_all_pvalue_parallel = ro.r["calculate.all.pvalue.parallel"] # Map the calculate.all.pvalue.parallel function self.r_PheWASManhattan = ro.r["PheWASManhattan"] # Map the PheWASManhattan function + self.r_Stop = ro.r["throwStopError"] # Map the PheWASManhattan function + self.r_PyLoadData = ro.r["PyLoadData"] # Map the load function print("Initialization of PheWAS done !") def run_analysis(self, requestform): @@ -56,23 +56,46 @@ class PheWAS(object): snpinfo.append(marker["chr"]); snpinfo.append(marker["Mb"]); - rnames = r_rep(1, len(parser.markers)) + rnames = r_seq(1, len(parser.markers)) # Create the snp aligner object out of the BXD genotypes snpaligner = ro.r.matrix(snpinfo, nrow=len(parser.markers), dimnames = r_list(rnames, r_c("SNP", "Chr", "Pos")), ncol = 3, byrow=True) + r_write_table(snpaligner, "~/snpaligner_GN2.txt", row_names=False) + # Create the phenotype aligner object using R phenoaligner = self.r_create_Pheno_aligner() - r_load(precompfilelocation) # Load the pre-computed EMMA results into R - allpvalues = ro.r['pval_all'] # Get a pointer to the pre-computed results + #r_load(precompfilelocation) # Load the pre-computed EMMA results into R + #allpvalues = ro.r['pval_small'] # Get a pointer to the pre-computed results + self.results = {} + self.results['imgurl1'] = webqtlUtil.genRandStr("phewas_") + ".png" + self.results['imgloc1'] = GENERATED_IMAGE_DIR + self.results['imgurl1'] + print("IMAGE AT:", self.results['imgurl1'] ) + print("IMAGE AT:", self.results['imgloc1'] ) # Create the PheWAS plot (The gene/probe name, chromosome and gene/probe positions should come from the user input) # TODO: generate the PDF in the temp folder, with a unique name - self.r_PheWASManhattan("1:25", allpvalues, phenoaligner, snpaligner, "1:25", 1, 25, 25 ) + self.r_PheWASManhattan("Test", precompfilelocation, phenoaligner, snpaligner, "None", 1, 25, 25, self.results['imgloc1'] ) + #self.r_PheWASManhattan(allpvalues) + #self.r_Stop() + print("Initialization of PheWAS done !") + def loadImage(self, path, name): + print("pre-loading imgage results:", self.results[path]) + imgfile = open(self.results[path], 'rb') + imgdata = imgfile.read() + imgB64 = imgdata.encode("base64") + bytesarray = array.array('B', imgB64) + self.results[name] = bytesarray + + def render_image(self, results): + self.loadImage("imgloc1", "imgdata1") + def process_results(self, results): print("Processing PheWAS output") # TODO: get the PDF in the temp folder, and display it to the user template_vars = {} + template_vars["results"] = self.results + self.render_image(self.results) return(dict(template_vars)) diff --git a/wqflask/wqflask/templates/phewas_analysis.html b/wqflask/wqflask/templates/phewas_analysis.html index 2b04d85b..f72564ae 100644 --- a/wqflask/wqflask/templates/phewas_analysis.html +++ b/wqflask/wqflask/templates/phewas_analysis.html @@ -4,6 +4,12 @@ {% block content %} <!-- Start of body --> <div class="container"> <h1>PheWAS analysis results</h1> - YAY ! We have our own route + YAY ! We have our own route<br> + <a href="/tmp/{{ results['imgurl1'] }}"> + <img alt="Embedded Image" src="data:image/png;base64, + {% for elem in results['imgdata1'] -%} + {% print("%c"|format(elem)) %} + {%- endfor %} + " /></a> </div> {% endblock %} |