I currently have a a problem with samtools and python.
Iḿ trying to write a sam or bam file into a file like object
which works well using the following code
import sh
import io
#define samtools as a python functions
samtools = sh.Command("samtools")
#where is the input sam
sam_input = "test.sam"
#generate a file like object
sam_IO2 = io.BytesIO()
#let samtools view write in the file like object
samtools.view(sam_output,S=True,h=True,_out = sam_IO2)
#show the sam file
sam_IO2.getvalue()
or
bam_IO2 = io.BytesIO()
samtools.view(bam_input,_out = bam_IO2)
#show the bam file
bam_IO2.getvalue()
but now i try to read from the file like object for both cases:
samtools.view("/dev/stdin",S=True,_in = sam_IO2)
samtools.view("/dev/stdin",_in = bam_IO2)
it fails in both tcases.
Does anyone have an idea how to do this correctly ?
Would be really helpful.
Iḿ trying to write a sam or bam file into a file like object
which works well using the following code
import sh
import io
#define samtools as a python functions
samtools = sh.Command("samtools")
#where is the input sam
sam_input = "test.sam"
#generate a file like object
sam_IO2 = io.BytesIO()
#let samtools view write in the file like object
samtools.view(sam_output,S=True,h=True,_out = sam_IO2)
#show the sam file
sam_IO2.getvalue()
or
bam_IO2 = io.BytesIO()
samtools.view(bam_input,_out = bam_IO2)
#show the bam file
bam_IO2.getvalue()
but now i try to read from the file like object for both cases:
samtools.view("/dev/stdin",S=True,_in = sam_IO2)
samtools.view("/dev/stdin",_in = bam_IO2)
it fails in both tcases.
Does anyone have an idea how to do this correctly ?
Would be really helpful.
Comment