Help starting a script

Hi guys, i already search in this forum and i can't find a way to do this. I have a file like this:

-1    1    lig
-1    1    lig
-1    1    lig
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec

And i need to compare the values of columns $1 and $2 and get a output with the results of diferences combinations, for exemple if $1=1 and $2=1 output TP, if $1=1 and $2=-1 output FP if $1=-1 and $2=1 output FN

The point is to count compare colum $1 that is a results from other script with colum $2 that is reall results and see if it is true positives, false negatives and false positives.

I already seach and im thinking using AWK with IF, but i don't know how to tell in the IF part of the script that

 if $1==1 $2==1 print TP for output.

Any ideas are wellcome thanks :smiley:

And if you have $1==-1 and $2==-1?

#!/usr/bin/perl -w                                                                                                                    
                                                                                                                                      
@a=qw(0 0 0 0);                                                                                                                       
while(<>){                                                                                                                            
    /^(.+?)\s+(.+?)\s+/;                                                                                                              
    $a[0]++,next if($1 == 1 && $2 == 1);                                                                                              
    $a[1]++,next if($1 == 1 && $2 == -1);                                                                                             
    $a[2]++,next if($1 == -1 && $2 == 1);                                                                                             
    $a[3]++,next if($1 == -1 && $2 == -1);                                                                                            
}                                                                                                                                     
                                                                                                                                      
print"$a[0]     $a[1]   $a[2]   $a[3]\n";

syntax: ./script filename

1 Like

Because i only need to count the number of the these ocorrences for caculate the precision and recall of my data :wink:

#!/usr/bin/perl -w                                                                                                                    
                                                                                                                                      
@a=qw(0 0 0 0);                                                                                                                       
while(<>){                                                                                                                            
    /^(.+?)\s+(.+?)\s+/;                                                                                                              
    $a[0]++,next if($1 == 1 && $2 == 1);                                                                                              
    $a[1]++,next if($1 == 1 && $2 == -1);                                                                                             
    $a[2]++,next if($1 == -1 && $2 == 1);                                                                                             
    $a[3]++,next if($1 == -1 && $2 == -1);                                                                                            
}                                                                                                                                     
                                                                                                                                      
print"$a[0]     $a[1]   $a[2]   $a[3]\n";

I was trying to do this in bash with awk because the rest of my scripts is in bash (im from Biology and im very new with bash and is the 1st linguage that im learning and i don't know how to use more)

Thanks for the fast reply

Please post what the matching output from the 9 lines in the sample input in post #1 should look like.

The aim is to count the number of occurences:

-1    1    lig -> this is a FN
-1    1    lig -> this is a FN
-1    1    lig -> this is a FN
-1    -1    dec 
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec
-1    -1    dec

So im trying to print something like this "FN=3 TP=0 TN=0" because when $1=-1 and $2=-1 i don't need to count

Maybe I'm being thick but I repeat:
Please post what the matching output from the 9 lines in the sample input in post #1 should look like.

Like i said the output can be in any format the important is that i can count how many conditions of the 3 that i said there are in the file.

So with awk i was thinking in a output like this:

TP=0 (the number of $1=1 and $2=1 are in the file)
FP=0 (the number of $1=1 and $2=-1 are in the file)
FN=3 (the number of $1=-1 and $2=1 are in the file)

or can be like 3 files one for the TP other for FP other for FN and i will wc -l the files to get the number of each occurence like this:

FN File
1
1
1
0
0
0
0
0
0

I ONLY SEE NOW THAT MY LAST POST WAS WRONG REALLY SORRY ABOUT THAT NOW IS CORRECT!!!

In this exemple the only condition that is verified is the one when $1=-1 $2=1 so is a FN, so there are no condition of $1=1 $2=1 that are a TP and there are no condition for $1=-1 $2=1 FP. And the condition $1=-1 $2=-1 i don't need to count.

I'm sorry if this is not to much easy to understand. But the output file doesn't matter because what i need is to know the number of each one of the conditions are.

---------- Post updated at 10:23 AM ---------- Previous update was at 06:01 AM ----------

Well after a lot of trys i just change a bit this script and put it to run with the bash.

Thanks a lot this do exactly what i need :smiley: