Skip to content

Commit

Permalink
improve mosek license check, make reduce_fasta a library
Browse files Browse the repository at this point in the history
rename pre_filtered bed to unfiltered_gain and put in cnvkit directory
  • Loading branch information
jluebeck committed May 1, 2024
1 parent a33a3f1 commit b494f24
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
28 changes: 17 additions & 11 deletions AmpliconSuite-pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import tarfile
import time

from paalib import check_reference, cnv_prefilter
from paalib import check_reference, cnv_prefilter, reduce_fasta
from paalib._version import __ampliconsuitepipeline_version__


Expand Down Expand Up @@ -166,9 +166,7 @@ def run_cnvkit(ckpy_path, nthreads, outdir, bamfile, seg_meth='cbs', normal=None
logging.info("Running CNVKit batch\n")
if normal and not args.ref == "GRCh38_viral":
# create a version of the stripped reference
scripts_dir = os.path.dirname(os.path.abspath(__file__)) + "/scripts/"
strip_cmd = "python {}reduce_fasta.py -r {} -c {} -o {}".format(scripts_dir, ref_fasta, ref_genome_size_file, outdir)
call(strip_cmd, shell=True)
reduce_fasta.reduce_fasta(ref_fasta, ref_genome_size_file, outdir)
base = os.path.basename(ref_fasta) # args.ref is the name, ref is the fasta
stripRefG = outdir + os.path.splitext(base)[0] + "_reduced" + "".join(os.path.splitext(base)[1:])
logging.debug("Stripped reference: " + stripRefG)
Expand Down Expand Up @@ -824,11 +822,16 @@ def contains_spaces(file_path):

if args.run_AA:
if not os.path.exists(os.environ["HOME"] + "/mosek/mosek.lic") and not "MOSEKLM_LICENSE_FILE" in os.environ:
logging.error("--run_AA set, but MOSEK license not found!")
logging.error("--run_AA set, but MOSEK license not found in $HOME/mosek/")
sys.exit(1)

elif "MOSEKLM_LICENSE_FILE" in os.environ and not os.path.exists(os.environ["MOSEKLM_LICENSE_FILE"] + "/mosek.lic"):
logging.error("--run_AA set, but MOSEK license not found!")
elif "MOSEKLM_LICENSE_FILE" in os.environ:
if os.environ["MOSEKLM_LICENSE_FILE"].endswith("mosek.lic"):
logging.error("MOSEKLM_LICENSE_FILE should be the path of the directory of the license, not the full path. Please update your .bashrc, and run 'source ~/.bashrc'")
sys.exit(1)

elif not os.path.exists(os.environ["MOSEKLM_LICENSE_FILE"] + "/mosek.lic"):
logging.error("--run_AA set, but MOSEK license not found in " + os.environ["MOSEKLM_LICENSE_FILE"])
sys.exit(1)

runCNV = None
Expand Down Expand Up @@ -975,6 +978,7 @@ def contains_spaces(file_path):
centromere_dict = get_ref_centromeres(args.ref)
chr_sizes = get_ref_sizes(ref_genome_size_file)
# coordinate CNV calling
cnvkit_output_directory = None
if runCNV == "CNVkit":
cnvkit_output_directory = args.output_directory + sname + "_cnvkit_output/"
if not os.path.exists(cnvkit_output_directory):
Expand All @@ -1001,17 +1005,19 @@ def contains_spaces(file_path):
sample_info_dict["sample_cnv_bed"] = args.cnv_bed

if not args.no_filter and not args.cnv_bed.endswith("_AA_CNV_SEEDS.bed"):
if not args.cnv_bed.endswith("_CNV_CALLS_pre_filtered.bed"):
if not args.cnv_bed.endswith("_CNV_CALLS_pre_filtered.bed") and not args.cnv_bed.endswith("_CNV_CALLS_unfiltered_gains.bed"):
pfilt_odir = cnvkit_output_directory if cnvkit_output_directory else args.output_directory
args.cnv_bed = cnv_prefilter.prefilter_bed(args.cnv_bed, args.ref, centromere_dict, chr_sizes,
args.cngain, args.output_directory)
args.cngain, pfilt_odir)

amplified_interval_bed = run_amplified_intervals(args.aa_python_interpreter, args.cnv_bed, args.bam,
outdir, sname, args.cngain, args.cnsize_min)

