Edit Seq object with Biopython
1
0
Entering edit mode
8.2 years ago
joreamayarom ▴ 140

I am using SeqIO to load a fasta file and play my sequences. For the sake of my analysis, I want to eliminate a fixed number of bases to the left and right of my sequences. Nevertheless, whenever I try to eliminate the last ten bases I get an error saying

sequences = list (SeqIO.parse(file("myfile.fasta"), "fasta")
for sequence in sequences:
            del sequence.seq[-10:]

TypeError: 'Seq' object doesn't support item deletion

I assume trimming borders and doing other edits are very basic functionalities in bioinformatics (the same can be done in Perl in a couple of lines) but I am bit surprised I can't find a method to do such things in Python because the Seq objects are immutable. Is there a way to trim a Seq object?

python biopython • 2.2k views
ADD COMMENT
1
Entering edit mode
8.2 years ago
Sanjar ▴ 150
for sequence in sequences:
    sequence.seq = sequence.seq[10:-10]
ADD COMMENT

Login before adding your answer.

Traffic: 1606 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6