Question: Pysam VariantFile.fetch() without specifying contig
0
gravatar for ricardoguerreiro2121
5 days ago by
ricardoguerreiro21210 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 • 51 views
ADD COMMENTlink modified 5 days ago • written 5 days ago by ricardoguerreiro21210
3
gravatar for finswimmer
5 days ago by
finswimmer8.8k
Germany
finswimmer8.8k 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 5 days ago • written 5 days ago by finswimmer8.8k

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

Danke schön!

Ricardo

ADD REPLYlink modified 5 days ago • written 5 days ago by ricardoguerreiro21210
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: 1172 users visited in the last hour