Skip to content

Commit

Permalink
- refactored import check to shared function
Browse files Browse the repository at this point in the history
- global in CORE formatting change
  • Loading branch information
mbowcut2 committed Mar 29, 2024
1 parent 05104ae commit e9cabb9
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 70 deletions.
8 changes: 1 addition & 7 deletions CRISPResso2/CRISPRessoAggregateCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions CRISPResso2/CRISPRessoBatchCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions CRISPResso2/CRISPRessoCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 1 addition & 6 deletions CRISPResso2/CRISPRessoCompareCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions CRISPResso2/CRISPRessoMetaCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions CRISPResso2/CRISPRessoPooledCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions CRISPResso2/CRISPRessoShared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 1 addition & 7 deletions CRISPResso2/CRISPRessoWGSCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions scripts/plotAmbiguous.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions scripts/plotCustomAllelePlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e9cabb9

Please sign in to comment.