citromatik has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

I've been developing (FTFOI) a Perl module to manage text files containing complex data structures as an array. It works by first indexing all the data and tie-ing an array to it. Then, you can read/write from/to the file through a tied array. Initially, the "rules of the game" were:

In general it behaves similar to Tie::File except that it manages complex data structures

An example is shown here:

For example, if you have a fasta format'ed DNA file like:

>Seq1 AGAGAGAGAGAGGA AGAGAGAGTTCCTT CATCGCACATCAGA AGG >Seq2 GCGTGAGATTGAGG GAATTGAGAGAGAG >Seq3 GAGAGCGCGACCCC TGAGTAGATAGAGA ACAGATATAGGAGA AGAG

Once tied you can:

#Print the file print $_.$/ for (@fastafile); #Reverse the file @fastafile = reverse @fastafile; #Change the 2nd secuence $fastafile[1] = $other_seq; #Put more sequences push @fastafile, $other_seq;

etc... and the changes would be mirrored to the file automatically

In this case it would behave similar to:

tie @fastafile,'Tie::File',recsep=>"\n>",autochomp=>1;

As I said before, this module was created "for the fun of it", but I was curious to know if a final version of it could be generally interesting. The idea is too simple, and surely there are modules (probably better than mine) doing the same tasks. I looked at CPAN but, although some other modules can do similar things (Tie::File, DB_File, Bio::DB::Fasta), none of them seem do the same work. Does anybody know how to do the same things with existing modules?

Thanx all

citromatik

Replies are listed 'Best First'.
Re: Tie-ing files containing complex data structures
by perrin (Chancellor) on May 24, 2007 at 18:06 UTC

      I don't see how to do the things I commented in my post with MLDBM.

      Is it possible to interface a (for example) fasta file (see the example in my post) with MLDBM? I read carefully the documentation and it doesn't seem obvious to me how to do the trick.

      citromatik

        No, of course it doesn't read someone else's data format. It does provide a tied interface to complex data storage using only what comes with perl though, which I thought was what you were asking about.

        If you're specifically wondering about FASTA files, search for FASTA on CPAN. There are a handful of modules for it.