ML scripts: {'n_jobs': os.cpu_count() }
This commit is contained in:
parent
11af00f1db
commit
b8653c6afe
4 changed files with 16 additions and 12 deletions
|
@ -76,8 +76,7 @@ import argparse
|
||||||
import re
|
import re
|
||||||
#####################################
|
#####################################
|
||||||
rs = {'random_state': 42}
|
rs = {'random_state': 42}
|
||||||
njobs = {'n_jobs': 10}
|
njobs = {'n_jobs': os.cpu_count() } # the number of jobs should equal the number of CPU cores
|
||||||
|
|
||||||
|
|
||||||
scoring_fn = ({ 'mcc' : make_scorer(matthews_corrcoef)
|
scoring_fn = ({ 'mcc' : make_scorer(matthews_corrcoef)
|
||||||
, 'fscore' : make_scorer(f1_score)
|
, 'fscore' : make_scorer(f1_score)
|
||||||
|
|
|
@ -76,7 +76,7 @@ import argparse
|
||||||
import re
|
import re
|
||||||
#%% GLOBALS
|
#%% GLOBALS
|
||||||
rs = {'random_state': 42}
|
rs = {'random_state': 42}
|
||||||
njobs = {'n_jobs': 10}
|
njobs = {'n_jobs': os.cpu_count() } # the number of jobs should equal the number of CPU cores
|
||||||
|
|
||||||
scoring_fn = ({ 'mcc' : make_scorer(matthews_corrcoef)
|
scoring_fn = ({ 'mcc' : make_scorer(matthews_corrcoef)
|
||||||
, 'fscore' : make_scorer(f1_score)
|
, 'fscore' : make_scorer(f1_score)
|
||||||
|
|
|
@ -41,7 +41,7 @@ import re
|
||||||
homedir = os.path.expanduser("~")
|
homedir = os.path.expanduser("~")
|
||||||
#%% GLOBALS
|
#%% GLOBALS
|
||||||
rs = {'random_state': 42}
|
rs = {'random_state': 42}
|
||||||
njobs = {'n_jobs': 10}
|
njobs = {'n_jobs': os.cpu_count() } # the number of jobs should equal the number of CPU cores
|
||||||
|
|
||||||
#%% Define split_tts function #################################################
|
#%% Define split_tts function #################################################
|
||||||
def split_tts(ml_input_data
|
def split_tts(ml_input_data
|
||||||
|
|
|
@ -5,8 +5,8 @@ library(ggpubr)
|
||||||
library(svglite)
|
library(svglite)
|
||||||
|
|
||||||
# for testing only
|
# for testing only
|
||||||
gene="pncA"
|
#gene="pncA"
|
||||||
drug="pyrazinamide"
|
#drug="pyrazinamide"
|
||||||
|
|
||||||
lineage_plot=function(gene,drug){
|
lineage_plot=function(gene,drug){
|
||||||
lineage_filename=paste0(tolower(gene),"_merged_df2.csv")
|
lineage_filename=paste0(tolower(gene),"_merged_df2.csv")
|
||||||
|
@ -84,7 +84,7 @@ lineage_plot=function(gene,drug){
|
||||||
#print (i)
|
#print (i)
|
||||||
s_mut = plot_df[plot_df$mutationinformation == i,]
|
s_mut = plot_df[plot_df$mutationinformation == i,]
|
||||||
s_tab = table(s_mut$lineage, s_mut$sensitivity)
|
s_tab = table(s_mut$lineage, s_mut$sensitivity)
|
||||||
ft_pvalue_i = fisher.test(s_tab)$p.value
|
ft_pvalue_i = fisher.test(s_tab, workspace=2000000)$p.value
|
||||||
plot_df$pval[plot_df$mutationinformation == i] <- ft_pvalue_i
|
plot_df$pval[plot_df$mutationinformation == i] <- ft_pvalue_i
|
||||||
}
|
}
|
||||||
plot_df$pvalR = round(plot_df$pval, 3)
|
plot_df$pvalR = round(plot_df$pval, 3)
|
||||||
|
@ -131,12 +131,14 @@ lineage_plot=function(gene,drug){
|
||||||
|
|
||||||
# Do plots
|
# Do plots
|
||||||
plot_pages = round(length(lin_muts)/25)
|
plot_pages = round(length(lin_muts)/25)
|
||||||
|
if (plot_pages<1){plot_pages=1}
|
||||||
p_title = gene
|
p_title = gene
|
||||||
res = 144 # SVG dots-per-inch
|
res = 144 # SVG dots-per-inch
|
||||||
|
print(paste0('About to plot ', plot_pages, ' page(s).'))
|
||||||
|
|
||||||
sapply(1:plot_pages, function(page){
|
sapply(1:plot_pages, function(page){
|
||||||
print(paste0("Plotting page:", page))
|
print(paste0("Plotting page:", page))
|
||||||
svglite(paste0("/tmp/",drug,"-",page,".svg"), width=2048/res, height=1534/res) # old-school square 4:3 CRT shape 1.3:1
|
svglite(paste0("/tmp/",drug,"-",page,".svg"), width=2048/res, height=1534/res) # old-school square 4:3 CRT shape 1.33:1
|
||||||
print(
|
print(
|
||||||
ggplot(plot_df2, aes(x = lineage
|
ggplot(plot_df2, aes(x = lineage
|
||||||
, fill = sensitivity)) +
|
, fill = sensitivity)) +
|
||||||
|
@ -169,17 +171,19 @@ lineage_plot=function(gene,drug){
|
||||||
|
|
||||||
# hardcoded list of drugs
|
# hardcoded list of drugs
|
||||||
drugs = c(#"ethambutol",
|
drugs = c(#"ethambutol",
|
||||||
#"isoniazid",
|
"isoniazid",
|
||||||
"pyrazinamide",
|
"pyrazinamide",
|
||||||
"rifampicin",
|
"rifampicin",
|
||||||
"streptomycin",
|
"streptomycin",
|
||||||
"cycloserine")
|
#"cycloserine"
|
||||||
|
)
|
||||||
genes = c(#"embB",
|
genes = c(#"embB",
|
||||||
#"katG",
|
"katG",
|
||||||
"pncA",
|
"pncA",
|
||||||
"rpoB",
|
"rpoB",
|
||||||
"gid",
|
"gid",
|
||||||
"alr")
|
#"alr"
|
||||||
|
)
|
||||||
combo = data.frame(drugs, genes)
|
combo = data.frame(drugs, genes)
|
||||||
|
|
||||||
#sapply(combo$drugs, function(x){print(c(x,combo[drugs==x,"genes"]))})
|
#sapply(combo$drugs, function(x){print(c(x,combo[drugs==x,"genes"]))})
|
||||||
|
@ -188,4 +192,5 @@ combo = data.frame(drugs, genes)
|
||||||
sapply(combo$drugs, function(drug){
|
sapply(combo$drugs, function(drug){
|
||||||
gene=combo[drugs==drug,"genes"]
|
gene=combo[drugs==drug,"genes"]
|
||||||
lineage_plot(gene,drug)
|
lineage_plot(gene,drug)
|
||||||
|
print(c(gene,drug))
|
||||||
})
|
})
|
Loading…
Add table
Add a link
Reference in a new issue