concatenate fasta file

P

PeroMHC

Hi All, I have a simple problem that I hope somebody can help with. I
have an input file (a fasta file) that I need to edit..

Input file format
name 1 tactcatacatac
name 2 acggtggcat
name 3
gggtaccacgtt

I need to concatenate the sequences.. make them look like
concatenated
tactcatacatacacggtggcatgggtaccacgtt

thanks. Matt
 
R

Roy Smith

PeroMHC said:
Hi All, I have a simple problem that I hope somebody can help with. I
have an input file (a fasta file) that I need to edit..

Input file format

gggtaccacgtt

I need to concatenate the sequences.. make them look like

tactcatacatacacggtggcatgggtaccacgtt

thanks. Matt

Some quick ideas. First, try something along the lines of (not tested):

data=[]
for line in sys.stdin:
if line.startswith('>'):
continue
data.append(line.strip())
print ''.join(data)

Second, check out http://biopython.org/wiki/Main_Page. I'm sure somebody
has solved this problem before.
 
J

Jean-Michel Pichavant

PeroMHC said:
Hi All, I have a simple problem that I hope somebody can help with. I
have an input file (a fasta file) that I need to edit..

Input file format


gggtaccacgtt

I need to concatenate the sequences.. make them look like


tactcatacatacacggtggcatgggtaccacgtt

thanks. Matt
A solution using regexp:

found = []
for line in open('seqfile.txt'):
found += re.findall('^[acgtACGT]+$', line)

print found
> ['tactcatacatac', 'acggtggcat', 'gggtaccacgtt']

print ''.join(found)
> 'tactcatacatacacggtggcatgggtaccacgtt'


JM
 
G

Grant Edwards

Hi All, I have a simple problem that I hope somebody can help with. I
have an input file (a fasta file) that I need to edit..

Input file format

gggtaccacgtt

I need to concatenate the sequences.. make them look like

tactcatacatacacggtggcatgggtaccacgtt

(echo "concantenated>"; grep '^ [actg]*$' inputfile | tr -d '\n'; echo) > outputfile
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top