You try the following script to do it.
use strict;
use warnings;
use Data::Dumper;
my $chrom='chr1';
my $start=9839;
my $stop=9841;
my %hash=();
my @values=();
while(<DATA>)
{
if(/[a-z]+\s*chrom=$chrom/)
{
while(<DATA>)
{
if(/([0-9]+)\s*([0-9]+\.[0-9]+)/)
{
$hash{$1}=$2;
}
else {
last;
}
}
}
}
for ($start .. $stop) {
push @values,$hash{$_};
}
print @values;
__DATA__
variableStep chrom=chr1
9837 0.010
9838 0.008
9839 0.007
9840 0.004
9841 0.002
9842 0.001
variableStep chrom=chr2
9837 0.090
9838 0.038
9839 0.017
9840 0.044
9841 0.052
9842 0.091
-
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.
|