Skip to content

Commit

Permalink
ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
kedhammar committed Dec 11, 2023
1 parent 548a3eb commit 6899e33
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 119 deletions.
4 changes: 1 addition & 3 deletions scilifelab_epps/epp.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ def __enter__(self):
)
except DistributionNotFound as e:
logging.error(e)
logging.error(
f"Make sure you have the {self.PACKAGE} " "package installed"
)
logging.error(f"Make sure you have the {self.PACKAGE} " "package installed")
sys.exit(-1)
return self

Expand Down
14 changes: 4 additions & 10 deletions scripts/attach_caliper_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,18 @@ def main(lims, args, epp_logger):
fns = list(filter(im_file_r.match, file_list))

if len(fns) == 0:
logging.warning(
f"No image file found for artifact with id {i_a.id}"
)
logging.warning(f"No image file found for artifact with id {i_a.id}")
artifact_missing_file.append(i_a)
elif len(fns) > 1:
logging.warning(

f"Multiple image files found for artifact with id {i_a.id}, "
"please attach files manually"

f"Multiple image files found for artifact with id {i_a.id}, "
"please attach files manually"
)
artifact_multiple_file.append(i_a)
else:
fn = fns[0]
found_files.append(fn)
logging.info(
f"Found image file {fn} for artifact with id {i_a.id}"
)
logging.info(f"Found image file {fn} for artifact with id {i_a.id}")
fp = os.path.join(args.path, fn)

