[Python] Creating A More Efficent For Loop for SNP Frequency

Discussão em 'Python' iniciado por Stack, Maio 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to count the frequency of SNPs every 100,000 base locations. I'm using a VCF file I've already prepared, and my professor showed me to use code such as below:

    inputfile=open("bcftools_snps.txt", 'r')
    X=0
    for line in inputfile:
    A=line.split()
    if float(A[1]) < 100000:
    X=X+1
    print("0-100000=", X)


    and thus far, I've done this with a new variable for 200,000-300,000 and so on and so forth. The issue is, there are 7 million placements, meaning I'd need to define 700 variables which just sounds horribly slow for one chromosome. Is there a more efficient way to do this?

    Continue reading...

Compartilhe esta Página