Skip to content

Commit

Permalink
Add zip_output (#240)
Browse files Browse the repository at this point in the history
* Making zip of results

* Zip command added, if zip is true place_report_in_output_folder is also true, zip removes all files while zipping

* Adding --zip to compare and pooled/wgs compare

* Add more formatting changes to CRISPRessoShared

* Refactoring propagate_crispress_options so only one version exists

* Zip added to arguments_to_ignore and warning added when changing arguments

* Restore styling

* Update README to include --zip

* Rename --zip to --zip_output

* Change --zip to --zip_output in CompareCORE and PooledWGSCompareCORE

* Bug fix arg to args

Co-authored-by: Samuel Nichols <Snic9004@gmail.com>
  • Loading branch information
Colelyman and Snicker7 committed Aug 23, 2022
1 parent 5de3d72 commit c80f828
Show file tree
Hide file tree
Showing 8 changed files with 585 additions and 348 deletions.
45 changes: 12 additions & 33 deletions CRISPResso2/CRISPRessoBatchCORE.py
Expand Up @@ -34,37 +34,6 @@
_ROOT = os.path.abspath(os.path.dirname(__file__))

####Support functions###
def propagate_options(cmd, options, params, paramInd):
####
# cmd - the command to run
# options - list of options to propagate e.g. crispresso options
# params - df from excel parser e.g. params['amplicon_name'] = ['name1','name2','name3'] where each item corresponds to a different run in the batch
# paramInd - index in dict - this is the run number in the batch

for option in options:
if option:
if option in params:
val = params.loc[paramInd, option]
if val is None:
pass
elif str(val) == "True":
cmd += ' --%s' % option
elif str(val) == "False":
pass
elif isinstance(val, str):
if val != "":
if " " in val or "-" in val:
cmd += ' --%s "%s"' % (option, str(val)) # quotes for options with spaces
else:
cmd += ' --%s %s' % (option, str(val))
elif isinstance(val, bool):
if val:
cmd += ' --%s' % option
else:
cmd += ' --%s %s' % (option, str(val))
# print("cmd is " + str(cmd))
return cmd

def check_library(library_name):
try:
return __import__(library_name)
Expand Down Expand Up @@ -107,11 +76,15 @@ def main():
debug_flag = args.debug

crispresso_options = CRISPRessoShared.get_crispresso_options()
options_to_ignore = {'name', 'output_folder'}
options_to_ignore = {'name', 'output_folder', 'zip_output'}
crispresso_options_for_batch = list(crispresso_options-options_to_ignore)

CRISPRessoShared.check_file(args.batch_settings)

if args.zip_output and not args.place_report_in_output_folder:
logger.warn('Invalid arguement combination: If zip_output is True then place_report_in_output_folder must also be True. Setting place_report_in_output_folder to True.')
args.place_report_in_output_folder = True

batch_folder_name = os.path.splitext(os.path.basename(args.batch_settings))[0]
if args.name and args.name != "":
clean_name = CRISPRessoShared.slugify(args.name)
Expand Down Expand Up @@ -298,7 +271,7 @@ def main():
batch_input_names[batch_name] = row["name"]

crispresso_cmd = args.crispresso_command + ' -o "%s" --name %s' % (OUTPUT_DIRECTORY, batch_name)
crispresso_cmd = propagate_options(crispresso_cmd, crispresso_options_for_batch, batch_params, idx)
crispresso_cmd = CRISPRessoShared.propagate_crispresso_options(crispresso_cmd, crispresso_options_for_batch, batch_params, idx)
if row.amplicon_seq == "":
crispresso_cmd += ' --auto '
crispresso_cmds.append(crispresso_cmd)
Expand Down Expand Up @@ -931,6 +904,12 @@ def main():
crispresso2_info,
)
info('Analysis Complete!')
if args.zip_output:
if args.output_folder == "":
path_value = os.path.split(OUTPUT_DIRECTORY)
CRISPRessoShared.zip_results(path_value[1])
else:
CRISPRessoShared.zip_results(OUTPUT_DIRECTORY)
print(CRISPRessoShared.get_crispresso_footer())
sys.exit(0)

Expand Down
5 changes: 5 additions & 0 deletions CRISPResso2/CRISPRessoCORE.py
Expand Up @@ -975,6 +975,9 @@ def print_stacktrace_if_debug():
CRISPRessoShared.check_file(aln_matrix_loc)
aln_matrix = CRISPResso2Align.read_matrix(aln_matrix_loc)

if args.zip_output:
args.place_report_in_output_folder = True

