from Bio import SeqIO
import numpy as np

path = "../data/sample.fastq"
# Guardar ids de records bajo umbral
mala_calidad = []
umbral = 32
for record in SeqIO.parse(path, 'fastq'):
    promedio = np.mean(record.letter_annotations['phred_quality'])
    if promedio < umbral:
        mala_calidad.append((promedio, record.id))

mala_calidad

# Eliminar si existe un valor menor al umbral
buena_calidad = []
umbral = 32
for record in SeqIO.parse(path, 'fastq'):
    minimo = min(record.letter_annotations['phred_quality'])
    if minimo > umbral:
        buena_calidad.append((record.id, record.seq))

buena_calidad

##########

for gb_record in SeqIO.parse("../data/aichi.gb", "genbank"):
    print("ID", gb_record.id)
    print('Secuencia', str(gb_record.seq)[0:30],'...')
    print('Longitud', len(gb_record))

# Informacion de metadatos almacenada como diccionario
gb_record.annotations

f_source = gb_record.features[0]
f_cds = gb_record.features[1]

print(f_source.location)
print(f_source.type)
print(f_source.qualifiers)

# Ejercicio 4

for virus in SeqIO.parse("../data/virus.gb", "genbank"):
    print(virus.annotations['sequence_version'])
    print(virus.annotations['organism'])
# Ejercicio 5

fuente_aislado = virus.features[0].qualifiers['isolation_source']
pais = virus.features[0].qualifiers['country']