elif args.no_filter and runCNV:
if not args.cnv_bed.endswith("_CNV_CALLS_pre_filtered.bed"):
if not args.cnv_bed.endswith("_CNV_CALLS_pre_filtered.bed") and not args.cnv_bed.endswith("_CNV_CALLS_unfiltered_gains.bed"):
pfilt_odir = cnvkit_output_directory if cnvkit_output_directory else args.output_directory
args.cnv_bed = cnv_prefilter.prefilter_bed(args.cnv_bed, args.ref, centromere_dict, chr_sizes,
args.cngain, args.output_directory)
args.cngain, pfilt_odir)
logging.info("Skipping amplified_intervals.py step due to --no_filter")

else:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ AmpliconSuite-pipeline can also be run through Nextflow, using the [nf-core/circ

### Option B: Conda or Mamba
```bash
conda create -n ampsuite && conda activate ampsuite
conda install -c bioconda -c mosek -c conda-forge ampliconsuite mosek
conda create -n ampsuite python=3.10 && conda activate ampsuite
conda install -c bioconda -c conda-forge ampliconsuite
conda install -c mosek mosek

# then run the installer script to finalize the locations of the data repo and mosek license
wget https://raw.githubusercontent.com/AmpliconSuite/AmpliconSuite-pipeline/master/install.sh
Expand Down
3 changes: 3 additions & 0 deletions docker/run_paa_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ def metadata_helper(metadata_args):
try:
# deprecated install of mosek license
MOSEKLM_LICENSE_FILE = os.environ['MOSEKLM_LICENSE_FILE']
if MOSEKLM_LICENSE_FILE.endswith("mosek.lic"):
sys.stderr.write(
"MOSEKLM_LICENSE_FILE should be the path of the directory of the license, not the full path. Please update your .bashrc, and run 'source ~/.bashrc'\n")
if not os.path.exists(MOSEKLM_LICENSE_FILE + "/mosek.lic"):
raise KeyError

Expand Down
2 changes: 1 addition & 1 deletion paalib/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__ampliconsuitepipeline_version__ = "1.3.1"
__ampliconsuitepipeline_version__ = "1.3.2"
2 changes: 1 addition & 1 deletion paalib/cnv_prefilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def prefilter_bed(bedfile, ref, centromere_dict, chr_sizes, cngain, outdir):

merged_filt_ivald = merge_intervals(filt_ivald, cn_cut=cngain, require_same_cn=True, ref=ref)
final_filt_entries = ivald_to_ilist(merged_filt_ivald)
bname = outdir + "/" + bedfile.rsplit("/")[-1].rsplit(".bed")[0] + "_pre_filtered.bed"
bname = outdir + "/" + bedfile.rsplit("/")[-1].rsplit(".bed")[0] + "_unfiltered_gains.bed"
with open(bname, 'w') as outfile:
for entry in final_filt_entries:
outfile.write("\t".join([str(x) for x in entry]) + "\n")
Expand Down
23 changes: 13 additions & 10 deletions scripts/reduce_fasta.py → paalib/reduce_fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ def fasta_reader(fasta_file, chroms_to_get):
return fasta_dict


def reduce_fasta(ref, chrom, outname=""):
chrList = getRelChrs(chrom)
seqD = fasta_reader(ref, chrList)
base = os.path.basename(ref)
refGOutName = os.path.splitext(base)[0] + "_reduced" + "".join(os.path.splitext(base)[1:])
print("Writing stripped FASTA\n")
with open(outname + refGOutName, 'w') as outfile:
for i in chrList:
outfile.write(">" + i + "\n")
outfile.write(seqD[i] + "\n")


if __name__ == '__main__':
# Parses the command line arguments
parser = argparse.ArgumentParser(description="Reduce FASTA to entries in list")
Expand All @@ -50,14 +62,5 @@ def fasta_reader(fasta_file, chroms_to_get):
if not args.outname:
args.outname = ""

chrList = getRelChrs(args.chrom)
seqD = fasta_reader(args.ref, chrList)
base = os.path.basename(args.ref)
refGOutName = os.path.splitext(base)[0] + "_reduced" + "".join(os.path.splitext(base)[1:])
print("Writing stripped FASTA\n")
with open(args.outname + refGOutName, 'w') as outfile:
for i in chrList:
outfile.write(">" + i + "\n")
outfile.write(seqD[i] + "\n")

reduce_fasta(args.ref, args.chrom, args.outname)
sys.exit()
1 change: 1 addition & 0 deletions singularity/run_paa_singularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def metadata_helper(metadata_args):


if not os.path.exists(os.environ['HOME'] + "/mosek/mosek.lic"):
sys.stdout.write("Python detected $HOME was set to: " + os.environ['HOME'])
sys.stderr.write(
"Mosek license (mosek.lic) file not found in $HOME/mosek/. Please see README for instructions.\n")
sys.exit(1)
Expand Down

0 comments on commit b494f24

Please sign in to comment.