bio15anu / revelio

A lightweight utility for BS-seq and MethylC-seq data which applies a double-masking procedure on bisulfite alignments, facilitating variant calling with conventional software.
MIT License
4 stars 4 forks source link

invalid cross-device link error and possible fix #4

Closed lnblum closed 7 months ago

lnblum commented 1 year ago

Hi,

Thanks for your work on this tool, the method is a nice advancement!

I was running revelio on an HPC and received this error, which is related to the temp directory being a different disk. I think this issue may affect others working on computing clusters.

Traceback (most recent call last):                                                                                                                                                                                   │···············
  File "revelio.py", line 445, in <module>                                                                                                                                       │···············
    main(args.inbam,args.outbam,args.QUALITY,args.THREADS,args.temp,args.fasta)                                                                                                                                      │···············
  File "revelio.py", line 119, in main                                                                                                                                           │···············
    if isinstance(bam, str): os.replace(bam, OUT)                                                                                                                                                                    │···············
OSError: [Errno 18] Invalid cross-device link: '/sge_tmp/1284423.1.all.q/tmp02t88d1k/tmpg1oql8sc' -> 'sample1.masked.bam' 

I tested a fix for this error, which works for me: using shutil.move instead of os.replace. Here is an explanation from the shutil.move documentation: "If the destination is on the current filesystem, then os.rename() is used. Otherwise, src is copied to dst using copy_function and then removed."

I couldn't open a PR, but here is the minor change I made:

 import argparse, tempfile, resource, os
 import pysam
 from array import array
+import shutil

 ££££££££££££££££££
@@ -116,8 +117,8 @@ def main(BAM,OUT,QUALITY,THREADS=1,TEMP=None,FASTA=None):
        pool.join()

        £ output the final file
-       if isinstance(bam, str): os.replace(bam, OUT)
-       else: os.replace(bam[0], OUT)
+       if isinstance(bam, str): shutil.move(bam, OUT)
+       else: shutil.move(bam[0], OUT)

If you think this is appropriate perhaps consider this modification.

Best, Laura

bio15anu commented 1 year ago

Hi Laura,

Thanks for your feedback! Sorry to hear that you ran into to issues with the temp directory. It should also work to use the -t option and point to a different location for the temp directory [default: /var/tmp] so that it is on the same disk? Would that also be a solution for you in this case, or is there perhaps something more going on?

Best regards, Adam

lnblum commented 1 year ago

Hi Adam,

Yes the -t option also works for this. Thanks for the reminder!

Laura