#!/usr/bin/perl

$basepairs = $ARGV[0];
$out_upl = $ARGV[1];
$out_lol = $ARGV[2];

open(IN, "<$basepairs") or die "Reqd args: file.in out.upl out.lol";
open(OUT_UPL, ">$out_upl") or die "Reqd args: file.in out.upl out.lol";
open(OUT_LOL, ">$out_lol") or die "Reqd args: file.in out.upl out.lol";

while (<IN>) {
   ($base1, $res1, $base2, $res2) = split; 
    if (($base1 eq "RGUA") and ($base2 eq "RCYT")) {
      printf OUT_UPL "# $base1 $res1 $base2 $res2
$res1 $base1  H1    $res2 $base2 N3      1.89  1.00E+00
$res1 $base1  N1    $res2 $base2 N3      3.00  1.00E+00
$res1 $base1  H21   $res2 $base2 O2      1.89  1.00E+00
$res1 $base1  N2    $res2 $base2 O2      3.00  1.00E+00
$res1 $base1  O6    $res2 $base2 H41     1.89  1.00E+00
$res1 $base1  O6    $res2 $base2 N4      3.00  1.00E+00
\n";
      printf OUT_LOL "# $base1 $res1 $base2 $res2
$res1 $base1  H1    $res2 $base2 N3      1.80  1.00E+00
$res1 $base1  N1    $res2 $base2 N3      2.90  1.00E+00
$res1 $base1  H21   $res2 $base2 O2      1.80  1.00E+00
$res1 $base1  N2    $res2 $base2 O2      2.90  1.00E+00
$res1 $base1  O6    $res2 $base2 H41     1.80  1.00E+00
$res1 $base1  O6    $res2 $base2 N4      2.90  1.00E+00
\n";

    } elsif (($base1 eq "RCYT") and ($base2 eq "RGUA")) {
           printf OUT_UPL "# $base1 $res1 $base2 $res2
$res1 $base1  N3    $res2 $base2 H1      1.89  1.00E+00
$res1 $base1  N3    $res2 $base2 N1      3.00  1.00E+00
$res1 $base1  O2    $res2 $base2 H21     1.89  1.00E+00
$res1 $base1  O2    $res2 $base2 N2      3.00  1.00E+00
$res1 $base1  H41   $res2 $base2 O6      1.89  1.00E+00
$res1 $base1  N4    $res2 $base2 O6      3.00  1.00E+00
\n";

           printf OUT_LOL "# $base1 $res1 $base2 $res2
$res1 $base1  N3    $res2 $base2 H1      1.80  1.00E+00
$res1 $base1  N3    $res2 $base2 N1      2.90  1.00E+00
$res1 $base1  O2    $res2 $base2 H21     1.80  1.00E+00
$res1 $base1  O2    $res2 $base2 N2      2.90  1.00E+00
$res1 $base1  H41   $res2 $base2 O6      1.80  1.00E+00
$res1 $base1  N4    $res2 $base2 O6      2.90  1.00E+00
\n";

    } elsif (($base1 eq "RADE") and ($base2 eq "URA")) {
           printf OUT_UPL "# $base1 $res1 $base2 $res2
$res1 $base1  N1    $res2 $base2  H3      1.89  1.00E+00
$res1 $base1  N1    $res2 $base2  N3      3.00  1.00E+00
$res1 $base1  H61   $res2 $base2  O4      1.89  1.00E+00
$res1 $base1  N6    $res2 $base2  O4      3.00  1.00E+00
\n";
           printf OUT_LOL "# $base1 $res1 $base2 $res2
$res1 $base1  N1    $res2 $base2  H3      1.80  1.00E+00
$res1 $base1  N1    $res2 $base2  N3      2.90  1.00E+00
$res1 $base1  H61   $res2 $base2  O4      1.80  1.00E+00
$res1 $base1  N6    $res2 $base2  O4      2.90  1.00E+00
\n";

    } elsif (($base1 eq "URA") and ($base2 eq "RADE")) {
           printf OUT_UPL "# $base1 $res1 $base2 $res2
$res1  $base1  H3    $res2 $base2 N1      1.89  1.00E+00
$res1  $base1  N3    $res2 $base2 N1      3.00  1.00E+00
$res1  $base1  O4    $res2 $base2 H61     1.89  1.00E+00
$res1  $base1  O4    $res2 $base2 N6      3.00  1.00E+00
\n";
           printf OUT_LOL "# $base1 $res1 $base2 $res2 
$res1  $base1  H3    $res2 $base2 N1      1.80  1.00E+00
$res1  $base1  N3    $res2 $base2 N1      2.90  1.00E+00
$res1  $base1  O4    $res2 $base2 H61     1.80  1.00E+00
$res1  $base1  O4    $res2 $base2 N6      2.90  1.00E+00
\n";

    }else { printf OUT_UPL "# $base1 $res1 $base2 $res2 \n\n";}
}
close(IN);
close(OUT_UPL);
close(OUT_LOL);
                 
