Parse blast est-gdna sorghum.pl

From RAJ INFO
Jump to navigation Jump to search


#! /usr/bin/perl -w
 
# *************************************************************
# This Programme does the following in sequence
# -> Parse the Blast output of scaffold mapping
# -> Write the results into a seperate folder with each identifier
# -> Write the statistics files (est_scaf_hit.stat, unique_scaf_hit.stat)
# Author : Rajkumar (itc@rajkumar.in)
# Release: APR 2009
# *************************************************************
 
# Libraries
	use strict;
	use Bio::Perl;
	use Bio::SearchIO;
 
# At the top: Time Start
	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
 
# Variables
	my $path      = "/home/raj/bio";
	my $infile    = "$path/user/rk/pmapping/est_sorghum.blast.out";
	my $tempdir   = "$path/user/rk/pmapping/temp";
	my $resdir    = "$path/user/rk/pmapping/result";
 
	my ($i)       = $_;
	my (@files)   = @_;
 
# Parsing Functions
 
	# Having the required dir
	if (-e "$tempdir") {`rm -fr $tempdir`;}
	if (! -e "$tempdir") {`mkdir $tempdir`;}
	if (-e "$resdir") {`rm -fr $resdir`;}
	if (! -e "$resdir") {`mkdir $resdir`;}
 
 
 
	# Let's Parse the file to have files written for indiavidual ESTs
 
	foreach my $line (split ("\n", `cat $infile`)) {
 
		next if ($line !~ m/^PUT-/);

		foreach my $tab (split ("\t", $line)) {
			next if ($tab !~ m/^PUT/);
 
			if ($tab =~ m/^PUT/) {
 
				open (FH, ">>".$tempdir."/".$tab.".gff");
				print FH "$line\n";
				close FH;
			}
		}
        }
 
 
# Work woth the temp file to pick only the top hits with one scaffold
	opendir (DIR, "$tempdir") or die $!;
	@files = readdir(DIR);
	close(DIR);
 	
	foreach my $file(@files) {
		next if ($file eq "."  or $file eq "..");
 		$i = 0;
		foreach my $line_ (split ("\n", `cat $tempdir/$file`)) {
 
			# Filters only the top hit EST 
			
			$i++;
			next if ($i>1);

			open (F, ">>".$resdir."/est_sorghum.blast.tophit.out");
			print F "$line_\n";
			close F;
		}
	}
 
	# cleaning the temp dir
	if (-e "$tempdir") {`rm -fr $tempdir`;}
	
	
 
 
	print "\nDone!\n\n";
 
# At the End: Time Calculation
	my ($sec_,$min_,$hour_,$mday_,$mon_,$year_,$wday_,$yday_,$isdst_) = localtime(time);
	my $days  = $mday_-$mday;
	my $hours = $hour_-$hour;
	my $mins  = $min_-$min;
	my $secs  = $sec_-$sec;
	print "\n------------------------\nDuration: ";
	if ($days>0) { print "$days days";}
	if ($hours>0) { print ": $hours hours";}
	if ($mins>0) { print ": $mins mins";}
	if ($secs>0) { print ": $secs secs";}
	print "\n------------------------\n";
 
# END