去除比对符号“-” |
#==========================================
# This code was written by Sihua Peng, PhD.
#==========================================
def clean_sequence(sequence):
return sequence.replace('-', '')
def clean_fasta(input_filename, output_filename):
with open(input_filename, 'r') as input_file:
lines = input_file.readlines()
cleaned_sequences = []
current_sequence = ""
for line in lines:
if line.startswith('>'):
if current_sequence:
cleaned_sequence = clean_sequence(current_sequence)
cleaned_sequences.append((header, cleaned_sequence))
header = line.strip()
current_sequence = ""
else:
current_sequence += line.strip()
if current_sequence:
cleaned_sequence = clean_sequence(current_sequence)
cleaned_sequences.append((header, cleaned_sequence))
with open(output_filename, 'w') as output_file:
for header, sequence in cleaned_sequences:
output_file.write(header + '\n')
output_file.write(sequence + '\n')
input_filename = "L-generated-89-samples.fasta"
output_filename = "L-generated-89-samples-clean.fasta"
clean_fasta(input_filename, output_filename)