I think your problem is
- you have a large file
- you have created a new file with line endings removed
- now you want to read in characters between two positions in the new file
To do that you can use sysseek and sysread.
use Fcntl qw(SEEK_SET);
my $input = '...';
my $start = 1_490_117;
my $end = 1_492_312;
my $length = $end - $start +1;
open my $fh, '<', $input or die "Can't open $input: $!";
sysseek($fh, $start, SEEK_SET) or die "Can't seek to $start in $input:
+ $!";
my $sequence;
my $read = sysread $fh, $sequence, $length;
die "Failed to read $length bytes from $input, got $read"
if $length != $read;
Now $sequence will contain the DNA sequence from 1,490,117 to 1,492,312 including both end points.
Note: sysread and sysseek use unbuffered IO, don't mix calls to them on a filehandle using other functions such as read, <> or eof.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|