From e9cabb9f62e773b2f1342e1faba55b502cb3571a Mon Sep 17 00:00:00 2001 From: McKay Date: Fri, 29 Mar 2024 16:49:44 -0600 Subject: [PATCH] - refactored import check to shared function - global in CORE formatting change --- CRISPResso2/CRISPRessoAggregateCORE.py | 8 +------- CRISPResso2/CRISPRessoBatchCORE.py | 7 +------ CRISPResso2/CRISPRessoCORE.py | 22 +++++++++++----------- CRISPResso2/CRISPRessoCompareCORE.py | 7 +------ CRISPResso2/CRISPRessoMetaCORE.py | 7 +------ CRISPResso2/CRISPRessoPooledCORE.py | 8 ++------ CRISPResso2/CRISPRessoShared.py | 11 ++--------- CRISPResso2/CRISPRessoWGSCORE.py | 8 +------- scripts/plotAmbiguous.py | 8 ++------ scripts/plotCustomAllelePlot.py | 7 +------ 10 files changed, 23 insertions(+), 70 deletions(-) diff --git a/CRISPResso2/CRISPRessoAggregateCORE.py b/CRISPResso2/CRISPRessoAggregateCORE.py index 87621171..2f09ce6e 100644 --- a/CRISPResso2/CRISPRessoAggregateCORE.py +++ b/CRISPResso2/CRISPRessoAggregateCORE.py @@ -17,12 +17,6 @@ import traceback from datetime import datetime from CRISPResso2 import CRISPRessoShared -try: - from CRISPRessoPro import __version__ - pro_installed = True -except: - pro_installed = False - from CRISPResso2.CRISPRessoReports import CRISPRessoReport from CRISPResso2.CRISPRessoMultiProcessing import get_max_processes, run_plot @@ -79,7 +73,7 @@ def main(): args = parser.parse_args() - if args.use_matplotlib or not pro_installed: + if args.use_matplotlib or not CRISPRessoShared.is_C2Pro_installed(): from CRISPResso2 import CRISPRessoPlot else: from CRISPRessoPro import plot as CRISPRessoPlot diff --git a/CRISPResso2/CRISPRessoBatchCORE.py b/CRISPResso2/CRISPRessoBatchCORE.py index d5c4c004..1c93cf23 100644 --- a/CRISPResso2/CRISPRessoBatchCORE.py +++ b/CRISPResso2/CRISPRessoBatchCORE.py @@ -14,11 +14,6 @@ import traceback from datetime import datetime from CRISPResso2 import CRISPRessoShared -try: - from CRISPRessoPro import __version__ - pro_installed = True -except: - pro_installed = False from CRISPResso2 import CRISPRessoMultiProcessing from CRISPResso2.CRISPRessoReports import CRISPRessoReport @@ -120,7 +115,7 @@ def main(): _jp = lambda filename: os.path.join(OUTPUT_DIRECTORY, filename) #handy function to put a file in the output directory - if args.use_matplotlib or not pro_installed: + if args.use_matplotlib or not CRISPRessoShared.is_C2Pro_installed(): from CRISPResso2 import CRISPRessoPlot else: from CRISPRessoPro import plot as CRISPRessoPlot diff --git a/CRISPResso2/CRISPRessoCORE.py b/CRISPResso2/CRISPRessoCORE.py index 34321479..fe3c0692 100644 --- a/CRISPResso2/CRISPRessoCORE.py +++ b/CRISPResso2/CRISPRessoCORE.py @@ -31,11 +31,11 @@ from CRISPResso2.CRISPRessoReports import CRISPRessoReport from CRISPResso2 import CRISPRessoShared -try: +if CRISPRessoShared.is_C2Pro_installed(): from CRISPRessoPro import __version__ as CRISPRessoProVersion - pro_installed = True -except: - pro_installed = False + C2PRO_INSTALLED = True +else: + C2PRO_INSTALLED = False from CRISPResso2 import CRISPResso2Align from CRISPResso2 import CRISPRessoMultiProcessing @@ -1172,7 +1172,7 @@ def print_stacktrace_if_debug(): raise CRISPRessoShared.BadParameterException("Needleman Wunsch gap extend penalty must be <= 0") - if args.use_matplotlib or not pro_installed: + if args.use_matplotlib or not C2PRO_INSTALLED: from CRISPResso2 import CRISPRessoPlot else: from CRISPRessoPro import plot as CRISPRessoPlot @@ -1677,7 +1677,7 @@ def get_prime_editing_guides(this_amp_seq, this_amp_name, ref0_seq, prime_edited #now that we're done with adding possible guides and amplicons, go through each amplicon and compute quantification windows info('Computing quantification windows', {'percent_complete': 2}) - if pro_installed: + if C2PRO_INSTALLED: info(f'CRISPRessoPro v{CRISPRessoProVersion} installed', {'percent_complete': 3}) else: info(f'CRISPRessoPro not installed', {'percent_complete': 3}) @@ -3675,7 +3675,7 @@ def count_alternate_alleles(sub_base_vectors, ref_name, ref_sequence, ref_total_ plot_2a_input = { 'nuc_pct_df': nuc_df_for_plot, 'mod_pct_df': mod_df_for_plot, - 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and pro_installed else plot_root, + 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and C2PRO_INSTALLED else plot_root, 'save_also_png': save_png, 'sgRNA_intervals': sgRNA_intervals, 'sgRNA_names': sgRNA_names, @@ -3723,7 +3723,7 @@ def count_alternate_alleles(sub_base_vectors, ref_name, ref_sequence, ref_total_ plot_2b_input = { 'nuc_pct_df': nuc_df_for_plot.iloc[:, sel_cols], 'mod_pct_df': mod_df_for_plot.iloc[:, sel_cols], - 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and pro_installed else plot_root, + 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and C2PRO_INSTALLED else plot_root, 'save_also_png': save_png, 'sgRNA_intervals': new_sgRNA_intervals, 'sgRNA_names': sgRNA_names, @@ -4093,7 +4093,7 @@ def count_alternate_alleles(sub_base_vectors, ref_name, ref_sequence, ref_total_ plot_4g_input = { 'nuc_pct_df': hdr_nucleotide_percentage_summary_df, 'mod_pct_df': hdr_modification_percentage_summary_df, - 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and pro_installed else plot_root, + 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and C2PRO_INSTALLED else plot_root, 'save_also_png': save_png, 'sgRNA_intervals': sgRNA_intervals, 'quantification_window_idxs': include_idxs_list, @@ -4691,7 +4691,7 @@ def get_scaffold_len(row, scaffold_start_loc, scaffold_seq): plot_11a_input = { 'nuc_pct_df': pe_nucleotide_percentage_summary_df, 'mod_pct_df': pe_modification_percentage_summary_df, - 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and pro_installed else plot_root, + 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and C2PRO_INSTALLED else plot_root, 'save_also_png': save_png, 'sgRNA_intervals': sgRNA_intervals, 'sgRNA_names': sgRNA_names, @@ -4751,7 +4751,7 @@ def get_scaffold_len(row, scaffold_start_loc, scaffold_seq): plot_11b_input = { 'nuc_pct_df': pe_nucleotide_percentage_summary_df.iloc[:, sel_cols], 'mod_pct_df': pe_modification_percentage_summary_df.iloc[:, sel_cols], - 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and pro_installed else plot_root, + 'fig_filename_root': f'{_jp(pro_output_name)}' if not args.use_matplotlib and C2PRO_INSTALLED else plot_root, 'save_also_png': save_png, 'sgRNA_intervals': new_sgRNA_intervals, 'sgRNA_names': sgRNA_names, diff --git a/CRISPResso2/CRISPRessoCompareCORE.py b/CRISPResso2/CRISPRessoCompareCORE.py index 57dd2d51..41759b65 100644 --- a/CRISPResso2/CRISPRessoCompareCORE.py +++ b/CRISPResso2/CRISPRessoCompareCORE.py @@ -10,11 +10,6 @@ import traceback import argparse from CRISPResso2 import CRISPRessoShared -try: - from CRISPRessoPro import __version__ - pro_installed = True -except: - pro_installed = False from CRISPResso2.CRISPRessoReports import CRISPRessoReport import logging @@ -113,7 +108,7 @@ def main(): args = parser.parse_args() - if args.use_matplotlib or not pro_installed: + if args.use_matplotlib or not CRISPRessoShared.is_C2Pro_installed(): from CRISPResso2 import CRISPRessoPlot else: from CRISPRessoPro import plot as CRISPRessoPlot diff --git a/CRISPResso2/CRISPRessoMetaCORE.py b/CRISPResso2/CRISPRessoMetaCORE.py index 7c855af3..c1de9b8a 100644 --- a/CRISPResso2/CRISPRessoMetaCORE.py +++ b/CRISPResso2/CRISPRessoMetaCORE.py @@ -13,11 +13,6 @@ import traceback import json from CRISPResso2 import CRISPRessoShared -try: - from CRISPRessoPro import __version__ - pro_installed = True -except: - pro_installed = False from CRISPResso2 import CRISPRessoMultiProcessing from CRISPResso2.CRISPRessoReports import CRISPRessoReport @@ -100,7 +95,7 @@ def main(): args = parser.parse_args() - if args.use_matplotlib or not pro_installed: + if args.use_matplotlib or not CRISPRessoShared.is_C2Pro_installed(): from CRISPResso2 import CRISPRessoPlot else: from CRISPRessoPro import plot as CRISPRessoPlot diff --git a/CRISPResso2/CRISPRessoPooledCORE.py b/CRISPResso2/CRISPRessoPooledCORE.py index 87ac8f17..e8aa2132 100644 --- a/CRISPResso2/CRISPRessoPooledCORE.py +++ b/CRISPResso2/CRISPRessoPooledCORE.py @@ -19,11 +19,7 @@ from CRISPResso2 import CRISPRessoShared from CRISPResso2 import CRISPRessoMultiProcessing from CRISPResso2.CRISPRessoReports import CRISPRessoReport -try: - from CRISPRessoPro import __version__ - pro_installed = True -except: - pro_installed = False + import traceback import logging @@ -339,7 +335,7 @@ def main(): args = parser.parse_args() - if args.use_matplotlib or not pro_installed: + if args.use_matplotlib or not CRISPRessoShared.is_C2Pro_installed(): from CRISPResso2 import CRISPRessoPlot else: from CRISPRessoPro import plot as CRISPRessoPlot diff --git a/CRISPResso2/CRISPRessoShared.py b/CRISPResso2/CRISPRessoShared.py index f0dfe142..a90a0ec6 100644 --- a/CRISPResso2/CRISPRessoShared.py +++ b/CRISPResso2/CRISPRessoShared.py @@ -24,12 +24,6 @@ import logging from inspect import getmodule, stack -try: - from CRISPRessoPro import __version__ - pro_installed = True -except: - pro_installed = False - from CRISPResso2 import CRISPResso2Align from CRISPResso2 import CRISPRessoCOREResources @@ -1987,7 +1981,7 @@ def zip_results(results_folder): def is_C2Pro_installed(): try: - spec = importlib.util.find_spec("crispressoPro") + spec = importlib.util.find_spec("CRISPRessoPro") if spec is None: return False else: @@ -2032,8 +2026,7 @@ def check_custom_config(args): logger = logging.getLogger(getmodule(stack()[1][0]).__name__) #Check if crispresso.pro is installed - # if not is_C2Pro_installed(): - if not pro_installed: + if not is_C2Pro_installed(): return config if args.config_file: try: diff --git a/CRISPResso2/CRISPRessoWGSCORE.py b/CRISPResso2/CRISPRessoWGSCORE.py index bcb9de93..8f17ae6d 100644 --- a/CRISPResso2/CRISPRessoWGSCORE.py +++ b/CRISPResso2/CRISPRessoWGSCORE.py @@ -19,12 +19,6 @@ from CRISPResso2 import CRISPRessoShared from CRISPResso2 import CRISPRessoMultiProcessing from CRISPResso2.CRISPRessoReports import CRISPRessoReport -try: - from CRISPRessoPro import __version__ - pro_installed = True -except: - pro_installed = False - import logging @@ -350,7 +344,7 @@ def print_stacktrace_if_debug(): args = parser.parse_args() - if args.use_matplotlib or not pro_installed: + if args.use_matplotlib or not CRISPRessoShared.is_C2Pro_installed(): from CRISPResso2 import CRISPRessoPlot else: from CRISPRessoPro import plot as CRISPRessoPlot diff --git a/scripts/plotAmbiguous.py b/scripts/plotAmbiguous.py index 675300e2..3a63281f 100644 --- a/scripts/plotAmbiguous.py +++ b/scripts/plotAmbiguous.py @@ -9,11 +9,7 @@ import numpy as np import pandas as pd import zipfile -try: - from CRISPRessoPro import __version__ - pro_installed = True -except: - pro_installed = False + from CRISPResso2 import CRISPRessoShared def main(): @@ -31,7 +27,7 @@ def main(): args = parser.parse_args() - if args.use_matplotlib or not pro_installed: + if args.use_matplotlib or not CRISPRessoShared.is_C2Pro_installed(): from CRISPResso2 import CRISPRessoPlot else: from CRISPRessoPro import plot as CRISPRessoPlot diff --git a/scripts/plotCustomAllelePlot.py b/scripts/plotCustomAllelePlot.py index e675e0d6..c623909d 100644 --- a/scripts/plotCustomAllelePlot.py +++ b/scripts/plotCustomAllelePlot.py @@ -9,11 +9,6 @@ import numpy as np import pandas as pd import zipfile -try: - from CRISPRessoPro import __version__ - pro_installed = True -except: - pro_installed = False from CRISPResso2 import CRISPRessoShared import seaborn as sns import matplotlib @@ -39,7 +34,7 @@ def main(): help='Use matplotlib for plotting instead of plotly/d3 when CRISPRessoPro is installed') args = parser.parse_args() - if args.use_matplotlib or not pro_installed: + if args.use_matplotlib or not CRISPRessoShared.is_C2Pro_installed(): from CRISPResso2 import CRISPRessoPlot else: from CRISPRessoPro import plot as CRISPRessoPlot