Read split.pl: Difference between revisions

From RAJ INFO
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
[[Category:Bioinformatics ]]
[[Category:Bioinformatics ]]
<source lang=perl>
<source lang=perl>
#! /usr/bin/perl -w
#! /usr/bin/perl -w
# *************************************************************
# *************************************************************
# This Programme does the following in sequence
# This Programme does the following in sequence
# -> Parses a multi fasta
# -> Parses a multi fasta
# -> count characters and splits as (1) 0 (2) <80 (3) >80
# -> Count characters and splits as (1) 0 (2) <=80 (3) >80
# -> Capture the results
# -> Capture the results in files in 3 catogories
# -> Generates the statistics
# -> Generates Tab delimited file with ID and size
# Author : Rajkumar (itc@rajkumar.in)
# Author : Rajkumar (itc@rajkumar.in)
# Release: MAR 2010
# Release: MAR 2010
Line 19: Line 19:
   
   
# Variables
# Variables
my $path = "/home/raj/bio/user/raja";
my $path       = "/home/raj/bio/user/raja";
my $multifasta = "$path/set_1.txt";
my $multifasta = "$path/set_1.txt";
my $file1 = "reads_0bp.txt";
my $file1     = "reads_0bp.txt";
my $file2 = "reads_1-80bp.txt";
my $file2     = "reads_1-80bp.txt";
my $file3 = "reads_80+bp.txt";
my $file3     = "reads_80+bp.txt";
my $statfile = "stat.txt";
my $statfile   = "stat.txt";
my $idfile    = "id_size.txt";
   
   
# spliting
# Getting the grip of files
  if (-e "$file1") {`rm  $file1`;}
  if (-e "$file1") {`rm  $file1`;}
if (-e "$file2") {`rm  $file2`;}
if (-e "$file2") {`rm  $file2`;}
if (-e "$file3") {`rm  $file3`;}
if (-e "$file3") {`rm  $file3`;}
if (-e "$idfile") {`rm  $idfile`;}


# Let's Hack
my $in  = Bio::SeqIO->new(-file => "$multifasta", -format => 'Fasta');
my $in  = Bio::SeqIO->new(-file => "$multifasta", -format => 'Fasta');
my ($identifier, $sequence) = $_;
my ($identifier, $sequence) = $_;
Line 38: Line 39:
$identifier = $seq->id;
$identifier = $seq->id;
   $sequence = $seq->seq;
   $sequence = $seq->seq;


my $fasta = ">$identifier\n$sequence\n";
my $count_seq = length($sequence);
my $count_seq = length($sequence);
 
my $fasta = ">".$identifier."_Size:".$count_seq."bp\n".$sequence."\n";
my $id_size = "$identifier\t$count_seq\n";
if ($count_seq eq 0){  
if ($count_seq eq 0){  
open (FH, ">>".$file1);
open (FH, ">>".$file1);
print FH $fasta ;
print FH $fasta ;
close FH ;
close FH ;
open (FH, ">>".$idfile);
print FH $id_size ;
close FH ;
}
}
if ( $count_seq < 81 && $count_seq > 0){  
if ( $count_seq < 81 && $count_seq > 0){  
open (FH, ">>".$file2);
open (FH, ">>".$file2);
print FH $fasta ;
print FH $fasta ;
close FH ;
open (FH, ">>".$idfile);
print FH $id_size ;
close FH ;
close FH ;
}
}
if ( $count_seq > 80){  
if ( $count_seq > 80){  
open (FH, ">>".$file3);
open (FH, ">>".$file3);
print FH $fasta ;
print FH $fasta ;
close FH ;
open (FH, ">>".$idfile);
print FH $id_size ;
close FH ;
close FH ;
}
}
Line 64: Line 81:
my $stat2 = `grep -c ">" $file2`; chomp $stat2;
my $stat2 = `grep -c ">" $file2`; chomp $stat2;
my $stat3 = `grep -c ">" $file3`; chomp $stat3;
my $stat3 = `grep -c ">" $file3`; chomp $stat3;
 
 
my $stat = "Statistics\n==========\n$file1    $stat1 sequences\n$file2 $stat2 sequences\n$file3  $stat3 sequences\n";
my $stat = "Statistics\n==========\n$file1    $stat1 sequences\n$file2 $stat2 sequences\n$file3  $stat3 sequences\n";
open (FH, ">".$statfile);
open (FH, ">".$statfile);
print FH $stat ;
print FH $stat ;
close FH ;
close FH ;
# END


# END
</source>
</source>

Revision as of 03:31, 8 April 2010

#! /usr/bin/perl -w
# *************************************************************
# This Programme does the following in sequence
# -> Parses a multi fasta
# -> Count characters and splits as (1) 0 (2) <=80 (3) >80
# -> Capture the results in files in 3 catogories
# -> Generates the statistics
# -> Generates Tab delimited file with ID and size
# Author : Rajkumar (itc@rajkumar.in)
# Release: MAR 2010
# *************************************************************
 
# Libraries
	use strict;
	use Bio::Perl;
	use Bio::SeqIO;
 
# Variables
	my $path       = "/home/raj/bio/user/raja";
	my $multifasta = "$path/set_1.txt";
	my $file1      = "reads_0bp.txt";
	my $file2      = "reads_1-80bp.txt";
	my $file3      = "reads_80+bp.txt";
	my $statfile   = "stat.txt";
	my $idfile     = "id_size.txt";
 
# Getting the grip of files
 	if (-e "$file1") {`rm  $file1`;}
	if (-e "$file2") {`rm  $file2`;}
	if (-e "$file3") {`rm  $file3`;}
 	if (-e "$idfile") {`rm  $idfile`;}

# Let's Hack
	my $in  = Bio::SeqIO->new(-file => "$multifasta", -format => 'Fasta');
	my ($identifier, $sequence) = $_;
 	while ( my $seq = $in->next_seq() ) {
		$identifier = $seq->id;
  		$sequence = $seq->seq;
 

		my $count_seq = length($sequence);
		my $fasta = ">".$identifier."_Size:".$count_seq."bp\n".$sequence."\n";
		my $id_size = "$identifier\t$count_seq\n";
 
		if ($count_seq eq 0){ 
			open (FH, ">>".$file1);
			print FH $fasta ;
			close FH ;

			open (FH, ">>".$idfile);
			print FH $id_size ;
			close FH ;
			
		}
 
		if ( $count_seq < 81 && $count_seq > 0){ 
			open (FH, ">>".$file2);
			print FH $fasta ;
			close FH ;

			open (FH, ">>".$idfile);
			print FH $id_size ;
			close FH ;
		}
 
		if ( $count_seq > 80){ 
			open (FH, ">>".$file3);
			print FH $fasta ;
			close FH ;


			open (FH, ">>".$idfile);
			print FH $id_size ;
			close FH ;
		}		
	}
# statistics
	my $stat1 = `grep -c ">" $file1`; chomp $stat1;
	my $stat2 = `grep -c ">" $file2`; chomp $stat2;
	my $stat3 = `grep -c ">" $file3`; chomp $stat3;		
 
 
	my $stat = "Statistics\n==========\n$file1    $stat1 sequences\n$file2 $stat2 sequences\n$file3  $stat3 sequences\n";
	open (FH, ">".$statfile);
	print FH $stat ;
	close FH ;		
 
# END