Fetch scaf.pl

From RAJ INFO
Revision as of 20:08, 29 December 2009 by Raj (talk | contribs) (New page: <source lang=perl> #! /usr/bin/perl -w # ************************************************************* # This Programme does the following in sequence # -> Parse the co-ordinates files #...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<source lang=perl>

  1. ! /usr/bin/perl -w
  1. *************************************************************
  2. This Programme does the following in sequence
  3. -> Parse the co-ordinates files
  4. -> Select the scaffolds
  5. -> Mark the specific region
  6. -> Add 300bp on both the sides
  7. -> Fetch the scaffolds as fasta and then as a multifasta
  8. Author : Rajkumar (itc@rajkumar.in)
  9. Release: DEC 2009
  10. *************************************************************
  1. Libraries

use strict; use Bio::Perl; use Bio::SearchIO;

  1. At the top: Time Start

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

  1. Variables

my $path = "/home/raj/bio"; my $scafdir = "$path/euca/data/grandis/scaffold/trim"; my $blastdir = "$path/euca/blast"; my $resdir = "$blastdir/scaffold"; my $scaf_coor = "$blastdir/scaf_coor_curated.stat"; my $addbp = "300"; my $scaf_ssr_dir = "$path/euca/data/grandis/scaffold/ssr"; my $scaf_ssr = "$scaf_ssr_dir/scaf_ssr.fa";


my ($i, $file, $file_)= $_; my (@files, @files1, @array) = @_;

  1. Parsing Functions

# Having the required dir if (-e "$resdir") {`rm -fr $resdir`;} if (! -e "$resdir") {`mkdir $resdir`;} if (-e "$scaf_ssr_dir") {`rm -fr $scaf_ssr_dir`;} if (! -e "$scaf_ssr_dir") {`mkdir $scaf_ssr_dir`;}

foreach my $line (split ("\n", `cat $scaf_coor`)) {

my ($scaf_id, $start, $end) = split(/\t/, $line);


# Adding 300bp on both the sides my $length = (); my $math = $start-$addbp; if ($math > 0) { $start = $start - $addbp; $length = $end - $start + $addbp; }

else { $length = $end - $start + $addbp; }


# Get the scaffolds opendir (DIR, "$scafdir") or die $!; @files = readdir(DIR); close(DIR); foreach my $file(@files) { next if ($file !~ m/$scaf_id.txt/g);

my $in = Bio::SeqIO->new(-file => "$scafdir/$file", -format => 'Fasta'); my $identifier; my $sequence;

while ( my $seq = $in->next_seq() ) { $identifier = $seq->id;

 				$sequence = $seq->seq;
 				
 				$identifier = "GRAN_".$identifier;
 				$sequence = substr($sequence, $start, $length);
 				
 				my $fasta = ">$identifier\n$sequence\n";
 				open (FH, ">>".$resdir."/".$file);

print FH "$fasta"; close FH;

print "\tWritten $scaf_id\n"

 			}	

}

}


# Make a multifasta of results file opendir (DIR, "$resdir") or die $!; @files1 = readdir(DIR); close(DIR); foreach my $file1(@files1) { next if ($file1 eq "." or $file1 eq ".."); push(@array, "$file1");

chdir $resdir; `cat @array >$scaf_ssr`;

}


print "\nDone!\n\n";

  1. 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";

  1. END

</perl>