Parse sorghum genome.pl: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
[[Category:Bioinformatics]] | [[Category:Bioinformatics]] | ||
< | <pre> | ||
#! /usr/bin/perl -w | #! /usr/bin/perl -w | ||
| Line 103: | Line 103: | ||
</ | </pre> | ||
Revision as of 06:24, 23 April 2011
#! /usr/bin/perl -w
# *************************************************************
# This Programme does the following in sequence
# -> Parses a multi fasta
# -> Write each sequence as individual files
# Author : Rajkumar (r@rajkumar.in)
# Release: AUG 2010
# *************************************************************
# Libraries
use strict;
use Bio::Perl;
use Bio::SearchIO;
use Parallel::ForkManager;
# Variables
my $path = "/home/raj/bio/user/rk/genome";
my $multifasta = "$path/sb_genome.fa";
my $resdir = "$path/individual_files_fasta";
my $zipdir = "$path/individual_files_zip";
my ($i,$file) = $_;
my (@files) = @_;
# At the top: Time Start
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
# Multi-threading
my $midstop = "0"; # If midstop is 0 it deals with all the files
my $pm = new Parallel::ForkManager(8);
# Getting the grip of files
if (-e "$resdir") {`rm -fr $resdir`;} if (! -e "$resdir") {`mkdir $resdir`;}
if (-e "$zipdir") {`rm -fr $zipdir`;} if (! -e "$zipdir") {`mkdir $zipdir`;}
# Let's Hack
# count the fasta
my $c_fasta = `grep -c ">" $multifasta`; chomp $c_fasta;
my $in = Bio::SeqIO->new(-file => "$multifasta", -format => 'Fasta');
my ($identifier, $sequence) = $_;
$i = 0;
while ( my $seq = $in->next_seq() ) {
$identifier = $seq->id;
$sequence = $seq->seq;
$i++;
$pm->start and next;
my $percent = ($i/$c_fasta)*100;
$percent = sprintf("%.2f", $percent);
my $count_seq = length($sequence);
$count_seq = $count_seq/1000000;
$count_seq = sprintf("%.2f", $count_seq);
my $fasta = ">".$identifier."_Size:".$count_seq."Mb\n".$sequence."\n";
my $id_size = $identifier."_Size:".$count_seq."Mb.fa";
print "\n\tInitiated [$i of $c_fasta] | $percent% ";
open (FH, ">".$resdir."/".$id_size);
print FH $fasta ;
close FH ;
chdir $resdir;
`zip $zipdir/$id_size.zip $id_size`;
$pm->finish;
}
$pm->wait_all_children;
`rm -fr $resdir`;
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