#!/usr/bin/perl 
#===============================================================================
#
#         FILE:  BoundfromTopHat.pl
#
#        USAGE:  ./BoundfromTopHat.pl  
#
#  DESCRIPTION:  Extract boundary information needed by IsoInfer from the output
#                (junction.bed) of TopHat.
#
#                Supported version:
#                    TopHat         :        V1.0.13
#                    IsoInfer       :        V0.8.2
#
#      OPTIONS:  ---
# REQUIREMENTS:  ---
#         BUGS:  ---
#        NOTES:  ---
#       AUTHOR:  Jianxing Feng (feeldead), feeldead@gmail.com
#      COMPANY:  THU
#      VERSION:  1.0
#      CREATED:  07/26/2010 09:14:57 AM
#     REVISION:  ---
#===============================================================================

if( @ARGV < 1 ){
  die("Usage: ./BoundfromTopHat.pl junctions.bed \n");
}

open(Junc, "<$ARGV[0]") or die("Error: cannot open file '$ARGV[0]'\n");

$first = 0;
while (<Junc>)
{
	if ($first == 0)
	{
		$first = 1;
		next;
	}
	elsif ($first == 1)
	{
		$first = 2;
	}
	else
	{
		print "\n";
	}
	chomp;
	@tmp = split(/[ \t]/);
	print "$tmp[1]\t1\n";
	print "$tmp[2]\t0";
}