AfshinLab / BLR

MIT License
5 stars 0 forks source link

Unterminated f-string in extract_barcodes.py #82

Closed ajdesalvio closed 3 days ago

ajdesalvio commented 4 days ago

Using BLR version 0.5.dev17+gc5535d9 (cloned on 2024-09-21), I initialized a BLR run for a TELL-Seq sample that was terminated at snakemake step 902 of 909 with the following output in the console:

python -c "import sys; print('.'.join(map(str, sys.version_info[:2])))"
Activating conda environment: /scratch/user/ajd/cotton/output/.snakemake/conda/e88cda0f0aee7365b5537b6da42167f6
python /scratch/user/ajd/cotton/output/.snakemake/scripts/tmpar4mpl5w.extract_barcodes.py
Activating conda environment: /scratch/user/ajd/cotton/output/.snakemake/conda/e88cda0f0aee7365b5537b6da42167f6
  File "/scratch/user/ajd/cotton/output/.snakemake/scripts/tmpar4mpl5w.extract_barcodes.py", line 383
    log = f"{args.outdir}.log
          ^
SyntaxError: unterminated f-string literal (detected at line 383)
[Thu Sep 26 02:29:36 2024]
Error in rule extract_barcodes:
    jobid: 898
    output: mtglink_tmp/read_subsampling_pre
    log: mtglink_tmp/read_subsampling_pre.log (check log file(s) for error message)
    conda-env: /scratch/user/ajd/cotton/output/.snakemake/conda/e88cda0f0aee7365b5537b6da42167f6

Upon investigating the block of code near line 383 in extract_barcodes.py, there was indeed a missing quotation after the f-string, see the line log = f"{args.outdir}.log. Just bringing this to everyone's attention to hopefully avoid failed runs in the future. Thanks!

if __name__ == "__main__":
    if len(sys.argv) == 1:
        outdir = snakemake.output.dir  # noqa: F821
        bam = snakemake.input.bam  # noqa: F821
        gfa = snakemake.input.gfa  # noqa: F821
        flanksize = snakemake.params.flanksize  # noqa: F821
        minbarcocc = snakemake.params.minbarcocc  # noqa: F821
        log = snakemake.log[0]  # noqa: F821
    else:
        parser = argparse.ArgumentParser(description=__doc__)
        parser.add_argument("outdir", help="Output directory")
        parser.add_argument("--gfa", help="Input GFA file", required=True)
        parser.add_argument("--bam", help="Input BAM file", required=True)
        parser.add_argument(
            "--flanksize",
            type=int,
            default=10_000,
            help="Flank size for extracting barcodes",
        )
        parser.add_argument(
            "--minbarcocc",
            type=int,
            default=2,
            help="Minimum barcode occurence for keeping in region",
        )
        args = parser.parse_args()

        outdir = args.outdir
        gfa = args.gfa
        bam = args.bam
        flanksize = args.flanksize
        minbarcocc = args.minbarcocc
        log = f"{args.outdir}.log

    # Write stdout to log file
    with open(log, "w") as sys.stdout:
        main(outdir, gfa, bam, flanksize, minbarcocc)
pontushojer commented 3 days ago

Thanks for your issue report! I was confused as to why the linting had not found this bug but it seems the CI was not properly set up. I made a PR (#84) that should fix this.

ajdesalvio commented 3 days ago

Thank you for the quick reply!