Skip to content

Commit

Permalink
remove_file fix and type fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sigven committed Jan 4, 2024
1 parent 30df312 commit 5a94eb3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions pcgr/arg_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ def check_args(arg_dict):
err_msg = f"Minimum sequencing depth tumor - TMB calculation ('tmb_dp_min' = {arg_dict['tmb_dp_min']}) must be >= 0"
error_message(err_msg, logger)

if int(arg_dict['tmb_dp_min']) < int(arg_dict['tumor_dp_min']):
err_msg = f"Minimum sequencing depth (tumor) for TMB calculation ('tmb_dp_min' = {arg_dict['tmb_dp_min']}) must be ",
err_msg += f"greater or equal to minimum sequencing depth tumor {arg_dict['tumor_dp_min']} (i.e. filter for variant inclusion in report)"
if int(arg_dict['tmb_dp_min']) > 0 and (int(arg_dict['tmb_dp_min']) < int(arg_dict['tumor_dp_min'])):
err_msg = f"Minimum sequencing depth (tumor) for TMB calculation ('tmb_dp_min' = {str(arg_dict['tmb_dp_min'])}) must be ",
err_msg += f"greater or equal to minimum sequencing depth tumor {str(arg_dict['tumor_dp_min'])} (i.e. filter for variant inclusion in report)"
error_message(err_msg, logger)

if float(arg_dict['tmb_af_min']) < 0 or float(arg_dict['tmb_af_min']) > 1:
err_msg = f"Minimum AF (tumor) for TMB calculation ('tmb_af_min' = {arg_dict['tmb_af_min']}) must be within [0, 1]"
error_message(err_msg, logger)

if float(arg_dict['tmb_af_min']) < float(arg_dict['tumor_af_min']):
err_msg = f"Minimum AF (tumor) for TMB calculation ('tmb_af_min' = {arg_dict['tmb_af_min']}) must be ",
err_msg += f"greater or equal to minimum AF tumor {arg_dict['tumor_dp_min']} (i.e. filter for variant inclusion in report)"
if float(arg_dict['tmb_af_min']) > 0 and (float(arg_dict['tmb_af_min']) < float(arg_dict['tumor_af_min'])):
err_msg = f"Minimum AF (tumor) for TMB calculation ('tmb_af_min' = {str(arg_dict['tmb_af_min'])}) must be ",
err_msg += f"greater or equal to minimum AF tumor {str(arg_dict['tumor_dp_min'])} (i.e. filter for variant inclusion in report)"
error_message(err_msg, logger)

# Check that coding target size region of sequencing assay is set correctly
Expand Down
6 changes: 3 additions & 3 deletions pcgr/cpsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from glob import glob
from argparse import RawTextHelpFormatter
from pcgr import pcgr_vars, arg_checker, utils, vep, config, variant
from pcgr.utils import check_subprocess, getlogger, error_message, warn_message
from pcgr.utils import check_subprocess, getlogger, error_message, warn_message, remove_file
from pcgr.config import populate_config_data

def get_args():
Expand Down Expand Up @@ -267,7 +267,7 @@ def run_cpsr(conf_options, cpsr_paths):
# do not delete if debugging
if not debug:
for fn in delete_files:
utils.remove(fn)
remove_file(fn)
logger.info('Finished cpsr-summarise main command')

# CPSR|vcf2tsvpy - convert VCF to TSV with https://github.com/sigven/vcf2tsvpy
Expand All @@ -291,7 +291,7 @@ def run_cpsr(conf_options, cpsr_paths):

variant_set.to_csv(output_pass_tsv_gz, sep="\t", compression="gzip", index=False)
if not debug:
utils.remove(output_pass_vcf2tsv_gz)
remove_file(output_pass_vcf2tsv_gz)

logger.info('Finished cpsr-summarise')

Expand Down
2 changes: 1 addition & 1 deletion pcgr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def sort_bed(unsorted_bed_fname: str, sorted_bed_fname: str, debug = False, logg
check_subprocess(logger, cmd_sort_custom_bed1, debug)
check_subprocess(logger, cmd_sort_custom_bed2, debug)
if not debug:
remove(str(unsorted_bed_fname))
remove_file(str(unsorted_bed_fname))
else:
err_msg = 'File ' + str(unsorted_bed_fname) + ' does not exist or is empty'
error_message(err_msg, logger)
Expand Down
4 changes: 2 additions & 2 deletions pcgr/variant.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ def clean_annotations(variant_set: pd.DataFrame, yaml_data: dict, germline: bool
for tag in ['AN','AC','NHOMALT']:
vcf_info_tag = 'gnomADe_non_cancer_' + str(pop) + '_' + str(tag)
if vcf_info_tag in variant_set.columns:
variant_set[vcf_info_tag] = variant_set[vcf_info_tag].astype(str)
#variant_set[vcf_info_tag] = variant_set[vcf_info_tag].astype(str)

variant_set.loc[variant_set[vcf_info_tag].notna(), vcf_info_tag] = \
variant_set.loc[variant_set[vcf_info_tag].notna(), vcf_info_tag].astype(float).astype(int)
variant_set.loc[variant_set[vcf_info_tag].notna(), vcf_info_tag].astype(str).astype(float).astype(int)

for elem in ['NUM_SUBMITTERS','ALLELE_ID','ENTREZGENE','REVIEW_STATUS_STARS']:
vcf_info_tag = 'CLINVAR_' + str(elem)
Expand Down
8 changes: 4 additions & 4 deletions scripts/cpsr_validate_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from cyvcf2 import VCF
from pcgr import utils, annoutils, vcf, pcgr_vars
from pcgr.utils import error_message, check_subprocess, random_id_generator, sort_bed, check_file_exists
from pcgr.utils import error_message, check_subprocess, random_id_generator, sort_bed, check_file_exists, remove_file


def __main__():
Expand Down Expand Up @@ -262,10 +262,10 @@ def simplify_vcf(input_vcf, validated_vcf, vcf, custom_bed, pcgr_directory, geno
bcftools_simplify_log,
vt_decompose_log]:
#print(f"Deleting {fn}")
utils.remove(fn)
remove_file(fn)

utils.remove(temp_files["vcf_2"] + str('.tbi'))
utils.remove(temp_files["vcf_3"] + str('.tbi'))
remove_file(temp_files["vcf_2"] + str('.tbi'))
remove_file(temp_files["vcf_3"] + str('.tbi'))

if check_file_exists(f'{validated_vcf}.gz'):
vcf = VCF(validated_vcf + '.gz')
Expand Down

0 comments on commit 5a94eb3

Please sign in to comment.