On Wed, Aug 10, 2011 at 12:43 PM, VinoRex.E <vino...@gmail.com> wrote:

> Hi every one
> i am a Biologist,i am having a DNA file having 2000 to 10000000 letters. eg
> file:(ATGCATGCTAGCTAGTCGATCGCATCGATAGCTAGCTACGCG
> CGTACCGTGCAGAAGAGCAGGACATATATATTACGCGGCGATCGATCGTAGC
>
> GATCGATCGATCGCTAGCTGACTATGCATGCTAGCTAGTCGATCGCATCGATAGCTAGCTACGCGCGTACCGTGCAGAAGAGCAGGACATATATATTACGCGGCGATCGATCGTAGCGATCGATCGATCGCTAGCTGACTATGCATGCTAGCTAGTCGATCGCATCGATAGCTAGCTACGCGCGTACCGTGCA
> GAAGAGCAGGACATATATATTACGCGGCGATCGATCGTAGCGATCGATCGA
> TCGCTAGCTGACTATGCATGCTAGCTAGTCGATCGCATCGATAGCTAGCTACGCGCGTACCGTGCAGAA
>
> GAGCAGGACATATATATTACGCGGCGATCGATCGTAGCGATCGATCGATCGCTAGCTGACTATGCATGCTAGCTAGTCGATCGCATCGATAGCTAGCTACGCGCGTACCGTGCAGAAGAGCAGGACATATATATTACGCGGCGATCGATCGTAGCGATCGATCGATCGCTAGCTGACT)
> i calculated the total length of the sequence. what i want to execute is to
> extract and show the output only the specific(ie highlighted ones only).
> thank you
>


Hi there,

Here is what I suggest you do:

First always use strict and warnings, second show us what yuo have done so
far that will help show people that you are actually trying and not just
asking others to do your homework for you. ;-)

As for solving the problem here is what I would do:

#!/usr/bin/perl

use strict;
use warnings;
use File::Slurp; # A handy module check it out at:
http://search.cpan.org/~uri/File-Slurp-9999.19/lib/File/Slurp.pm

my $file_contents = read_file( '<your file>' ); #Reads the whole file in one
go, please note that this includes the linefeeds etc... you might or might
not need to strip these out depending on how clean the files are.

my $total = length( $file_contents );

my $substring = substr 0, 10, $file_contents;

print "Total number of characters: $total\nSub string: $substring\n";


That should do the trick of course change the 0, 10 to the starting position
of the substring and the total number of chars you would like to get have
returned. The trick for you would be to loop over the files, or allow for
command line or interactive feeding of the filename/path and the start
point/length of the substring you want to get out of the file.

Regards,

Rob

Reply via email to