in reply to Refomating a large fasta file...

I wouldn't do it this way if I were you! :)

From the size it looks like you're thinking of parsing nt, which is going to be slow no matter what. The sooner you start getting used to BioPerl the better off you are. With Bio::SeqIO this is a handful of lines. Further, the tired/tireless developers there are always looking for ways to speed up their parsers. It's a real friendly mailing list, too (bioperl-l@bioperl.org).

use Bio::SeqIO; my $seqIO = Bio::SeqIO->new({-file=>'nt', -format=>'fasta'}); my $i = 0; while (my $seq = $seqIO->next_seq()) { $i++; } print "There are $i non-redundant nucleotide sequences\n";

The last thing any bioinformatician wants to do is rewrite parsers. There are dozens of sequence formats, and BioPerl allows you to parse them all in this way, just changing the -format to what you need. In fact, it even has some rudimentary auto-identification, I believe. You can also rewrite sequence objects with BioSeqIO, allowing for two or three line reformatters. It's an invaluable resource, and it isn't too hard to learn to use.

BioPerl 1.2.3 is available from CPAN, or you can get a CVS tarball from the BioPerl project site.

Replies are listed 'Best First'.
Re: Re: Refomating a large fasta file...
by bioinformatics (Friar) on Nov 19, 2003 at 18:06 UTC
    This is a great suggestion. However, I have attempted to use the various bioperl modules, but to no avail. Again, I'm still new to computer programming in general, and the lack of good documentation for bioperl modules has left me with little more than headaches :-). I'm working on using your suggestion currently, and also intend to join the mailing list. Thanks!!
    Bioinformatics

      As I reread your initial post, I suspect you want to split nt into smaller chunks and write those to file. Here is a script I've been using to do that

      ### USAGE # perl -w splitter.pl <filename> <seq-per-file> # e.g. perl -w splitter.pl nt 20000 ### INCLUDES use strict; use Bio::SeqIO; ### LOCALS my $infile = $ARGV[0]; my $size = $ARGV[1]; my $i = 0; my $j = 1; ### OBJECT INSTANTIATION my $in = Bio::SeqIO->new( -file => $infile, -format => 'Fasta', ); my $out = Bio::SeqIO->new( -file => ">$infile"."_$j.fasta", -format => 'Fasta', ); ### PROCESS FILES while ( my $seq = $in->next_seq() ) { $i++; if ($i == $size) { $j++; $out = Bio::SeqIO->new( -file => ">$infile"."_$j.fasta", -format => 'Fasta'); $i = 0; } $out->write_seq($seq); }