in reply to input record separator help

I've been making small modification of your code:

while (<INFILE>) { if (/^>/) { $in_sequence = 1; next; } $dna .= $_ if $in_sequence; } }

Also, I'd like to suggest you look at site of BioPerl if you haven't seen yet it ;)

~ Schiller

Replies are listed 'Best First'.
Re: Re: input record separator help
by Anonymous Monk on Mar 15, 2004 at 14:29 UTC
    thanks for your help Schiller, but I dont get how I can perform my various calculations on each sequence using your code. How can I push each extracted $dna into an array, which I can then iterate through for the calculations? This is the sort of thing I want to do for each sequence:
    for (my $i=0; $i < @genome; $i++) { my $token = $genome[$i] . $genome[$i+1]; $freq{$token}++; $tt = $freq{tt}; $cg = $freq{cg}; $gc = $freq{gc}; $ta = $freq{ta}; $at = $freq{at}; $cc = $freq{cc}; $tg = $freq{tg}; $ag = $freq{ag}; $ac = $freq{ac}; $ga = $freq{ga}; $aa = $freq{aa}; $gg = $freq{gg}; $ca = $freq{ca}; $ct = $freq{ct}; $gt = $freq{gt}; $tc = $freq{tc}; }
    I have tried just using a simple 'push', but this slowed the program down far too much. cheers x
      Anonymous Monk,
      So my earlier assumption that you wanted to throw away non sequence lines was correct. I believe you can avoid an array all together.
      #!/usr/bin/perl use strict; use warnings; my $file = $ARGV[0] || 'default'; open (DNA, '<', $file) or die "Unable to open $file for reading : $!"; my %seq; while ( <DNA> ) { my $dna = <DNA>; my $pairs = "a2" x ((length $dna) / 2); $seq{$_}++ for unpack $pairs , $dna; } print "$_ : $seq{$_}\n" for keys %seq;
      Cheers - L~R
        hi L~R, thankyou for your help, would you mind exaplaining to me exactly what the code does? e.g. the 'a2' and 'unpack' bits? many thanks