Asked  1 Year ago    Answers:  5   Viewed   10 times

I'm using the PHP exec() function to execute the Canu assembler programs, and I want to get its process ID within the same script.

The problem is exec() not returning any PID, even the process is running successfully.

The processes are started like this:

$gnuplot_path = '/usr/bin/gnuplot';

$command = 'nohup canu -d . -p E.coli gnuplot='.$gnuplot_path.' genomeSize=4.8m useGrid=false maxThreads=30 -pacbio-raw /path/to/p6.25x.fastq > /path/to/process.err 2>&1 &';

Currently, I try to determine if the process is still running by:

$pid = exec($command, $output);
var_dump($pid);

and also this:

exec($command, $pid, $return_var);
print_r($pid);
echo "$return_varn";

However, I got output of string(0) "" and Array ( ) 0 respectively.

Please let me know how to solve this. Thanks much.

 Answers

1

This one is tricky. What I would do:

$gnuplot_path = '/usr/bin/gnuplot';
$command = 'nohup canu -d . -p E.coli gnuplot='.$gnuplot_path.' genomeSize=4.8m useGrid=false maxThreads=30 -pacbio-raw /path/to/p6.25x.fastq > /path/to/process.err 2>&1';
$command .= ' & echo $!';

$pid = exec($command, $output, $a);
var_dump($output[0]);
Saturday, May 29, 2021
 
Deyson
 
3

SVN command line errors go to stderr, not stdout, which is why you aren't able to see them. What you want to do is redirect stderr to stdout and then print_r($output) to determine the cause of the error.

exec('svn commit <stuff> 2>&1', $output, $returnStatus);
if ( $returnStatus )
{
    print_r($output);
}

Sample output:

Array
(
    [0] => svn: Commit failed (details follow):
    [1] => svn: '/path/to/<stuff>' is not under version control
)

This is not ideal because it mixes stderr with stdout when it would otherwise be unnecessary, but I don't know of another way to get the desired output in this case. If someone else does, please comment.

Note: The third parameter to exec(...) is the return status, not the error message, so you need to tweak your code accordingly for that as well.

If the error output after making the 2>&1 modification doesn't help solve the root cause of your problem, please post the new output here.

Edit after new information:

Did you upload this SVN working copy to your server from somewhere else? That would explain this error.

If I check out a working copy from my local repository, upload it to my remote server, and then try to commit, I get the same error.

If that's the case, you need to execute the "svn checkout" of the working copy on the server running the PHP script in order to be able to commit to it. If that server can't communicate with the repository's server, then that's a whole other problem.

Thursday, April 1, 2021
 
2

You need to capture the stderr too.

Redirecting stderr to stdout should do the trick. Append 2>&1 to the end of your command.

e.g.

exec("/usr/bin/svn --username something --password something --non-interactive log -r HEAD --xml --verbose http://a51.unfuddle.com/svn/a51_activecollab/ 2>&1", $output);
Thursday, June 24, 2021
 
Nickool
 
4

Perhaps a little shorter and faster way, since by all odds this function is going to be used on very large data:

from Bio import Seq
from itertools import product

def extend_ambiguous_dna(seq):
   """return list of all possible sequences given an ambiguous DNA input"""
   d = Seq.IUPAC.IUPACData.ambiguous_dna_values
   return [ list(map("".join, product(*map(d.get, seq)))) ]

Using map allows your loops to be executed in C rather than in Python. This should prove much faster than using plain loops or even list comprehensions.

Field testing

With a simple dict as d instead of the one returned by ambiguous_na_values

from itertools import product
import time

d = { "N": ["A", "G", "T", "C"], "R": ["C", "A", "T", "G"] }
seq = "RNRN"

# using list comprehensions
lst_start = time.time()
[ "".join(i) for i in product(*[ d[j] for j in seq ]) ]
lst_end = time.time()

# using map
map_start = time.time()
[ list(map("".join, product(*map(d.get, seq)))) ]
map_end = time.time()

lst_delay = (lst_end - lst_start) * 1000
map_delay = (map_end - map_start) * 1000

print("List delay: {} ms".format(round(lst_delay, 2)))
print("Map delay: {} ms".format(round(map_delay, 2)))

Outputs:

# len(seq) = 2:
List delay: 0.02 ms
Map delay: 0.01 ms

# len(seq) = 3:
List delay: 0.04 ms
Map delay: 0.02 ms

# len(seq) = 4
List delay: 0.08 ms
Map delay: 0.06 ms

# len(seq) = 5
List delay: 0.43 ms
Map delay: 0.17 ms

# len(seq) = 10
List delay: 126.68 ms
Map delay: 77.15 ms

# len(seq) = 12
List delay: 1887.53 ms
Map delay: 1320.49 ms

Clearly map is better, but just by a factor of 2 or 3. It's certain it could be further optimised.

Tuesday, November 9, 2021
 
5

The break lines are the problem, try

<?php

exec('
/path/to/blastx 
-query /path/to/PAO1.fasta 
-db /path/to/VFDB_setB_pro 
-evalue 0.0001 
outfmt 6 
-out /path/to/output.tsv 
'); 

EDIT

I show the process since I cann't do tracking

1- Input data

cat seq.fa #NUCLEOTIDES

>seq_1
GGCAGCCTAACACATGCAAGTCGAACGGTAACAGGAAGCAGCTTGCTGCTTTGCT
GACGAGTGGCGGACGGGTGAGTAATGTCTGGGAAACTGCCTGATGGAGGGGGAT
AACTACTGGAAACGGTAGCTAATACCGCATAATGTCGCAAGACCAAAGAGGGGGA

cat database.fa #PROTEINS

>KDG85104.1 hypothetical protein AE17_03267, partial [Escherichia coli UCI 58]
PVVIPLHQAVSQTLLTRPPLVSKAASCFLLPFDLHVLGLPPAFNLSHDQTLQFKSLMLKELNFVMNYVFTLETWYSFFVL
RR
>EUM99718.1 hypothetical protein L347_09473, partial [Enterobacter sp. MGH 1]
VVIPLHQAVSQTLLTRPPLVSEAASCFLLPFDLHVLGLPPAFNLSHDQTLQFKSLMLNELNFVMNYVFTR
>CSD41531.1 Uncharacterised protein [Vibrio cholerae]
MADHPLRPARDRRLGEPLPHQLANPTWAYPVAQGPKVPCFALARLCGISHRFQWLSPSTGQFPRHYSPVRRSPPKEQVPL
CCRSTCMC

2- Format database

makeblastdb -in database.fa -dbtype prot -out database

3- bash script

cat myscript.sh

path_to_blast/blastx -query path_to_query/seq.fa -db path_to_db/database -evalue 0.0001 -outfmt 6

4- php script

cat blast.php

<?php
exec('sh myscript.sh', $output, $return_var);
print_r($output);
echo "$return_varn";

5- Run it,

php blast.php

you get,

Array
(
    [0] => seq_1    KDG85104.1  100.00  38  0   0   118 5   1   38  1e-24   77.0
    [1] => seq_1    EUM99718.1  97.30   37  1   0   115 5   1   37  2e-23   73.6
    [2] => seq_1    CSD41531.1  70.59   51  15  0   162 10  38  88  1e-22   72.0
)
0
Wednesday, November 24, 2021
 
DasDave
 
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :