Skip to content

Instantly share code, notes, and snippets.

@StephenFordham
Created August 8, 2024 17:58
Show Gist options
  • Save StephenFordham/649f4762e843d7083ece9321a8291584 to your computer and use it in GitHub Desktop.
Save StephenFordham/649f4762e843d7083ece9321a8291584 to your computer and use it in GitHub Desktop.
Repeat_confirmation
from Bio import SeqIO
def read_fasta_sequence(file_path):
sequence = ""
with open(file_path, 'r') as file:
for line in file:
if not line.startswith('>'):
sequence += line.strip()
return sequence
def count_sequence_repeats(fasta_file, repeat_sequence_file):
"""
Counts how many times a repeat sequence is found in a given FASTA file.
Parameters:
fasta_file (str): Path to the input FASTA file.
repeat_sequence_file (str): Path to the FASTA file containing the repeat sequence.
Returns:
int: Number of times the repeat sequence is found in the FASTA file.
"""
# Read the repeat sequence from the FASTA file
repeat_sequence = read_fasta_sequence(repeat_sequence_file)
count = 0
for record in SeqIO.parse(fasta_file, "fasta"):
count += record.seq.count(repeat_sequence)
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment