Question: Pysam VariantFile.fetch() without specifying contig
0
gravatar for ricardoguerreiro2121
22 months ago by
Germany
ricardoguerreiro212160 wrote:

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 • 1.3k views
ADD COMMENTlink modified 22 months ago • written 22 months ago by ricardoguerreiro212160
4
gravatar for finswimmer
22 months ago by
finswimmer14k
Germany
finswimmer14k wrote:

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 COMMENTlink modified 22 months ago • written 22 months ago by finswimmer14k

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

Danke schön!

Ricardo

ADD REPLYlink modified 22 months ago • written 22 months ago by ricardoguerreiro212160
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1203 users visited in the last hour