diff options
Diffstat (limited to 'wqflask')
4 files changed, 56 insertions, 25 deletions
diff --git a/wqflask/wqflask/marker_regression/marker_regression.py b/wqflask/wqflask/marker_regression/marker_regression.py index db92e14c..8fb1d841 100755 --- a/wqflask/wqflask/marker_regression/marker_regression.py +++ b/wqflask/wqflask/marker_regression/marker_regression.py @@ -82,6 +82,10 @@ class MarkerRegression(object): else: self.num_perm = start_vars['num_perm'] self.control = start_vars['control_marker'] + print("StartVars:", start_vars) + self.method = start_vars['mapmethod_rqtl_geno'] + self.model = start_vars['mapmodel_rqtl_geno'] + if start_vars['pair_scan'] == "true": self.pair_scan = True @@ -240,7 +244,7 @@ class MarkerRegression(object): count, p_values = self.parse_rqtl_output(plink_output_filename) def geno_to_rqtl_function(self): # TODO: Need to figure out why some genofiles have the wrong format and don't convert properly - print("Adding a function to the R environment") + print("Adding some custom helper functions to the R environment") ro.r(""" trim <- function( x ) { gsub("(^[[:space:]]+|[[:space:]]+$)", "", x) } @@ -250,7 +254,7 @@ class MarkerRegression(object): } GENOtoCSVR <- function(genotypes = 'BXD.geno', out = 'cross.csvr', phenotype = NULL, sex = NULL, verbose = FALSE){ - header = readLines(genotypes, 40) + header = readLines(genotypes, 40) # Assume a geno header is not longer than 40 lines toskip = which(unlist(lapply(header, function(x){ length(grep("Chr\t", x)) })) == 1)-1 # Major hack to skip the geno headers genocodes <- c(getGenoCode(header, 'mat'), getGenoCode(header, 'het'), getGenoCode(header, 'pat')) # Get the genotype codes @@ -264,9 +268,9 @@ class MarkerRegression(object): cbind(genodata[,c('Locus','Chr', 'cM')], genodata[, 5:ncol(genodata)])) # Genotypes write.table(outCSVR, file = out, row.names=FALSE, col.names=FALSE,quote=FALSE, sep=',') # Save it to a file require(qtl) - cross = read.cross(file=out, 'csvr', genotypes=genocodes) - if(type == 'riset') cross <- convert2riself(cross) - return(cross) # Load it using R/qtl read.cross + cross = read.cross(file=out, 'csvr', genotypes=genocodes) # Load the created cross file using R/qtl read.cross + if(type == 'riset') cross <- convert2riself(cross) # If its a RIL, convert to a RIL in R/qtl + return(cross) } """) @@ -276,11 +280,11 @@ class MarkerRegression(object): self.geno_to_rqtl_function() ## Get pointers to some common R functions - r_library = ro.r["library"] # Map the library function - r_c = ro.r["c"] # Map the c function - r_sum = ro.r["sum"] # Map the ncol function + r_library = ro.r["library"] # Map the library function + r_c = ro.r["c"] # Map the c function + r_sum = ro.r["sum"] # Map the sum function - print(r_library("qtl")) # Load R/qtl + print(r_library("qtl")) # Load R/qtl ## Get pointers to some R/qtl functions scanone = ro.r["scanone"] # Map the scanone function @@ -295,7 +299,7 @@ class MarkerRegression(object): print("Conversion of geno to cross at location:", genofilelocation, " to ", crossfilelocation) - cross_object = GENOtoCSVR(genofilelocation, crossfilelocation) # TODO: Add the SEX if that is available + cross_object = GENOtoCSVR(genofilelocation, crossfilelocation) # TODO: Add the SEX if that is available if self.manhattan_plot: cross_object = calc_genoprob(cross_object) @@ -307,30 +311,30 @@ class MarkerRegression(object): # for debug: write_cross(cross_object, "csvr", "test.csvr") # Scan for QTLs - covar = self.create_covariates(cross_object) + covar = self.create_covariates(cross_object) # Create the additive covariate matrix if self.pair_scan: - if(r_sum(covar)[0] > 0): + if(r_sum(covar)[0] > 0): # If sum(covar) > 0 we have a covariate matrix print("Using covariate"); result_data_frame = scantwo(cross_object, pheno = "the_pheno", addcovar = covar) else: print("No covariates"); result_data_frame = scantwo(cross_object, pheno = "the_pheno") - print("pair scan results:", result_data_frame) + print("Pair scan results:", result_data_frame) return 0 else: if(r_sum(covar)[0] > 0): - print("Using covariate"); result_data_frame = scanone(cross_object, pheno = "the_pheno", addcovar = covar) + print("Using covariate"); result_data_frame = scanone(cross_object, pheno = "the_pheno", addcovar = covar, model=self.model, method=self.method) else: - print("No covariates"); result_data_frame = scanone(cross_object, pheno = "the_pheno") + print("No covariates"); result_data_frame = scanone(cross_object, pheno = "the_pheno", model=self.model, method=self.method) - if int(self.num_perm) > 0: # Do permutation (if requested by user) + if int(self.num_perm) > 0: # Do permutation (if requested by user) if(r_sum(covar)[0] > 0): - perm_data_frame = scanone(cross_object, pheno_col = "the_pheno", addcovar = covar, n_perm = int(self.num_perm)) + perm_data_frame = scanone(cross_object, pheno_col = "the_pheno", addcovar = covar, n_perm = int(self.num_perm), model=self.model, method=self.method) else: - perm_data_frame = scanone(cross_object, pheno_col = "the_pheno", n_perm = int(self.num_perm)) + perm_data_frame = scanone(cross_object, pheno_col = "the_pheno", n_perm = int(self.num_perm), model=self.model, method=self.method) - self.process_rqtl_perm_results(perm_data_frame) # Functions that sets the thresholds for the webinterface + self.process_rqtl_perm_results(perm_data_frame) # Functions that sets the thresholds for the webinterface return self.process_rqtl_results(result_data_frame) @@ -342,14 +346,14 @@ class MarkerRegression(object): def create_covariates(self, cross): ro.globalenv["the_cross"] = cross ro.r('genotypes <- pull.geno(the_cross)') # Get the genotype matrix - userinputS = self.control.replace(" ", "").split(",") # TODO sanitize user input, Never Ever trust a user + userinputS = self.control.replace(" ", "").split(",") # TODO: sanitize user input, Never Ever trust a user covariate_names = ', '.join('"{0}"'.format(w) for w in userinputS) print("Marker names of selected covariates:", covariate_names) ro.r('covnames <- c(' + covariate_names + ')') ro.r('covInGeno <- which(covnames %in% colnames(genotypes))') ro.r('covnames <- covnames[covInGeno]') ro.r("cat('covnames (purged): ', covnames,'\n')") - ro.r('covariates <- genotypes[,covnames]') # Get the covariate matrix by using the marker name as index to the genotype file + ro.r('covariates <- genotypes[,covnames]') # Get the covariate matrix by using the marker name as index to the genotype file print("R/qtl matrix of covariates:", ro.r["covariates"]) return ro.r["covariates"] diff --git a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee index fdec0ee4..a87d3537 100755 --- a/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee +++ b/wqflask/wqflask/static/new/javascript/show_trait_mapping_tools.coffee @@ -198,4 +198,4 @@ $("#choose_closet_control").change(-> $("#display_all_lrs").change(-> toggle_enable_disable("#suggestive_lrs") -);
\ No newline at end of file +); diff --git a/wqflask/wqflask/templates/show_trait_mapping_tools.html b/wqflask/wqflask/templates/show_trait_mapping_tools.html index 946dab49..7794fab5 100755 --- a/wqflask/wqflask/templates/show_trait_mapping_tools.html +++ b/wqflask/wqflask/templates/show_trait_mapping_tools.html @@ -146,6 +146,7 @@ {% endif %} </div> </div> + <div class="mapping_method_fields form-group"> <label style="text-align:left;" class="col-xs-12 control-label">Manhattan Plot</label> <div class="col-xs-12 controls"> @@ -159,6 +160,30 @@ </label> </div> </div> + + <div class="mapping_method_fields form-group"> + <label style="text-align:left;" class="col-xs-12 control-label">Method</label> + <select name="mapmethod_rqtl_geno"> + <option value="em">em</option> + <option value="imp">imp</option> + <option value="hk">hk</option> + <option value="ehk">ehk</option> + <option value="mr">mr</option> + <option value="mr-imp">mr-imp</option> + <option value="mr-argmax">mr-argmax</option> + </select> + </div> + + <div class="mapping_method_fields form-group"> + <label style="text-align:left;" class="col-xs-12 control-label">Model</label> + <select name="mapmodel_rqtl_geno"> + <option value="normal">normal</option> + <option value="binary">binary</option> + <option value="2part">2part</option> + <option value="np">np</option> + </select> + </div> + <div class="mapping_method_fields form-group"> <label style="text-align:left;" class="col-xs-12 control-label">Pair Scan</label> <div class="col-xs-12 controls"> @@ -240,4 +265,4 @@ <div id="mapping_result_holder_wrapper" style="display:none;"> <div id="mapping_result_holder"></div> </div> -</div>
\ No newline at end of file +</div> diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index e60852d5..bac553d7 100755 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -286,9 +286,11 @@ def marker_regression_page(): 'manhattan_plot', 'control_marker', 'control_marker_db', - 'pair_scan' + 'pair_scan', + 'mapmethod_rqtl_geno', + 'mapmodel_rqtl_geno' ) - + print("Random Print too see if it is running:", initial_start_vars) start_vars = {} for key, value in initial_start_vars.iteritems(): if key in wanted or key.startswith(('value:')): |