# Attach file to the LIMS
Expand Down
4 changes: 1 addition & 3 deletions scripts/bravo_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,9 +1248,7 @@ def calc_vol(art_tuple, logContext, checkTheLog):
f"{total_volume:.2f}",
)
except KeyError as e:
logContext.write(
f"ERROR : The input artifact is lacking a field : {e}\n"
)
logContext.write(f"ERROR : The input artifact is lacking a field : {e}\n")
checkTheLog[0] = True
except AssertionError:
logContext.write(
Expand Down
4 changes: 1 addition & 3 deletions scripts/calculate_cell_nuclei_conc.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def calculate_cell_nuclei_conc(pro):
art.udf["Conc. Units"] = "count/ul"
art.udf["Amount (ng)"] = 0
art.put()
log.append(
f"Sample {sample} concentration set to {conc} count/ul."
)
log.append(f"Sample {sample} concentration set to {conc} count/ul.")
# Throw error message when there is missing value
else:
for k, v in value_dict.items():
Expand Down
8 changes: 2 additions & 6 deletions scripts/copy_frag_an.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,9 @@ def get_frag_an_csv_data(process):
if k == "concentration":
target_file.udf["Conc. Units"] = "ng/ul"
else:
log.append(
f"NaN {k} value for Sample {file_sample}."
)
log.append(f"NaN {k} value for Sample {file_sample}.")
except ValueError:
log.append(
f"Bad {k} value format for Sample {file_sample}."
)
log.append(f"Bad {k} value format for Sample {file_sample}.")
# actually set the data
target_file.put()
set_field(target_file)
Expand Down
42 changes: 12 additions & 30 deletions scripts/illumina_run_parameter_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ def fetch_rundir(fc_id, run_type):
data_dir = "NovaSeqXPlus_data"

metadata_dir = "ngi-nas-ns"
run_dir_path = os.path.join(
os.sep, "srv", metadata_dir, data_dir, f"*{fc_id}"
)
run_dir_path = os.path.join(os.sep, "srv", metadata_dir, data_dir, f"*{fc_id}")

if len(glob.glob(run_dir_path)) == 1:
run_dir = glob.glob(run_dir_path)[0]
Expand All @@ -82,13 +80,9 @@ def fetch_rundir(fc_id, run_type):
def parse_run(run_dir):
runParserObj = RunParser(run_dir)
if os.path.exists(f"{run_dir}/RunParameters.xml"):
RunParametersParserObj = RunParametersParser(
f"{run_dir}/RunParameters.xml"
)
RunParametersParserObj = RunParametersParser(f"{run_dir}/RunParameters.xml")
elif os.path.exists(f"{run_dir}/runParameters.xml"):
RunParametersParserObj = RunParametersParser(
f"{run_dir}/runParameters.xml"
)
RunParametersParserObj = RunParametersParser(f"{run_dir}/runParameters.xml")
else:
sys.stderr.write(f"No RunParameters.xml found in path {run_dir}")
sys.exit(2)
Expand Down Expand Up @@ -212,13 +206,11 @@ def set_run_stats_in_lims(process, run_stats_summary):
for i in list(run_stats_summary[lane_nbr].keys()):
lane_stats_for_read = run_stats_summary[lane_nbr][i]
if not math.isnan(lane_stats_for_read["density"]):
art.udf[
f"Cluster Density (K/mm^2) R{read}"
] = lane_stats_for_read["density"]
if not math.isnan(lane_stats_for_read["error_rate"]):
art.udf[f"% Error Rate R{read}"] = lane_stats_for_read[
"error_rate"
art.udf[f"Cluster Density (K/mm^2) R{read}"] = lane_stats_for_read[
"density"
]
if not math.isnan(lane_stats_for_read["error_rate"]):
art.udf[f"% Error Rate R{read}"] = lane_stats_for_read["error_rate"]
if not math.isnan(lane_stats_for_read["first_cycle_intensity"]):
art.udf[f"Intensity Cycle 1 R{read}"] = lane_stats_for_read[
"first_cycle_intensity"
Expand All @@ -234,21 +226,15 @@ def set_run_stats_in_lims(process, run_stats_summary):
if not math.isnan(lane_stats_for_read["percent_pf"]):
art.udf[f"%PF R{read}"] = lane_stats_for_read["percent_pf"]
if not math.isnan(lane_stats_for_read["phasing"]):
art.udf[f"% Phasing R{read}"] = lane_stats_for_read[
"phasing"
]
art.udf[f"% Phasing R{read}"] = lane_stats_for_read["phasing"]
if not math.isnan(lane_stats_for_read["prephasing"]):
art.udf[f"% Prephasing R{read}"] = lane_stats_for_read[
"prephasing"
]
art.udf[f"% Prephasing R{read}"] = lane_stats_for_read["prephasing"]
if not math.isnan(lane_stats_for_read["reads_pf"]):
art.udf[f"Reads PF (M) R{read}"] = (
lane_stats_for_read["reads_pf"] / 1000000
)
if not math.isnan(lane_stats_for_read["yield_g"]):
art.udf[f"Yield PF (Gb) R{read}"] = lane_stats_for_read[
"yield_g"
]
art.udf[f"Yield PF (Gb) R{read}"] = lane_stats_for_read["yield_g"]
read += 1
art.put()
process.put()
Expand All @@ -271,13 +257,9 @@ def set_run_stats_in_lims_miseq(process, run_stats_summary):
"first_cycle_intensity"
]
if not math.isnan(lane_stats_for_read["percent_aligned"]):
art.udf[f"% Aligned R{read}"] = lane_stats_for_read[
"percent_aligned"
]
art.udf[f"% Aligned R{read}"] = lane_stats_for_read["percent_aligned"]
if not math.isnan(lane_stats_for_read["percent_gt_q30"]):
art.udf[f"% Bases >=Q30 R{read}"] = lane_stats_for_read[
"percent_gt_q30"
]
art.udf[f"% Bases >=Q30 R{read}"] = lane_stats_for_read["percent_gt_q30"]
if not math.isnan(lane_stats_for_read["percent_pf"]):
art.udf[f"%PF R{read}"] = lane_stats_for_read["percent_pf"]
if not math.isnan(lane_stats_for_read["phasing"]):
Expand Down
4 changes: 1 addition & 3 deletions scripts/index_distance_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def verify_indexes(data):
)
)
if len(idx_length) > 1:
message.append(
f"INDEX WARNING: Multiple index lengths noticed in pool {p}"
)
message.append(f"INDEX WARNING: Multiple index lengths noticed in pool {p}")
return message


Expand Down
4 changes: 1 addition & 3 deletions scripts/make_running_note_from_pooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def main(lims, args):
if out.name == "RNotes Log":
attach_file(os.path.join(os.getcwd(), "EPP_Notes.log"), out)

sys.stderr.write(
f"Updated {len(list(datamap.keys()))} projects successfully"
)
sys.stderr.write(f"Updated {len(list(datamap.keys()))} projects successfully")


if __name__ == "__main__":
Expand Down
4 changes: 1 addition & 3 deletions scripts/make_running_note_from_workset.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def main(lims, args):
if out.name == "RNotes Log":
attach_file(os.path.join(os.getcwd(), "EPP_Notes.log"), out)

sys.stderr.write(
f"Updated {len(list(datamap.keys()))} projects successfully"
)
sys.stderr.write(f"Updated {len(list(datamap.keys()))} projects successfully")


