dcouvin / CRISPRCasFinder

A Perl script allowing to identify CRISPR arrays and associated Cas proteins from DNA sequences
https://crisprcas.i2bc.paris-saclay.fr
GNU General Public License v3.0
80 stars 28 forks source link

error in using crisprcasfinder with subprocess, snakemake and Rscript #47

Open mf116 opened 1 year ago

mf116 commented 1 year ago

when i use subprocess, the error coming from using subprocess is /home/DRs_1 permission required. when i use snakemkae, the error is related to after refining and generating the fasta file from my input and says, no such file or directory 'CPXXXXXX.fna' when i use Rscript the error is, please provide fasta file with -in, even thoug it is provided.

i am trying to batch analyse multiple fasta files

dcouvin commented 1 year ago

Hi @mf116, Thank you for your message. We will try to see why this error is occurring when using subprocess, snakemake or Rscript. Best regards, David

mf116 commented 1 year ago

Hi @dcouvin,

Were you able to figure out what is happening?

Best Regards, Marc

dcouvin commented 1 year ago

Dear Marc (@mf116 ), Thank you for your message. I haven't had time to try with subprocess, snakemake and Rscript yet. Please send me the command lines (I will try to run the tool the same way you did). Did you use the last version of the program (4.3.2) ? Thank you in advance. Best Regards, David

mf116 commented 1 year ago

Dear David (@dcouvin),

i will add the scripts as a following text for each. kindly note that the following tests were run on terminal and worked, but writing a bash command in text editor and running it in bash did not work. i even inserted the arguments as path instead of the assigned variables for testing purposes. i did not include all the path location, but while running the script the full path was used.

Rscript:

fasta <- "CRISPRCasFinder-master/install_test/sequence.fasta"
out <- "CRISPRCasFinder-master/install_test/Res"
workdir <- "CRISPRCasFinder-master/install_test"
command <- paste0("CRISPRCasFinder.pl -in CRISPRCasFinder-master/install_test/sequence.fasta -o CRISPRCasFinder-master/install_test/Res -so CRISPRCasFinder-master/sel392v2.so -cas -cpuM 10 -lMin 4 -faster")

setwd(workdir)
system(paste("bash", "-c", command), intern = TRUE, ignore.stderr = FALSE)

Python:

#!/usr/bin/env python
import sys
import os
import shlex, subprocess

fasta='/CRISPRCasFinder-master/install_test/sequence.fasta'
out='/CRISPRCasFinder-master/install_test/Res'
workdir='/CRISPRCasFinder-master/install_test'
command=f"CRISPRCasFinder-master/CRISPRCasFinder.pl -in '{fasta}' -o '{out}' -so 'CRISPRCasFinder-master/sel392v2.so' -cas -log -force -lMin 4"
conda_ac='cfinder'

result=subprocess.run("CRISPRCasFinder-master/CRISPRCasFinder.pl -i 'CRISPRCasFinder-master/install_test/sequence.fasta' -cas -log -out CRISPRCasFinder-master/install_test/RES_Sequence -force -so 'CRISPRCasFinder-master/sel392v2.so'", shell=True, cwd=workdir)

C++:

#include <iostream>
#include <cstdlib>
#include <string>

int main() {
    std::string fasta = "CRISPRCasFinder-master/install_test/sequence.fasta";
    std::string out = "CRISPRCasFinder-master/install_test/Res";
    std::string workdir = "CRISPRCasFinder-master/install_test";
    std::string command = "CRISPRCasFinder.pl -in " + fasta + " -o " + out + " -so CRISPRCasFinder-master/sel392v2.so -cas -cpuM 10 -lMin 4 -faster";
    std::string conda_ac = "cfinder";

    std::string fullCommand = "cd " + workdir + " && " + command;
    int result = system(fullCommand.c_str());

    if (result == 0) {
        std::cout << "Command executed successfully." << std::endl;
    } else {
        std::cout << "Command execution failed." << std::endl;
    }

    return 0;
}

Thank you,

Regards, Marc

dcouvin commented 1 year ago

Dear Marc, Thank you for your message. I will try o have a look on this issue as soon as possible. Best regards, David

mf116 commented 11 months ago

Dear David,

Kind reminder, were you able to figure out the issue i am having?

Best regards, Marc

mf116 commented 11 months ago

Dear David, i got an update, some contigs are causing this issue, i still can't figure out why, they are normal and they work on the online version, but yet i did not figure out what is the problem (all names are consistent and contain are named like this >NODE_1) the error come like this,

Sequence number 1..  ( Input file: NODE_7.fna, Sequence ID: NODE_7, Sequence name = Unknown )

muscle 5.1.linux64 []  32.6Gb RAM, 16 cores
Built May 16 2023 07:53:40
(C) Copyright 2004-2021 Robert C. Edgar.
https://drive5.com

Input: 2 seqs, avg length 32, max 34

00:00 7.4Mb  CPU has 16 cores, running 16 threads
00:00 133Mb   100.0% Calc posteriors
00:00 133Mb   100.0% UPGMA5         
Could not write file /home/DRs_1 because Permission denied

it is not related to any of my languages.

Best, Marc

aababc1 commented 11 months ago

I've encountered same problem. Would you check why this error occur ? Thank you for your work .

mf116 commented 11 months ago

I've encountered same problem. Would you check why this error occur ? Thank you for your work .

this error is happening, after i manually checked, with contigs that have evidence levels for crispr or cas. any other contigs that are negative, are not failing on the script.

fanvanf commented 8 months ago

I have also encountered a similar situation. However, after some experimentation, I managed to resolve the issue. In essence, the solution is to use a relative output path that is both readable and writable, instead of an absolute path. For example, consider using the command perl CRISPRCasFinder.pl -in /home/cloud_workdir/R3/R3.final.assembly.fasta -outdir out instead of perl CRISPRCasFinder.pl -in /home/cloud_workdir/R3/R3.final.assembly.fasta -outdir /home/cloud_workdir/R3/out. Now, let's discuss the cause of this problem. Prompted by the error message, I searched the CRISPRCasFinder.plscript for the term "DRs_" and eventually located the following lines:

 my $drFile = $tabReport[0]."/".$tabReport[1]."/"."DRs_".$idCrispr; # DC

  open(DRLIST,">",$drFile) or die("Could not write file $drFile because $!\n"); # DC

https://github.com/dcouvin/CRISPRCasFinder/blob/9a7f07edc4001875be05f6f0f0eb81f4fdf52e4d/CRISPRCasFinder.pl#L2630C1-L2633C85 I am not proficient in Perl, I am unsure about how to fix this particular error. However @setting the output path to a relative path is indeed a good compromise solution.