This is the 3rd time I am asking this question. Previous answers were wrong or incomplete. Please, do not copy old answers for me. I will upvote if you provide a workable code. Here is the code and tree I have already provided if it's helpful. Please use the tree: tree = { 9: ['N',{'node': 6, 'branch': 0.1}, {'node': 8, 'branch': 0.5}], 8: ['N',{'node': 3, 'branch': 0.75}, {'node': 7, 'branch': 0.1}], 7: ['N',{'node': 4, 'branch': 0.1}, {'node': 5, 'branch': 0.15}], 6: ['N',{'node': 1, 'branch': 0.5}, {'node': 2, 'branch': 0.25}], 5: ['L'], 4: ['L'], 3: ['L'], 2: ['L'], 1: ['L'] } # Write code to solve problem here: # Open the file and read the contents with open('SSA_regions.fasta', 'r') as f: file_contents = f.read() # Split the contents by sequence sequences = file_contents.split('>') # Initialize an empty dictionary to store the sequences sequence_dict = {} # Loop over the sequences for sequence in sequences[1:]: # Split the sequence into header and nucleotide sequence header, nucleotides = sequence.split('\n', 1) # Remove any whitespace from the nucleotide sequence nucleotides = nucleotides.replace('\n', '') # Add the nucleotide sequence to the dictionary sequence_dict[header] = nucleotides # Print the dictionary print(sequence_dict)
This is the 3rd time I am asking this question. Previous answers were wrong or incomplete. Please, do not copy old answers for me. I will upvote if you provide a workable code. Here is the code and tree I have already provided if it's helpful. Please use the tree:
tree = {
9: ['N',{'node': 6, 'branch': 0.1}, {'node': 8, 'branch': 0.5}],
8: ['N',{'node': 3, 'branch': 0.75}, {'node': 7, 'branch': 0.1}],
7: ['N',{'node': 4, 'branch': 0.1}, {'node': 5, 'branch': 0.15}],
6: ['N',{'node': 1, 'branch': 0.5}, {'node': 2, 'branch': 0.25}],
5: ['L'],
4: ['L'],
3: ['L'],
2: ['L'],
1: ['L']
}
# Write code to solve problem here:
# Open the file and read the contents
with open('SSA_regions.fasta', 'r') as f:
file_contents = f.read()
# Split the contents by sequence
sequences = file_contents.split('>')
# Initialize an empty dictionary to store the sequences
sequence_dict = {}
# Loop over the sequences
for sequence in sequences[1:]:
# Split the sequence into header and nucleotide sequence
header, nucleotides = sequence.split('\n', 1)
# Remove any whitespace from the nucleotide sequence
nucleotides = nucleotides.replace('\n', '')
# Add the nucleotide sequence to the dictionary
sequence_dict[header] = nucleotides
# Print the dictionary
print(sequence_dict)
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images