#!/usr/local/bin/perl

# Example program 3.  Perform a relative rate test for
# three related sequences.  The program accepts three
# inputs, from a dissimilarity matrix.  As in Chapter 3,
# elements 1 and 2 represent the ingroup, element 3 the
# outgroup.  The inputs to this program are d12, d13, d23.


# Make sure there are 3 inputs, store them for future use,
# and print them out.

if ( @ARGV != 3 )
{
  printf( "$0: <d12> <d13> <d23> \n\n" );
  exit( 1 );
} # if

$d12 = $ARGV[0];
$d13 = $ARGV[1];
$d23 = $ARGV[2];

printf( "d12: $d12\n" );
printf( "d13: $d13\n" );
printf( "d23: $d23\n\n" );


# Make sure that the inputs make some sense: that
# element 3 seems to represent the outgroup.

if (    ( ( 2 * $d12 ) >= $d13 )
     && ( ( 2 * $d12 ) >= $d23 )
   )
{
  printf( "$0: Element 3 does not appear to represent"
        . " the outgroup.\n\n" );
  exit( 1 );
} # if

# Compute and print dA1 and dA2.

$dA1 = ( $d12 + $d13 - $d23 ) / 2;
$dA2 = ( $d12 + $d23 - $d13 ) / 2;

printf( "dA1: $dA1\n" );
printf( "dA2: $dA2\n\n" );

