Problem with process substitution


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with process substitution
# 1  
Old 06-10-2013
Problem with process substitution

i have tried process substitution, but run in some problems.

this works:
Code:
 
samtools view -h $SAMdir/$b.bam | htseq-count -m union -s no -q -t exon -i gene_id - $gtf > $b.count &

but this not:
Code:
 
htseq-count -m union -s no -q -t exon -i gene_id <(samtools view -h $SAMdir/$b.bam) $gtf > $b.count &

the error is not fundamental, and some (few) of the runs worked (i looped over a bunch of files). the error indicated a truncated sam-file, that means that one line of the file (which is in a specific format, the sam format) was malformed (some columns are missing). how can the above commands be different?
or has it to do with the multiple processes i started (using &)?
# 2  
Old 06-11-2013
Maybe it treats stdin - as a pipe but does seeks when there is a file name. Use strace/tusc/truss to verify what calls are made to the kernel.
# 3  
Old 06-11-2013
What shell are you using and on what OS and version ?
# 4  
Old 06-12-2013
@Scrutinizer
OS: Scientific Linux 6.3 (= Red Hat Enterprise Linux 6.3)
shell: GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)


@DGPicket
do you mean that htseq knows that - is a piped stream but is confused from <(..). i thought <(..) simulates a pipe perfectly.

strace is new for me, i will look if i can use it correctly...
# 5  
Old 06-12-2013
Could you check if there is still a difference if you use:
Code:
( samtools view -h $SAMdir/$b.bam | htseq-count -m union -s no -q -t exon -i gene_id - $gtf > $b.count ) &

vs.
Code:
( htseq-count -m union -s no -q -t exon -i gene_id <(samtools view -h $SAMdir/$b.bam) $gtf > $b.count ) &

--
Also, do you use a wait statement further down in your script?

Last edited by Scrutinizer; 06-12-2013 at 03:27 AM..
# 6  
Old 06-12-2013
While <() substitutes the name of a named pipe as a 'word' (has virtual spaces around it, cannot be concatenated to quoted strings, says David Korne), the programmer may have assumed (ass U me) that it was a flat file, and that only '-' was suspected of being a pipe, and so incapable of a seek. You can see that on strace. I say this not out of experience with such behaviors, just from knowing the stupid things half-knowing UNIX programmers do. If there is a problem, stat() would tell the deducated programmer before that it was a pipe. Presumably, the proces copies the pipe data into a tmpfile() and uses that in place of the pipe, adding latency. Hard to say. Maybe the programmer likes to rewind() files out of paranoia alone, and only had problems with stdin as he did not have or know of <() and 'mknod <name> p'.

You might dump the data in a temp file and exec redirect stdout in the <() to give it a flat file. I would get back to the writer of the app about this goofiness.

The ksh only supports <() on systems with the open fd in the file tree, like /proc/$$/fd/#, so a simple pipe() call makes ephemeral named pipes that disappear at close or exit. In comparison, bash makes durable named pipes in /var/tmp to use (and never cleans them up, an unfortunate bug with no easy solution).

Last edited by DGPickett; 06-12-2013 at 03:23 PM..
# 7  
Old 06-12-2013
Quote:
Originally Posted by dietmar13
@DGPicket
do you mean that htseq knows that - is a piped stream but is confused from <(..). i thought <(..) simulates a pipe perfectly.
It doesn't simulate a pipe, it is one -- a different kind of pipe though, since it must have a filename.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cannot make pipe for process substitution: Too many open files

Hi, I've came across an issue with a script I've been writing to check DHCP addresses on an Solaris system, the script has been running reasonably well, until it hit the following problem: ./sub_mon_v2: redirection error: cannot duplicate fd: Too many open files ./sub_mon_v2: cannot make... (3 Replies)
Discussion started by: CiCa
3 Replies

2. UNIX for Dummies Questions & Answers

Process Substitution Question?

Hello to all. I'm new to this forum, so please go easy on me. =) I am working on a script to send two e-mail attachments in a single e-mail, and am running into a little bit of an issue when using process substitution. I am using the following: cat <(uuencode $1 <(basename $1)) <(uuencode... (5 Replies)
Discussion started by: rommager
5 Replies

3. Shell Programming and Scripting

sed substitution problem

I'm writing my first script and I have all the other commands I'm using working properly, but I'm having one final issue with a sed. I've looked on the forums for some answers, which have been close but sed is quite confusing to me. My problem is that I have a file called CylinderAtom1.txt... (3 Replies)
Discussion started by: 1Aegis1
3 Replies

4. Shell Programming and Scripting

Another substitution problem

Hello again, I'm trying to change the following line: INSERT INTO PH1_TX_LOAD VALUES ('TX-78731-AABSS:4182-4','RH: GUIDE TO TENNIS',TO_DATE('18-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS'),TO_DATE('21-JUN-2001:00:00:00', 'DD-MON-YYYY:HH24:MI:SS'),500) so that any TO_DATE is taken... (6 Replies)
Discussion started by: user_invalid
6 Replies

5. Shell Programming and Scripting

problem in dollar substitution

Hi, I have a problem in dollar substitution:- $ csv1="first_csv" $ csvnumber=1 $ echo {csv$csvnumber} {csv1} $ echo "${csv$csvnumber}" bad substitution I want first_csv...why is it not working thanks (2 Replies)
Discussion started by: scripter12
2 Replies

6. Shell Programming and Scripting

Process substitution

Just playing around with process substitution. Hoping maybe someone can give me some help on what I'm doing wrong. When this script is run, "Null message body; hope that's ok" is returned and the script hangs. I can't seem to work out what I'm doing wrong. Here is the script: #!/bin/bash... (3 Replies)
Discussion started by: mandelbrot333
3 Replies

7. Shell Programming and Scripting

Can process substitution be used as an input file to another program?

Hey, I was trying to figure out how to launch a program from the command line, and it works if you pass it a config file. I was thinking about writing a script to dynamically create the config file and pass it to the command using something like command substitution (so I don't actually have to... (3 Replies)
Discussion started by: bj0
3 Replies

8. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

9. AIX

VI Substitution problem

I'm having a problem getting my variables to work in dishing out an RMC script. The $1 works fine. $2 does not Here's a portion of the script: server=$1 filesystem1=$2 # dsh -w $1 'mkcondition -c "/var space used" -s "Name == \"$2\"" -e "PercentTotUsed > 90" -d "An event will be generated... (7 Replies)
Discussion started by: gravy26
7 Replies

10. Shell Programming and Scripting

Substitution problem.

Hi, Just need some help in this. Suppose there is one file a.txt, which contains this data: "25187","00000022","00",28-MAR-2007,"" ,"D",-000001550,+0000000000,"C", ,+000000000,+000000000,000000000,"2","" ,29-MAR-2007 613TB.STEXTRF1 "25187","0000004H","00",29-MAR-2007,""... (3 Replies)
Discussion started by: er_ashu
3 Replies
Login or Register to Ask a Question