I am writing a script which can replace all of the instances of an amino acid residue in a column of a FASTA alignment file. Using AlignIO, I just can read an alignment file and extract information from it but I can't modify their sequences. Moreover, MutableSeq module just can be modify string sequences and if I use a seq object input, it can't modify it. I'd like to find a module or a method to modify an alignment file and save it, while it is in the structure of AlignIO as a sequence object for subsequent procedures.
My code using just AlignIO:
alignment = AlignIO.read(input_handle, "fasta")
for record in alignment:
if record.seq[10] == "G":
record.seq[10] = "T"
Output:
record.seq[10] = "T"
TypeError: 'Seq' object does not support item assignment
My code using both AlignIO and MutableSeq:
alignment = AlignIO.read(input_handle, "fasta")
for record in alignment[0:1, : ]:
mut_align = MutableSeq(record.seq)
mut_align.__delitem__(10)
mut_align.insert(10, "T")
print(mut_align)
Output:
del self.data[index]
TypeError: 'Seq' object doesn't support item deletion