I have a question regarding bash process substitution in python using subprocess. I'm trying to write it in a way that both the main function and the subprocess use the same input from stdin (which in the code is a string variable). Here is the code:
p1 = subprocess.run(['cat'],
stdout=subprocess.PIPE, input=in_fa.encode())
p2 = subprocess.run(['bwa samse reference/C57BL_6J.fa <(bwa aln -l 20 reference/C57BL_6J.fa -) -'],
shell=True, executable="/bin/bash", input=p1.stdout,
stdout=subprocess.PIPE)
In this example, in_fa
is a string like the following:
>header\ntTCAGCCTTCCCTTCCATTTCTCTCCCCTTCCCTCTCCTCCCCATTTCAGAGTTTCTTTAGAATCTGTATTCTGGCACCCAAAGTGAACTATGTGTCTGACTCAGGGGCTCTTTGTTTCACTGCAGGGCTGTGGTG
In this code, both '-' in the main process and the subprocess refer to in_fa
, but while the main process is reading it correctly, the subprocess is not.
This, for example, would work, but it's not dynamic and it's reading from a file instead than a variable:
p1 = subprocess.run(['''cat fasta/input.fasta |
bwa samse reference/C57BL_6J.fa <(
cat fasta/input.fasta |
bwa aln -l 20 reference/C57BL_6J.fa -) -'],
shell=True, executable="/bin/bash", stdout=subprocess.PIPE)
Any help would be appreciated! Meanwhile, I will keep trying.