Greetings,
First some suggestions, against using barewords, and for using open in its three terms form: more explicit and understandable
Also I put there use autodie because I'm lazy :$
use warnings;
use strict;
use autodie;
open my $in,'<', "in.txt";
open my $out,'>', "out.txt";
Since you start at first line and then jump over each line to save to the previous line you can use the perl auto variable for line counts
my $previous_line;
while (<$in>) {
$current_line = $_;
chomp $current_line;
if(!defined($previous_line) || $. mod 2 != 0){
$previous_line = $current_line;
next;
}
my @previous_columns = split(" ", $previous_line);
my $end_coor = $previous_columns[2] + $previous_columns[3];
my @current_columns = split(" ", $current_line);
my $seq_length = length $previous_columns[6];
my $gap_count = $previous_columns[6] =~ tr/Q//;
my $original_length = $seq_length - $gap_count;
my $original_end_coor = $previous_columns[2] + $original_length;
my $distance = $current_columns[2] - $original_end_coor;
$current_columns[2] = $end_coor + $distance;
$previous_line = $current_line;
print $out "$current_columns[2]\n";
}
close $in;
close $out;
I'm not sure about the way you want to go over the file though, do you want to just jump over half of the lines?
-
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.