I want to return the nth basepair given my fna.gz genome input. Theoretically it would work like this:
allele = genome[14325]
print(allele)
#: G
This is the code I have now:
from Bio import SeqIO
import gzip
from Bio.Alphabet import generic_dna
input_file = r"C:\Users\blake\PycharmProjects\Transcendence3.0\DNA\GCF_000001405.38_GRCh38.p12_genomic.fna.gz"
output_file = r"C:\Users\blake\PycharmProjects\Transcendence3.0\DNA\Probabilities"
with gzip.open(input_file, "rt") as handle:
for record in SeqIO.parse(input_file, "fasta", generic_dna):
fasta_sequences = SeqIO.parse(open(input_file), 'fasta')
print("seq parsed")
with open(output_file) as out_file:
for fasta in fasta_sequences:
name, sequence = fasta.id, str(fasta.seq)
new_allele = tell_basepair(sequence)
write_fasta(out_file)
def tell_basepair(n, seq):
bp = seq[n-1]
return bp
but it doesn't work and I get an error:
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 386: character maps to <undefined>