Go Back   SEQanswers > Bioinformatics > Bioinformatics

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining fasta file and bed file into a different file using biopython,python surachit Introductions 0 10-25-2015 10:55 PM
Python counting bases fasta file illinu Bioinformatics 9 08-22-2013 08:17 AM
Program edit an ace file to simultaneously extract read information from all contig? cllorens Bioinformatics 3 06-27-2012 08:20 AM
BAM Header minor edit seq_lover Bioinformatics 4 05-31-2012 03:46 PM
edit RGID in header shawpa Bioinformatics 5 02-22-2012 09:02 AM

Thread Tools
Old 02-24-2016, 05:13 PM   #1
Junior Member
Location: NH

Join Date: Nov 2015
Posts: 9
Default how to edit header in a fast file with python

I am looking to edit the header of a fast file using python. I am converting the DNA sequence to an amino acid sequence and I need to add "-aa" where the first space in the header is located.

The header looks like this:
>ANIS1000.x1 ET TIME...

It needs to look like this:
>ANIS1000.x1-aa ET TIME...

I can locate the index of the space using this:
locate = dnaHeader.find(' ')

But then I cannot insert the '-aa' using the insert function:
dnaHeader = dnaHeader.insert(locate, ' ')

The error says 'str' object does not support item assignment.

bfp7 is offline   Reply With Quote
Old 02-25-2016, 02:49 AM   #2
Senior Member
Location: Cambridge, UK

Join Date: May 2010
Posts: 311

You could use:

newHeader= dnaHeader[0:locate] + '-aa' + dnaHeader[locate:]
Maybe it's not the most efficient strategy since you need to create a new string but unless your file is massive it should be good enough.

.insert() is a method for lists not for strings, which are immutable.
dariober is offline   Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT -8. The time now is 10:23 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO