Pysam VariantFile.fetch() without specifying contig
1
0
Entering edit mode
5.9 years ago

Hello,

I'm using the Pysam module of Python and calling the function:

VF = VariantFile("input_file")

VF.fetch()

seems to retrieve all reads in the file,

while this retrieves reads from positions 0 to 1000 in one specific contig:

VF.fetch(contig="contig_name", start=0, end=1000)

My question is: is it possible to retrieve sequences based on positions without specifying the contig name? Or better, specifying multiple contig names? (gives error, expects one string).

This is because I have a file with multiple contigs, but I would like to get for example all reads in positions 0:1000 in all contigs.

If I do this:

VF.fetch( start=0, end=1000)

It ignores my start and end specification, and retrieves all reads, like if it were no arguments inside fetch.

pysam python vcf • 3.6k views
ADD COMMENT
4
Entering edit mode
5.9 years ago

Hello,

you can get all the contig names via VCF.header.contigs. This returns a view you can iterate over (untested):

for name in VCF.header.contigs:
    VF.fetch(contig=name, start=0, end=1000)

This presumes that the contigs are listed in the header.

fin swimmer

ADD COMMENT
0
Entering edit mode

Brilliant! Sometimes you just have to go around the problems, not force your way through.

Danke schön!

Ricardo

ADD REPLY

Login before adding your answer.

Traffic: 2382 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6