Inside the CHR, it looks like 1 1 1 1 1 1 2 2 2 ... 22 22 X X ... Y ... MT MT MT
.I'd like to count the number by number.I don't know what to do because there are letters as well as numbers.
import sys
importos
with open('test.vcf', 'r') as file:
lines=file.read().split('\n')
For line in lines:
a=line.split('\t')
CHR = a [0]
Use the collections.Counter.
collections---Container data types—Python 3.7.3 Documentation
This is a subclass of dict
that counts the number of appearances for each key of an element, and is exactly the class that exists for that purpose.
You should be able to verify the operation with the following code:
import sys
importos
from collections import Counter
chars = [ ]
with open('test.vcf', 'r') as file:
lines=file.read().split('\n')
For line in lines:
a=line.split('\t')
CHR = a [0]
chars.append (CHR)
c=Counter(chars)
print(c)
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
576 Who developed the "avformat-59.dll" that comes with FFmpeg?
584 PHP ssh2_scp_send fails to send files as intended
623 Uncaught (inpromise) Error on Electron: An object could not be cloned
922 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.