Count fasta.pl

From RAJ INFO
Jump to navigation Jump to search
#! /usr/bin/perl -w
 
# *************************************************************
# This Programme does the following in sequence
# -> Count Numbers and generate statistics
# -> Singlecored
# Author : Rajkumar (itc@rajkumar.in)
# Release: JUN 2010
# *************************************************************
 
# Libraries
        use strict;
        use Bio::Perl;
        use Bio::SearchIO;
        use List::Util qw[min max];
        use Parallel::ForkManager;
 
 
# At the top: Time Start
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
        localtime(time);
 
# Variables
        my $path    = "/home/raj/bio";
        my $datadir = "$path/tobacco/data";
        my $curdir  = "$path/tobacco/annotation/gt";

        my $infile  = "$datadir/unigenes.fa";
        my $outfile = "$curdir/est.stat";
 
        my ($i, $c_fasta)     = $_;
        my (@length)     = @_;

        my $pm = new Parallel::ForkManager(16);
 

# Genome threader RUN
 
        print "\n\tCounting ...\n";     

        
        # count number of fasta
        $c_fasta = `grep -c ">" $infile`;
        chomp $c_fasta;
        
        
        my $in  = Bio::SeqIO->new(-file => "$infile", -format =>
        'Fasta');
        my $identifier;
        my $sequence;

        $i = 0;
        while ( my $seq = $in->next_seq() ) {
                $identifier = $seq->id;
                $sequence = $seq->seq;
                
                $i++;
                
                my $percent = ($i/$c_fasta)*100;
                $percent = sprintf("%.2f", $percent);
                
                                
                my $length = ($sequence =~ tr/[A-Z]|[a-z]//);
                
                push(@length, "$length");

                
                
                #print "$identifier\t$length\n";
 
        }
        
        my $mini = min(@length);
        my $maxi = max(@length);
        my $c_array = @length;
        
        my $set1  = @length[$mini .. 1000];
        my $set2  = @length[1001 .. 2000];
        my $set3  = @length[2001 .. 3000];
        my $set4  = @length[3001 .. $maxi];
        
        

        print "Max:$maxi\tMini:$mini\tTotalLength:$c_array\n
               Set1:$set1\tSet2:$set2\tSet3:$set3\tSet4:$set4\n";
        


exit;
 
 
# 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