Hi,
I wrote a script to compare values on two columns, but I only want to do this while the id on the 4th column remains the same.
The file looks like this:
chr1 15865 15915 cg13869341 908 913
chr1 18827 18877 cg14008030 688 776
chr1 29407 29457 cg12045430 43 70
chr1 29407 29457 cg12045430 43 88
chr1 29407 29457 cg12045430 43 16
chr1 29425 29475 cg20826792 57 70
chr1 29425 29475 cg20826792 57 88
chr1 29425 29475 cg20826792 57 16
chr1 29435 29485 cg00381604 33 70
chr1 29435 29485 cg00381604 33 88
chr1 29435 29485 cg00381604 33 16
chr1 68849 68899 cg20253340 560 593
chr1 69591 69641 cg21870274 791 809
chr1 91550 91600 cg03130891 55 84
So for example I want to compare line 3,4,5 because they have the same id in column 4.
My code looks like this now:
open(intersectMethyl,'<',"intersect148methyl.bed") or die $!;
my @methylData = <intersectMethyl>;
close(intersectMethyl);
my @methylScore;
my @ids;
for my $line(@methylData){
my($chr,$start,$end,$id,$scoreNormal,$scoreTumor) = split("\t",$li
+ne);
push(@ids, $id);
for ($i = 1; $i<eof; $i++){
if (@ids[$i]==@ids[$i-1] && (($scoreTumor/1000) - ($scoreNormal
+/1000) >= 0.2)){
push(@methylscore, "$chr $start $end $id $scoreNor
+mal $scoreTumor")
}
}
}
open(RESULTS,'>','methylDifferences.txt') or die $!;
foreach(@methylscore){
print RESULTS "$_\n";
}
close(RESULTS);
But this doesn't work..
Could somebody help me?
Thanks!
-
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.