#!/usr/bin/env perl

# generates interaction link files for CRI circos plot from ResearchInterests-MarianMod.tsv
# format looks like this:

# Andersen, B	X		X	X	X													X						Transcriptional Regulation and the Developmental Biology of Epidermis, Cornea, and Mammary Gland; Stem cell proliferation and metabolism.
# Atwood, S	X			X						X														The Atwood lab is interested in how cells choose their fate. We focus on protein kinase regulation of signaling pathways and transcription factors, using models of skin cancer and skin and hair follicle development to determine how kinases influence fate by controlling the genetic landscape of the cell.

# eats that file and generates a link file for Research Interests (which can be plotted separately
# or with other, coordinated in the conf file.

my $lnkwdth = 1;
my $mid = 50; # the ~midpoint of the size of PI span (currently 100).

my @int = ("spacer", "brain","skin","blood","breast","immune","intest","lung","stem","prost","tumoruv","metast",
"cellsignal","metab","biomark","dnarepair","virol","obes","rnabio","epigen","tools");

#my @int = ("spacer", "Skin","BldCan","BrstCan","Stem","Wnt","MitMet","CanMet","NovThe",
#"ProCan","Kinase","Immuno","Imagng","ColCan","Radn","BioMrk","DNA","Vir","CanBio",
#"Signal","Diabet","RNA","Epigen","Metast");

# @cntsPer holds the number of end links for the interest subjects, to allow the end links to be
# spaced appropriately

my @cntsPer = (0,5,8,8,10,17,7,1,19,4,4,8,12,18,5,5,5,2,7,9,26);
my %offset;

my @color = ("spacer","chr1","chr2","chr3","chr4","chr5","chr6","chr7","chr8",
"chr9","chr10","chr11","chr12","chr13","vlblue","chr15","chr16","chr17",
"chr18","chr19","chr20");

# ,"chr21","chr22","chr23");


while (<>) {
    my $N = my @A = split(/\t/);
    if (!defined $offset{$L1}) {$offset{$L1} = 0;}
    my $L1 = mkID($A[0]); my $L2;
    #print "L1: $L1 ";
    for ($i=1; $i<21; $i++) {
        if ($A[$i] eq "X") { 
            $L2 = $int[$i];  # from the interests array
            my $L1Ab = ($mid - $offset{$L1}++); my $L1Ae = ($mid - $offset{$L1}++);

#            my $L2Ab = ($mid - ($cntsPer[$i]));  $cntsPer[$i]++; #$cntsPer{$L2}++; 
#            my $L2Ae = ($mid - ($cntsPer[$i]));  $cntsPer[$i]++;   # ($cntsPer{$L2}));  $cntsPer{$L2}++;

            my $L2Ab = ($mid - ($cntsPer[$i]));  $cntsPer[$i]--; 
            my $L2Ae = ($mid - ($cntsPer[$i]));  $cntsPer[$i]--;
            #select $FH[$i];
            print    "$L1 $L1Ab $L1Ae $L2 $L2Ab $L2Ae color=$color[$i]\n"; 
            # print    "$L1 48 52 $L2 48 52 color=$color[$i]\n"; 
       }
    }
}
#print "\n";


sub mkID($) {
  my $FN = shift;
  $FN =~ s/ //g;
  $Nn = @An = split(/,/, $FN);
  $LN = substr($An[0],0,3);
  return "${LN}${An[1]}";;
}






