-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathENT3C.jl
executable file
·151 lines (132 loc) · 5.34 KB
/
ENT3C.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function parse_args(args)
installs = nothing
resolve_env = nothing
config_file = nothing
julia_version = nothing
for arg in args
if startswith(arg, "--config-file=")
config_file = split(arg, "=")[2]
end
if startswith(arg, "--install-deps=")
installs = split(arg, "=")[2]
end
if startswith(arg, "--resolve-env=")
resolve_env = split(arg, "=")[2]
end
if startswith(arg, "--julia-version=")
julia_version = split(arg, "=")[2]
end
end
if isnothing(config_file) || config_file == ""
throw(ArgumentError("--config-file is missing or empty"))
end
return installs, resolve_env, config_file, julia_version
end
function check_missing_packages(required_packages)
installed_packages = [info.name for info in values(Pkg.dependencies())]
missing_packages = [pkg for pkg in required_packages if !(pkg in installed_packages)]
return missing_packages
end
function install_packages(packages)
for pkg in packages
try
Pkg.add(pkg)
catch e
println("Failed to install package $pkg: $e")
exit(1)
end
end
end
using Pkg
installs, resolve_env, config_file, julia_version = parse_args(ARGS)
#args = ["--config-file=config/config.json", "--install-deps=no"]
#installs, config_file = parse_args(args)
required_packages = ["DataFrames", "BenchmarkTools", "JSON", "Printf", "Plots", "ColorSchemes", "SuiteSparse", "HDF5", "NaNStatistics", "Statistics", "Combinatorics", "CSV"]
missing_packages = check_missing_packages(required_packages)
if isnothing(installs) && isnothing(resolve_env) && !isempty(missing_packages)
println("Error! Missing julia packages. Please specify one of the following:")
println("1. Use --install-deps=yes to install the packages globally.")
println(" Or")
println("2. Specify --resolve-env=yes with --julia-version=1.10.4 or 1.11.2 to install and resolve environment.")
exit(1)
end
if installs == "yes" && length(missing_packages)!=1 && resolve_env != "yes"
println("Installing missing dependencies globally.")
println(resolve_env)
install_packages(missing_packages)
end
if resolve_env == "yes"
if isnothing(julia_version) || julia_version == ""
throw(ArgumentError("--resolve-env requires julia version specification --julia-version=1.11.2 or --julia-version=1.10.4"))
end
println("Resolving ENT3C julia enviornment.")
Pkg.activate("project_files/$(julia_version)")
Pkg.add(["DataFrames", "BenchmarkTools", "JSON", "Printf", "Plots", "ColorSchemes", "SuiteSparse", "HDF5", "NaNStatistics", "Statistics", "Combinatorics", "CSV"])
Pkg.instantiate()
end
using DataFrames, BenchmarkTools, JSON, Printf, Plots, ColorSchemes, SuiteSparse
include("JULIA_functions/ent3c_functions.jl")
######################################################
# user input config file
######################################################
#config = JSON.parsefile("config/config.test.json")
function get_config(config_file)
config=nothing
if config_file === nothing
println("Please specify a configuration file.")
else
println("Using config file: $config_file")
try
config = JSON.parsefile(config_file)
println("Config data: ", config)
catch e
println("Error reading config file: ", e)
end
end
return config
end
config = get_config(config_file)
#########################################################
SUB_M_SIZE_FIX = config["SUB_M_SIZE_FIX"]
PHI_MAX = config["PHI_MAX"]
Resolutions = config["Resolution"]
Resolutions = split(Resolutions, ",")
Resolutions = [parse(Float64, res) |> Int for res in Resolutions]
phi = config["phi"]
NormM = config["NormM"]
DATA_PATH = config["DATA_PATH"]
FILES = config["FILES"]
Biological_replicates = any(x -> contains(x, '_'), FILES[2, :])
FILES = hcat(joinpath.(DATA_PATH, FILES[1:2:end-1]), FILES[2:2:end])
OUT_PREFIX = config["OUT_PREFIX"]
CHRSPLIT = config["CHRSPLIT"]
weights_name = config["WEIGHTS_NAME"]
if OUT_PREFIX === nothing
OUT_PREFIX = @sprintf("%dkb",Resolution/1e3)
end
OUT_DIR = config["OUT_DIR"]
OUT_DIR = string(OUT_DIR,"JULIA")
if !isdir(OUT_DIR)
mkpath(OUT_DIR)
end
ChrNrs = string(config["ChrNr"])
if contains(ChrNrs, ",")
ChrNrs = split(ChrNrs, ",")
else
ChrNrs = [ChrNrs]
end
#############################################################################
# ENT3C table
##############################################################################
ENT3C_OUT = main(FILES,Resolutions,ChrNrs,SUB_M_SIZE_FIX,CHRSPLIT,PHI_MAX,phi,NormM,weights_name)
#f = [filter(row -> isnan(row.S) , ENT3C_OUT).binNrStart[1], filter(row -> isnan(row.S) , ENT3C_OUT).binNrEnd[1]]
#filter(row -> row.binNrStart==f[1] && row.binNrEnd==f[2], ENT3C_OUT)
#############################################################################
# similarity table
#############################################################################
SAMPLES::Array=unique(ENT3C_OUT.Name)
if length(SAMPLES)>1
Similarity = get_similarity_table(ENT3C_OUT,ChrNrs,Resolutions,Biological_replicates)
CSV.write(@sprintf("%s/%s_ENT3C_similarity.csv",OUT_DIR,OUT_PREFIX), Similarity)
end
CSV.write(@sprintf("%s/%s_ENT3C_OUT.csv",OUT_DIR,OUT_PREFIX), ENT3C_OUT)