Fetch scaf.pl
<source lang=perl>
- ! /usr/bin/perl -w
- *************************************************************
- This Programme does the following in sequence
- -> Parse the co-ordinates files
- -> Select the scaffolds
- -> Mark the specific region
- -> Add 300bp on both the sides
- -> Fetch the scaffolds as fasta and then as a multifasta
- Author : Rajkumar (itc@rajkumar.in)
- Release: DEC 2009
- *************************************************************
- Libraries
use strict; use Bio::Perl; use Bio::SearchIO;
- At the top: Time Start
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
- 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) = @_;
- 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";
- 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
</perl>