Mike Robeson wrote:
> Hello,
> 
> I am a relatively new PERL beginner and have been trying to work with
> simple bioinformatics stuff. I have so far written some very useful
> but simple bioinformatics scripts. However.... recently I have been
> trying to work on a script to no avail. I have a text file whose
> contents are: 
> 
>  >dog
> agatagatcgcatcga
>  >cat
> acgcttcgatacgctagctta
>  >mouse
> agatatacgggt
> 
> .... and so on...
> 
> I would like to turn that into this:
> 
> a g a t a g a t c g c a t c g a - - - - - - - - - - - - - - -
> dog
> a c g c t t c g a t a c g c t a g c t t a - - - - - - - - - -
> cat
> a g a t a t a c g g g t t  - - - - - - - - - - - - - - - - - - -
> mouse
> 
> Notice that the sequence of letters varies however I need the lines in
> the newly formed file to be equal in length by adding the appropriate
> amount of dashes. For those in the know I am trying to convert a FASTA
> file into a DCSE file.
> 
> I have been beating my head for the past 2 weeks and I cannot figure
> out how to do this. I do not expect a complete answer (I would like to
> try figuring this out on my own as much as possible) but rather some
> guidance. Any detailed pseudo-code would be appreciated!!
> 
> -Thanks!
> -Mike
        Here is a shot and at least one way to try it:

#!perl -w

use strict;

my @MyWorka = ();
my $In = 0;
my $MyItem1 ;
my $MyItem2 ;
my $MyMaxLen = 35;

while ( <DATA> ) {
    chomp;
    next if ( /^\s*$/ );
    if ( /^\s+>(\S+)/ ) {
        $MyItem1 = $1;
        chomp($MyItem2 = <DATA>);
        $In++;
        $MyItem2 =~ s/\s+//g;
        my $MyLen = length($MyItem2);
        if ( $MyLen < $MyMaxLen ) {
            my $MyExtra = $MyMaxLen - $MyLen;
            $MyItem2 .= sprintf "%s", '-'x$MyExtra;
         }
        @MyWorka = split(//,$MyItem2);
        printf "%-2s"x$MyMaxLen , @MyWorka;
        printf "\n%-s\n\n",
                                $MyItem1;
     }    
 }

__DATA__
 >dog
agatagatcgcatcga
 >cat
acgcttcgatacgctagctta
 >mouse
agatatacgggt

Output:
a g a t a g a t c g c a t c g a - - - - - - - - - - - - - - - - - - -
dog

a c g c t t c g a t a c g c t a g c t t a - - - - - - - - - - - - - -
cat

a g a t a t a c g g g t - - - - - - - - - - - - - - - - - - - - - - -
mouse



**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to