Skip to content

Commit

Permalink
print status of finished jobs to a log-file (towards #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Warchal committed Feb 13, 2018
1 parent e81f884 commit d4dfe26
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
27 changes: 26 additions & 1 deletion cptools2/generate_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ def make_qsub_scripts(commands_location, commands_count_dict, logfile_location):
analysis_script.loop_through_file(cmd_path["cp_commands"])
analysis_loc = os.path.join(commands_location,
"{}_analysis_script.sh".format(time_now))
analysis_script.template += make_logfile_text(logfile_location, job_hex)
print("** saving analysis submission script at '{}'".format(analysis_loc))
analysis_script.save(analysis_loc)

destaging_script = BodgeScript(
name="destaging_{}".format(job_hex),
memory="1G",
Expand All @@ -183,6 +183,24 @@ def make_qsub_scripts(commands_location, commands_count_dict, logfile_location):
utils.make_executable(submit_script)


def make_logfile_text(logfile_location, job_file):
text = """
# get the exit code from the cellprofiler job
RETURN_VAL=$?
if [[ $RETURN_VAL == 0]]; then
RETURN_STATUS="Finished"
else
RETURN_STATUS="Failed with error code: $RETURN_VAL
fi
LOG_FILE_LOC={logfile_location}/{job_file}.log
echo "`date +"%Y%m%d %H:%M"` $JOB_ID $SGE_TASK_ID $RETURN_STATUS" >> $LOG_FILE_LOC
""".format(logfile_location=logfile_location,
job_file=job_file)
return textwrap.dedent(text)


def load_venv_store():
"""
Load the virtual environment yaml file that details each user's path to
Expand Down Expand Up @@ -237,6 +255,13 @@ def make_submit_script(commands_location, job_date):
# create text for a shell script that qsub's the scripts
output = """
#!/bin/sh
# This script submits the staging, analysis and destaging
# scripts in the correct order
# NOTE: run this as a shell script, NOT a submission script
# so either call `./name_of_script` or `bash name_of_script`
qsub {staging_script}
qsub {analysis_script}
qsub {destaging_script}
Expand Down
1 change: 1 addition & 0 deletions cptools2/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def create_commands(self, pipeline, location, commands_location, job_size):
file path to location in which to store the stage, analysis and
destage commands.
"""
print("** creating image list")
if self.has_loaddata is False:
self._create_loaddata(job_size)
cp_commands, rsync_commands, rm_commands = [], [], []
Expand Down
4 changes: 2 additions & 2 deletions cptools2/loaddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ def cast_dataframe(dataframe, check_nan=True):
# rename FileName columns from 1, 2... to FileName_W1, FileName_W2 ...
columns = {}
for i in range(1, n_channels+1):
columns[i] = "FileName_W" + str(i)
columns[i] = "FileName_W{0}".format(str(i))
wide_df.rename(columns=columns, inplace=True)
# duplicate PathName for each channel
for i in range(1, n_channels+1):
wide_df["PathName_W" + str(i)] = wide_df.path
wide_df.drop(["path"], axis=1, inplace=True)
if check_nan is True:
if utils.any_nan_values(dataframe):
raise Warning("dataframe contains missing values")
raise LoadDataError("dataframe contains missing values")
return wide_df


Expand Down

0 comments on commit d4dfe26

Please sign in to comment.