popgenmethods / momi2

Infer demographic history with the Moran model
GNU General Public License v3.0
47 stars 11 forks source link

VCF files reading error: fetch requires index #40

Closed AlexLlanesQuevedo closed 2 years ago

AlexLlanesQuevedo commented 3 years ago

Hi all, I have my dataset in a single vcf (obtained with ipyrad and curated with vcftools) so I created the .bed file by using the vcf2bed script (https://raw.githubusercontent.com/isaacovercast/lab-notebooks/master/vcf2bed/vcf2bed.py). I assigned the individuals to populations with the parameter ind2pop ; however when creating the snp allele counts array with momi.SnpAlleleCounts.read_vcf I get the error: ValueError: fetch requires an index. Could you help me to overcome this error? imagen

terhorst commented 3 years ago

pysam (the library momi2 uses to read VCFs) requires that the variant file be indexed for reading. You need to compress and index your VCF file by running:

$ bcftools view -o run5_40indv.bcf run5_40indv.vcf $ bcftools index run5_40indv.bcf

Then use the resulting .bcf file with momi2.

On Mon, Dec 28, 2020 at 12:15 PM AlexLlanesQuevedo notifications@github.com wrote:

Hi all, I have my dataset in a single vcf (obtained with ipyrad and curated with vcftools) so I created the .bed file by using the vcf2bed script ( https://raw.githubusercontent.com/isaacovercast/lab-notebooks/master/vcf2bed/vcf2bed.py). I assigned the individuals to populations with the parameter ind2pop ; however when creating the snp allele counts array with momi.SnpAlleleCounts.read_vcf I get the error: ValueError: fetch requires an index. Could you help me to overcome this error? [image: imagen] https://user-images.githubusercontent.com/59844946/103231617-d1e05d80-48fd-11eb-85fb-934851bd1943.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/popgenmethods/momi2/issues/40, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEOHGOMRPAVQXGVU7BBA3SXC4JTANCNFSM4VMIIHWA .

-- Jonathan terhorst@gmail.com

jackkamm commented 3 years ago

What @terhorst says is correct, but I'm leaving this issue open until we update the documentation of read_vcf() to make clear that an indexed VCF file is required.