Read split.pl: Difference between revisions

From RAJ INFO
Jump to navigation Jump to search
m Created page with '<source lang=perl> #! /usr/bin/perl -w # ************************************************************* # This Programme does the following in sequence # -> Parses a multi fasta …'
 
mNo edit summary
Line 1: Line 1:
[[Category:Bioinformatics ]]
<source lang=perl>
<source lang=perl>



Revision as of 17:59, 7 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
 
# 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";
 
# spliting
 	if (-e "$file1") {`rm  $file1`;}
	if (-e "$file2") {`rm  $file2`;}
	if (-e "$file3") {`rm  $file3`;}

	
	
	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 $fasta = ">$identifier\n$sequence\n";
		my $count_seq = length($sequence);

		if ($count_seq eq 0){ 
			open (FH, ">>".$file1);
			print FH $fasta ;
			close FH ;
		}
		
		if ( $count_seq < 81 && $count_seq > 0){ 
			open (FH, ">>".$file2);
			print FH $fasta ;
			close FH ;
		}
						 
		if ( $count_seq > 80){ 
			open (FH, ">>".$file3);
			print FH $fasta ;
			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