Skip to content

Commit

Permalink
Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
gurayerus committed Sep 11, 2024
1 parent 1cd3922 commit dfaca17
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 276 deletions.
64 changes: 17 additions & 47 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,32 @@

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--dir_input", help="Provide input folder", required=True)
parser.add_argument("--dir_output", help="Provide output folder", required=True)
parser.add_argument("--studies", type=int, help="Provide total studies", required=True)
parser.add_argument("--cores", help="Select number of cores that the workflow will use to run", required=True)
parser.add_argument("--dry_run", help="Select dry run", default=0)
parser.add_argument("--version", type=str, default="test", help="Provide version")
parser.add_argument("--conda", type=int, help="Run workflows without initializing a coda environment again", default=0)
parser.add_argument("--input_rois", help="Provide input csv name with ROIs", required=True)
parser.add_argument("--input_demog", help="Provide input csv name with demographic info", required=True)
parser.add_argument("--input_config", help="Provide input config file name", required=True)
parser.add_argument("--dir_output", help="Provide output folder name", required=True)

options = parser.parse_args()

if int(options.cores) < 1:
print("Please select a valid number of cores(>=1)")
exit(0)
# Read default config file
with open(options.input_config, 'r') as f:
config = json.load(f)

if int(options.conda) == 1:
os.system("pip install -r requirements.txt")
os.system("conda install -n base -c conda-forge mamba")
os.system("mamba init")
os.system("mamba create -c conda-forge -c bioconda -n NiChart_Workflows python=3.8")
os.system("conda activate NiChart_Workflows")
os.system("mamba install -c conda-forge -c bioconda snakemake")

# generate info.json file for configuration
if not os.path.exists("info.json"):
os.system("touch info.json")
# Update the default config using the input args
config['input_rois'] = options.input_rois
config['input_demog'] = options.input_demog
config['dir_output'] = options.dir_output

config = {
"version": options.version,
"dir_input": options.dir_input,
"dir_output": options.dir_output,
"studies": options.studies,
"list_ROIs_all": "MUSE/list_MUSE_all.csv",
"list_ROIs_single": "MUSE/list_MUSE_single.csv",
"list_ROIs_primary": "MUSE/list_MUSE_primary.csv",
"list_derived_ROIs": "MUSE/list_MUSE_mapping_derived.csv",
"corr_type": "normICV",
"model_combat": "models/vISTAG1/COMBAT/combined_DLMUSE_raw_COMBATModel.pkl.gz",
"model_SPARE-AD": "models/vISTAG1/SPARE/combined_DLMUSE_raw_COMBAT_SPARE-AD_Model.pkl.gz",
"model_SPARE-Age": "models/vISTAG1/SPARE/combined_DLMUSE_raw_COMBAT_SPARE-Age_Model.pkl.gz",
"model_SPARE-Diabetes": "models/vISTAG1/SPARE/combined_DLMUSE_raw_COMBAT_SPARE-Diabetes_Model.pkl.gz",
"model_SPARE-Hyperlipidemia": "models/vISTAG1/SPARE/combined_DLMUSE_raw_COMBAT_SPARE-Hyperlipidemia_Model.pkl.gz",
"model_SPARE-Hypertension": "models/vISTAG1/SPARE/combined_DLMUSE_raw_COMBAT_SPARE-Hypertension_Model.pkl.gz",
"model_SPARE-Obesity": "models/vISTAG1/SPARE/combined_DLMUSE_raw_COMBAT_SPARE-Obesity_Model.pkl.gz",
"model_SPARE-Smoking": "models/vISTAG1/SPARE/combined_DLMUSE_raw_COMBAT_SPARE-Smoking_Model.pkl.gz",
"studies": [f"Study{i + 1}" for i in range(options.studies)],
"SPARE_types": ["AD", "Age", "Diabetes", "Hyperlipidemia", "Hypertension", "Obesity", "Smoking"],
"seg_types": ["DLMUSE"]
}
# Create out dir
if not os.path.exists(options.dir_output):
os.makedirs(options.dir_output)

# Write config file
json_config = json.dumps(config, indent=4)
out_file = os.path.join(options.dir_output, 'config.json')
with open("info.json", "w") as outfile:
outfile.write(json_config)
os.system("mv info.json src/workflow/workflows/")

os.chdir('src/workflow/workflows/w_sMRI')
if int(options.dry_run) == 1:
os.system("snakemake -np")
else:
os.system(f"snakemake --cores {options.cores}")
os.system(f"snakemake --cores 1")
Loading

0 comments on commit dfaca17

Please sign in to comment.