Caps fasta.pl

From RAJ INFO
Revision as of 17:24, 28 December 2009 by Raj (talk | contribs) (New page: <source lang=perl> #! /usr/bin/perl -w # ************************************************************* # This Programme does the following in sequence # -> Parses a multi fasta # -> Makes ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#! /usr/bin/perl -w
# *************************************************************
# This Programme does the following in sequence
# -> Parses a multi fasta
# -> Makes the small letters on CAPS
# -> Write the results

# Author : Rajkumar (itc@rajkumar.in)
# Release: DEC 2009
# *************************************************************

# Libraries
	use strict;
	use Bio::Perl;
	use Bio::SeqIO;

# Variables
	my $path     = "/home/raj/bio";
	my $datadir  = "$path/euca/data/grandis/scaffold/dl";
	my $resdir  = "$path/euca/data/grandis/scaffold/trim";
	my ($i, $file)= $_;
	my (@files)= @_;
	
# At the top: Time Start
	my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

	
# Start your Hack!

	# Get ready with the folders
	if (-e "$resdir") {`rm -fr $resdir`;}
	if (! -e "$resdir") {`mkdir $resdir`;}

	
	opendir (DIR, "$datadir") or die $!;
	@files = readdir(DIR);
	close(DIR);

	#Lets Grab the number of files
	my $count_files = @files;
	$i = 0;
	
	foreach my $file(@files) {
		next if ($file !~ m/.txt/g);

		$i++;
		my $in  = Bio::SeqIO->new(-file => "$datadir/$file", -format => 'Fasta');
		my $identifier;
		my $sequence;
	
		while ( my $seq = $in->next_seq() ) {
			$identifier = $seq->id;
  			$sequence = $seq->seq;
			
			$sequence =~ s/(.+)/\U$1/g;
			
			
			my $fasta = ">$identifier\n$sequence\n";
				 
			open (FH, ">>".$resdir."/".$file);
			print FH "$fasta";
			close FH;
			
			
			print "\r\tWritten $file . Writing $i of $count_files files"

		}
	}

	print "\nAll Done!\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