streetslab / dimelo

python package for analysis of dimelo-seq & nanopore modified base data
MIT License
3 stars 4 forks source link

Current examples break in WSL because of path strings #5

Closed thekugelmeister closed 2 years ago

thekugelmeister commented 2 years ago

I am using the Windows Linux Subsystem to test this. When I try to run the example code from the documentation, e.g.

dm.parse_bam("dimelo/test/data/mod_mappings_subset.bam", "test", "/dimelo/dimelo_test", bedFile="dimelo/test/data/test.bed", basemod="A+CG", center=True, windowSize=500, threshA=190, threshC=190, extractAllBases=False, cores=8)

I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/thekugelmeister/devspace/streets_rotation/dimelo/dimelo/parse_bam.py", line 207, in parse_bam
    make_db(fileName, sampleName, outDir, testMode, qc, joint)
  File "/home/thekugelmeister/devspace/streets_rotation/dimelo/dimelo/parse_bam.py", line 68, in make_db
    os.mkdir(outDir)
FileNotFoundError: [Errno 2] No such file or directory: '/dimelo/dimelo_test'

Removing the leading forward slash from the output file argument fixes the problem. Somehow, the file specifications are not system-agnostic right now.

thekugelmeister commented 2 years ago

I have not diagnosed why this occurs, but I propose the following solution:

Use pathlib.Path objects for handling paths

Rather than go through the hassle of diagnosing the problem and implementing a fix, why not let python's builtin path abstraction capabilities do the job for us? See https://docs.python.org/3/library/pathlib.html for more detail.

thekugelmeister commented 2 years ago

Clarification: adding pathlib will not actually address this issue, as the preceding forward slash makes it a valid file path that points somewhere different. However, adding more robust path handling will help future-proof in other ways.

amaslan commented 2 years ago

On cleanup branch removed preceding forward slash in examples since that was an error, and I agree implementing pathlib sounds great.

amaslan commented 2 years ago

After discussion decided will eventually switch to pathlib and will use moving forward but for now the issue is fixed by providing a valid file path for example code.