Breaking a fasta formatted file into multiple files containing each gene separately

Thread Tools Search this Thread
# 1  
Breaking a fasta formatted file into multiple files containing each gene separately


I've been trying to break a massive fasta formatted file into files containing each gene separately. Could anyone help me? I've tried to use the following code but i've recieved errors every time:
for i in *.rtf.out
awk '/^>/{f=++d".fasta"} {print > $i.out}' $i 

Last edited by Corona688; 03-16-2012 at 12:47 PM..
# 2  
".out" is not in quotes, which causes an error.

You cannot use shell variables inside awk in that manner, which causes malfunctions. $i for instance would be, if i=1, field one, not a shell variable. You don't need the shell variable in the first place fortunately, awk can handle multiple files by itself.

This will create files 0001.out, 0002.out, etc, etc.

awk 'BEGIN { F=0 }; /^>/ { F++ }; { print > sprintf("%04d", F) ".out" }' *.rtf.out

The name of the file currently being processed is available as the special varaible FILENAME, if you want to base the output filename on it.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to append two fasta files?

Discussion started by: dineshkumarsrk
11 Replies

2. Shell Programming and Scripting

Getting unique sequences from multiple fasta file

Hi, I have a fasta file with multiple sequences. How can i get only unique sequences from the file. For example my_file.fasta >seq1 TCTCAAAGAAAGCTGTGCTGCATACTGTACAAAACTTTGTCTGGAGAGATGGAGAATCTCATTGACTTTACAGGTGTGGACGGTCTTCAGAGATGGCTCAAGCTAACATTCCCTGACACACCTATAGGGAAAGAGCTAAC >seq2... (3 Replies)
Discussion started by: Ibk
3 Replies

3. UNIX for Advanced & Expert Users

Map snps into a ref gene file

I have the following data set about the snps ID txt file POS ID 78599583 rs987435 33395779 rs345783 189807684 rs955894 33907909 rs6088791 75664046 rs11180435 218890658 rs17571465 127630276 rs17011450 90919465 rs6919430 and a gene... (7 Replies)
Discussion started by: marwah
7 Replies

4. Shell Programming and Scripting

Breaking large file into small files

Dear all, I have huge txt file with the input files for some setup_code. However for running my setup_code, I require txt files with maximum of 1000 input files Please help me in suggesting way to break down this big txt file to small txt file of 1000 entries only. thanks and Greetings, Emily (12 Replies)
Discussion started by: emily
12 Replies

5. Shell Programming and Scripting

Count and search by sequence in multiple fasta file

Hello, I have 10 fasta files with sequenced reads information with read sizes from 15 - 35 . I have combined the reads and collapsed in to unique reads and filtered for sizes 18 - 26 bp long unique reads. Now i wanted to count each unique read appearance in all the fasta files and make a table... (5 Replies)
Discussion started by: empyrean
5 Replies

6. Shell Programming and Scripting

Breaking a column's value into multiple rows

Hello Friends, I am trying to implement the following using UNIX. I am getting a sequential file as input which would have two columns, "Name" and "Countries Visited". The "Countries Visisted" field will be multi-valued, each value separated by a space and also the number of values are not... (2 Replies)
Discussion started by: mehimadri
2 Replies

7. UNIX for Dummies Questions & Answers

grep FASTA files

I would like to extract the sequences larger than 10 bases but shorter than 18 along with the identifier from a FASTA file that looks like this: > Seq I ACGACTAGACGATAGACGATAGA > Seq 2 ACGATGACGTAGCAGT > Seq 3 ACGATACGAT I know I can extract the IDs alone with the following code grep... (3 Replies)
Discussion started by: Xterra
3 Replies

8. Shell Programming and Scripting

To extract date and time separately from the file name

Hi., My current script extracts only if the date and time are in 3rd and 4th pos. #!/bin/bash echo "Enter the file name to extract the timestamp" read fname IFILE=$fname F=$IFILE IFS="_." f=($F) echo "Date ${f} Time ${f}" How to generalize the script to extract the... (3 Replies)
Discussion started by: IND123
3 Replies

9. Shell Programming and Scripting

Breaking the files as 10k recs. per file

Hi, I have a code as given below Set -A _Category="A\ B\ C" for _cat in ${_Category} do sed -e "s:<TABLE_NAME>:${_cat}:g" \ -e "s:<date>:${_dt}:g" \ ${_home}/skl/sq1.sql >> ${_dest}/del_${_dt}.sql fi ... (4 Replies)
Discussion started by: mr_manii
4 Replies

10. Shell Programming and Scripting

Breaking one file into many files based on first column?

Hi, I have a file that looks like this (tab deliminited). MAT1 YKR2 3 MAT1 YMR1 2 MAT1 YFG2 2 MAT2 YLM4 4 MAT2 YHL2 1 BAR1 YKR2 3 BAR1 YFR1 4 BAR1 YMR1 1 What I want to do is break this file down into multiple files. So the result will look like this: File 1... (2 Replies)
Discussion started by: kylle345
2 Replies

Featured Tech Videos