perl - How to split in blocks a file and count the intermediate lines -
i have file this:
fixedstep chrom=chr22 start=14430001 step=1 144300010.000 0.002 0.030 0.990 0.000 0.000 0.000 fixedstep chrom=chr22 start=14430001 step=1 0.000 0.000 0.000
and take number of start every line starts fixedstep , put counter in every of other lines. eg.
fixedstep chrom=chr22 start=14430001 step=1 14430001 0.000 14430002 0.002 14430003 0.030 fixedstep chrom=chr22 start=16730005 step=1 16730005 0.990 16730006 0.000 .........
i wrote code doesn't work.
open $scores_info, $scores_file or die "could not open $scores_file: $!"; while( $sline = <$scores_info>) { if ($sline=~ m/fixedstep/) { @data = split(' ', $sline); @begin = split('=', $data[2]); $start = $begin[1]; print "$start\n"; $nextline = <$scores_info>; $start++; print $start . "\t" . $nextline; }
an print in new file. me please?? thank in advance
if encounter line "fixedstep", set $count
, print line. otherwise, print , increment $count
:
my $count = 0; while( $sline = <$scores_info>) { if ($sline=~ m/fixedstep/) { @data = split(' ', $sline); @begin = split('=', $data[2]); $count = $begin[1]; print $sline; } else { print $count++ . "\t" . $sline; } }
output:
fixedstep chrom=chr22 start=14430001 step=1 14430001 144300010.000 14430002 0.002 14430003 0.030 14430004 0.990 14430005 0.000 14430006 0.000 14430007 0.000 fixedstep chrom=chr22 start=16730005 step=1 16730005 0.990 16730006 0.000 16730007 0.000
Comments
Post a Comment