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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.