# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
import glob
import random
import re

from Bio import SeqIO

# -

# cd ~/Downloads/HUMAN_CHIMP_Organoid_ForOlga_Sept2019/human_ALL_by_celltype/

# ! wc -l *fasta

# ! head all_human.Neuron.fasta

# +
def get_longest_translation(record):
    matches = re.finditer("ATG", str(record.seq.upper()))
    longest_translation = None
    for match in matches:
        translation = record.seq[match.start():].translate(to_stop=True)
        if longest_translation is None or len(translation) > len(longest_translation):
            longest_translation = translation
    return longest_translation

random.seed(0)
records = list(SeqIO.parse('all_human.Neuron.fasta', 'fasta'))
random.shuffle(records)

for i, record in zip(range(5), records):
    start = record.seq.upper().find('ATG')
    print('\n---')
    print(f'>{record.description}')
    print(str(record.seq))
    print('---')
    print('first ATG translation:\n', record.seq[start:].translate(to_stop=True))
    longest_translation = get_longest_translation(record)

    print('longest_translation:\n', longest_translation)
# -

record.seq.translate()

record.seq.upper().find('ATG')

re.finditer("ATG", str(record.seq.upper()))

record.seq.upper().find('ATG')



StarcoderdataJupyterScriptsDedupFiltered