jpoldot has asked for the wisdom of the Perl Monks concerning the following question:
fixedStep chrom=chrX start=1 step=1 0.930
0.955
0.972
0.985
0.993
0.995
0.994
0.990
0.984
0.971
0.942
0.944
0.971
fixedStep chrom=chrX start=200 step=1
0.987
The problem is that, apart from the numbers shown, there are these headers found in the file multiple times. I want to construct a program that stores the position and the value, that means:
1 0.9302 0.955
etc
the numbering starts from where it is indicated by the number stored in the field start, that is start = 200 etc...So this means:
200 0.987
etc
I have constructed the following code:
#!/usr/bin/perl -w print "Please enter the filename of your file: "; $dnafilename = <STDIN>; chomp $dnafilename; unless ( -e $dnafilename) { print "File \"$dnafilename\" doesn't seem to exist!!\n"; exit; } unless ( open(DNAFILE, $dnafilename) ) { print "Cannot open file \"$dnafilename\"\n\n"; exit; } while ( <DNAFILE> ) { next if (/fixedStep chrom=chrX start=(.+) step=1/); $counter = $1; } print "$counter\t$_\n"; close DNAFILE; exit;
With awk, we could do it easily with the command: nawk -F' =' 'NF>1{start=$5;next}{print start++,$0}' myFile but I need a program...Any help would be greatly appreciated :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to continue numbering after a regular expression has been found
by jethro (Monsignor) on Feb 11, 2011 at 12:30 UTC | |
by jpoldot (Initiate) on Feb 11, 2011 at 12:49 UTC | |
by Ratazong (Monsignor) on Feb 11, 2011 at 13:01 UTC | |
|
Re: How to continue numbering after a regular expression has been found
by Ratazong (Monsignor) on Feb 11, 2011 at 12:21 UTC |