if __name__ == "__main__":
Expand Down
32 changes: 8 additions & 24 deletions scripts/manage_demux_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def get_process_stats(demux_process):
inputartifactlimsid=demux_process.all_inputs()[0].id, type=seq_processes
)[0]
except Exception as e:
problem_handler(
"exit", f"Undefined prior workflow step (run type): {str(e)}"
)
problem_handler("exit", f"Undefined prior workflow step (run type): {str(e)}")
# Copies LIMS sequencing step content
proc_stats = dict(list(seq_process.udf.items()))
# Instrument is denoted the way it is since it is also used to find
Expand Down Expand Up @@ -114,9 +112,7 @@ def get_process_stats(demux_process):
try:
proc_stats["Chemistry"] = seq_process.udf["Chemistry"]
except Exception as e:
problem_handler(
"exit", f"No run type set in sequencing step: {str(e)}"
)
problem_handler("exit", f"No run type set in sequencing step: {str(e)}")
proc_stats["Instrument"] = "NextSeq"
proc_stats["Read Length"] = (
max(seq_process.udf["Read 1 Cycles"], seq_process.udf["Read 2 Cycles"])
Expand All @@ -133,9 +129,7 @@ def get_process_stats(demux_process):
try:
proc_stats["Paired"] = proc_stats.get("Paired", False)
except Exception as e:
problem_handler(
"exit", f"Unable to fetch workflow information: {str(e)}"
)
problem_handler("exit", f"Unable to fetch workflow information: {str(e)}")
if "Read 2 Cycles" in proc_stats:
proc_stats["Paired"] = True
logger.info("Paired libraries: {}".format(proc_stats["Paired"]))
Expand Down Expand Up @@ -229,9 +223,7 @@ def fill_process_fields(demux_process, process_stats):
try:
demux_process.put()
except Exception as e:
problem_handler(
"exit", f"Failed to apply process thresholds to LIMS: {str(e)}"
)
problem_handler("exit", f"Failed to apply process thresholds to LIMS: {str(e)}")


def set_sample_values(demux_process, parser_struct, process_stats):
Expand Down Expand Up @@ -261,9 +253,7 @@ def set_sample_values(demux_process, parser_struct, process_stats):
inputartifactlimsid=demux_process.all_inputs()[0].id, type=seq_processes
)[0]
except Exception as e:
problem_handler(
"exit", f"Undefined prior workflow step (run type): {str(e)}"
)
problem_handler("exit", f"Undefined prior workflow step (run type): {str(e)}")

if "Lanes to include undetermined" in demux_process.udf:
try:
Expand All @@ -286,9 +276,7 @@ def set_sample_values(demux_process, parser_struct, process_stats):
try:
outarts_per_lane = demux_process.outputs_per_input(pool.id, ResultFile=True)
except Exception as e:
problem_handler(
"exit", f"Unable to fetch artifacts of process: {str(e)}"
)
problem_handler("exit", f"Unable to fetch artifacts of process: {str(e)}")
if process_stats["Instrument"] == "miseq":
lane_no = "1"
else:
Expand Down Expand Up @@ -317,9 +305,7 @@ def set_sample_values(demux_process, parser_struct, process_stats):
"exit",
f"Faulty LIMS setup. Pool in lane {lane_no} has no samples: {e}",
)
logger.info(
f"Expected sample clusters for this lane: {exp_smp_per_lne}"
)
logger.info(f"Expected sample clusters for this lane: {exp_smp_per_lne}")

# Artifacts in each lane
for target_file in outarts_per_lane:
Expand Down Expand Up @@ -735,9 +721,7 @@ def set_sample_values(demux_process, parser_struct, process_stats):
problem_handler("warning", "Undetermined reads included in read count!")

if failed_entries > 0:
problem_handler(
"warning", f"{failed_entries} entries failed automatic QC"
)
problem_handler("warning", f"{failed_entries} entries failed automatic QC")


def write_demuxfile(process_stats, demux_id):
Expand Down
4 changes: 1 addition & 3 deletions scripts/readscount.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,7 @@ def sumreads(sample, summary):
except AttributeError as e:
print(e)
# base_art is still None because no arts were found
logging.info(
f"No demultiplexing processes found for sample {sample.name}"
)
logging.info(f"No demultiplexing processes found for sample {sample.name}")

# total is displayed as millions
tot /= 1000000
Expand Down
Loading

0 comments on commit 6899e33

Please sign in to comment.