n_processes = 1
if args.n_processes == "max":
n_processes = CRISPRessoMultiProcessing.get_max_processes()
Expand Down Expand Up @@ -4816,6 +4819,8 @@ def get_scaffold_len(row, scaffold_start_loc, scaffold_seq):
crispresso2_info_file,
crispresso2_info,
)
if args.zip_output:
CRISPRessoShared.zip_results(OUTPUT_DIRECTORY)

info('Analysis Complete!')
print(CRISPRessoShared.get_crispresso_footer())
Expand Down
8 changes: 7 additions & 1 deletion CRISPResso2/CRISPRessoCompareCORE.py
Expand Up @@ -92,12 +92,15 @@ def main():
parser.add_argument('--max_rows_alleles_around_cut_to_plot', type=int, help='Maximum number of rows to report in the alleles table plot. ', default=50)
parser.add_argument('--suppress_report', help='Suppress output report', action='store_true')
parser.add_argument('--place_report_in_output_folder', help='If true, report will be written inside the CRISPResso output folder. By default, the report will be written one directory up from the report output.', action='store_true')
parser.add_argument('--zip_output', help="If set, the output will be placed in a zip folder.", action='store_true')
parser.add_argument('--debug', help='Show debug messages', action='store_true')

args = parser.parse_args()
debug_flag = args.debug


if args.zip_output and not args.place_report_in_output_folder:
logger.warn('Invalid arguement combination: If zip_output is True then place_report_in_output_folder must also be True. Setting place_report_in_output_folder to True.')
args.place_report_in_output_folder = True
#check that the CRISPResso output is present and fill amplicon_info
quantification_file_1, amplicon_names_1, amplicon_info_1=CRISPRessoShared.check_output_folder(args.crispresso_output_folder_1)
quantification_file_2, amplicon_names_2, amplicon_info_2=CRISPRessoShared.check_output_folder(args.crispresso_output_folder_2)
Expand Down Expand Up @@ -433,6 +436,9 @@ def get_plot_title_with_ref_name(plotTitle, refName):

CRISPRessoShared.write_crispresso_info(crispresso2Compare_info_file, crispresso2_info)

if args.zip_output:
CRISPRessoShared.zip_results(OUTPUT_DIRECTORY)

info('Analysis Complete!')
print(CRISPRessoShared.get_crispresso_footer())
sys.exit(0)
Expand Down
8 changes: 7 additions & 1 deletion CRISPResso2/CRISPRessoPooledCORE.py
Expand Up @@ -282,11 +282,14 @@ def main():
args = parser.parse_args()

crispresso_options = CRISPRessoShared.get_crispresso_options()
options_to_ignore = {'fastq_r1', 'fastq_r2', 'amplicon_seq', 'amplicon_name', 'output_folder', 'name'}
options_to_ignore = {'fastq_r1', 'fastq_r2', 'amplicon_seq', 'amplicon_name', 'output_folder', 'name', 'zip_output'}
crispresso_options_for_pooled = list(crispresso_options-options_to_ignore)

files_to_remove = []

if args.zip_output and not args.place_report_in_output_folder:
logger.warn('Invalid arguement combination: If zip_output is True then place_report_in_output_folder must also be True. Setting place_report_in_output_folder to True.')
args.place_report_in_output_folder = True

info('Checking dependencies...')

Expand Down Expand Up @@ -1595,6 +1598,9 @@ def default_sigpipe():
crispresso2_info_file, crispresso2_info,
)

if args.zip_output:
CRISPRessoShared.zip_results(OUTPUT_DIRECTORY)

info('All Done!')
print(CRISPRessoShared.get_crispresso_footer())
sys.exit(0)
Expand Down
8 changes: 8 additions & 0 deletions CRISPResso2/CRISPRessoPooledWGSCompareCORE.py
Expand Up @@ -161,6 +161,7 @@ def main():
help='Show debug messages',
action='store_true',
)
parser.add_argument('--zip_output', help="If set, the output will be placed in a zip folder.", action='store_true')

args = parser.parse_args()
debug_flag = args.debug
Expand All @@ -174,6 +175,10 @@ def main():
'debug',
]

if args.zip_output and not args.place_report_in_output_folder:
logger.warn('Invalid arguement combination: If zip_output is True then place_report_in_output_folder must also be True. Setting place_report_in_output_folder to True.')
args.place_report_in_output_folder = True

sample_1_name = CRISPRessoShared.slugify(args.sample_1_name)
sample_2_name = CRISPRessoShared.slugify(args.sample_2_name)

Expand Down Expand Up @@ -366,6 +371,9 @@ def main():
crispresso2Compare_info_file, crispresso2_info,
)

if args.zip_output:
CRISPRessoShared.zip_results(OUTPUT_DIRECTORY)

info('All Done!')
print(CRISPRessoShared.get_crispresso_footer())
sys.exit(0)
Expand Down

0 comments on commit c80f828

Please sign in to comment.