aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorDanny Arends2020-05-06 05:21:59 -0500
committerDanny Arends2020-05-06 05:21:59 -0500
commit8c05b01213019735fcf72ffbacf4d02e4f803b07 (patch)
treec9d2253f126766ca0f02329e16719618bac5ef96 /wqflask
parent3b1bcd0ff7dc199e6ea83a766cb1d9e6081776a7 (diff)
downloadgenenetwork2-8c05b01213019735fcf72ffbacf4d02e4f803b07.tar.gz
Fix the covariate, added debug, more output to track what it is doing
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/marker_regression/rqtl_mapping.py53
1 files changed, 40 insertions, 13 deletions
diff --git a/wqflask/wqflask/marker_regression/rqtl_mapping.py b/wqflask/wqflask/marker_regression/rqtl_mapping.py
index 46b54f36..a64a9f9a 100644
--- a/wqflask/wqflask/marker_regression/rqtl_mapping.py
+++ b/wqflask/wqflask/marker_regression/rqtl_mapping.py
@@ -12,6 +12,7 @@ import utility.logger
logger = utility.logger.getLogger(__name__ )
def run_rqtl_geno(vals, samples, dataset, method, model, permCheck, num_perm, perm_strata_list, do_control, control_marker, manhattan_plot, pair_scan, cofactors):
+ logger.info("Start run_rqtl_geno");
## 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
@@ -21,6 +22,8 @@ def run_rqtl_geno(vals, samples, dataset, method, model, permCheck, num_perm, pe
print(r_library("qtl")) # Load R/qtl
+ logger.info("QTL library loaded");
+
## Get pointers to some R/qtl functions
scanone = ro.r["scanone"] # Map the scanone function
scantwo = ro.r["scantwo"] # Map the scantwo function
@@ -40,31 +43,32 @@ def run_rqtl_geno(vals, samples, dataset, method, model, permCheck, num_perm, pe
genofilelocation = locate(dataset.group.genofile, "genotype")
else:
genofilelocation = locate(dataset.group.name + ".geno", "genotype")
+ logger.info("Going to create a cross from geno");
cross_object = GENOtoCSVR(genofilelocation, crossfilelocation) # TODO: Add the SEX if that is available
-
+ logger.info("before calc_genoprob");
if manhattan_plot:
cross_object = calc_genoprob(cross_object)
else:
cross_object = calc_genoprob(cross_object, step=5, stepwidth="max")
-
+ logger.info("after calc_genoprob");
pheno_string = sanitize_rqtl_phenotype(vals)
-
+ logger.info("phenostring done");
+ names_string = sanitize_rqtl_names(samples)
+ logger.info("sanitized pheno and names");
cross_object = add_phenotype(cross_object, pheno_string, "the_pheno") # Add the phenotype
-
+ cross_object = add_names(cross_object, names_string, "the_names") # Add the phenotype
+ logger.info("Added pheno and names");
# Scan for QTLs
marker_covars = create_marker_covariates(control_marker, cross_object) # Create the additive covariate markers
-
+ logger.info("Marker covars done");
if cofactors != "":
cross_object, trait_covars = add_cofactors(cross_object, dataset, cofactors, samples) # Create the covariates from selected traits
ro.r('all_covars <- cbind(marker_covars, trait_covars)')
else:
ro.r('all_covars <- marker_covars')
-
- # Force all covaraites to be numeric (which is wrong for ITP year, season, etc... But required for R/qtl)
- ro.r('covarnames <- colnames(all_covars)')
- ro.r('all_covars <- apply(all_covars, 2, as.numeric)')
- ro.r('colnames(all_covars) <- covarnames')
-
+ logger.info("Saving");
+ ro.r('save.image(file = "/home/dannya/gn2-danny/cross.RData")')
+ logger.info("Saving Done");
covars = ro.r['all_covars']
#DEBUG to save the session object to file
#ro.r('save.image(file = "/home/dannya/gn2-danny/all.RData")')
@@ -191,12 +195,35 @@ def sanitize_rqtl_phenotype(vals):
return pheno_as_string
+def sanitize_rqtl_names(vals):
+ pheno_as_string = "c("
+ for i, val in enumerate(vals):
+ if val == "x":
+ if i < (len(vals) - 1):
+ pheno_as_string += "NA,"
+ else:
+ pheno_as_string += "NA"
+ else:
+ if i < (len(vals) - 1):
+ pheno_as_string += "'" + str(val) + "',"
+ else:
+ pheno_as_string += "'" + str(val) + "'"
+ pheno_as_string += ")"
+
+ return pheno_as_string
+
def add_phenotype(cross, pheno_as_string, col_name):
ro.globalenv["the_cross"] = cross
ro.r('pheno <- data.frame(pull.pheno(the_cross))')
ro.r('the_cross$pheno <- cbind(pheno, ' + col_name + ' = as.numeric('+ pheno_as_string +'))')
return ro.r["the_cross"]
+def add_names(cross, names_as_string, col_name):
+ ro.globalenv["the_cross"] = cross
+ ro.r('pheno <- data.frame(pull.pheno(the_cross))')
+ ro.r('the_cross$pheno <- cbind(pheno, ' + col_name + ' = '+ names_as_string +')')
+ return ro.r["the_cross"]
+
def pull_var(var_name, cross, var_string):
ro.globalenv["the_cross"] = cross
ro.r(var_name +' <- pull.pheno(the_cross, ' + var_string + ')')
@@ -220,8 +247,8 @@ def add_cofactors(cross, this_dataset, covariates, samples):
this_dataset.group.get_samplelist()
trait_samples = this_dataset.group.samplelist
trait_sample_data = trait_ob.data
- for index, sample in enumerate(trait_samples):
- if sample in samples:
+ for index, sample in enumerate(samples):
+ if sample in trait_samples:
if sample in trait_sample_data:
sample_value = trait_sample_data[sample].value
this_covar_data.append(sample_value)