[Bioperl-guts-l] [16765] bioperl-run/trunk/lib/Bio/Tools/Run/Bowtie.pm: Add Bio::SeqFeature: :Collection creation

Dan Kortschak kortsch at dev.open-bio.org
Tue Jan 26 20:44:59 EST 2010


Revision: 16765
Author:   kortsch
Date:     2010-01-26 20:44:58 -0500 (Tue, 26 Jan 2010)
Log Message:
-----------
Add Bio::SeqFeature::Collection creation

Modified Paths:
--------------
    bioperl-run/trunk/lib/Bio/Tools/Run/Bowtie.pm

Modified: bioperl-run/trunk/lib/Bio/Tools/Run/Bowtie.pm
===================================================================
--- bioperl-run/trunk/lib/Bio/Tools/Run/Bowtie.pm	2010-01-26 16:53:24 UTC (rev 16764)
+++ bioperl-run/trunk/lib/Bio/Tools/Run/Bowtie.pm	2010-01-27 01:44:58 UTC (rev 16765)
@@ -56,6 +56,10 @@
  # get the file object of the last assembly
  $io = $bowtie_fac->result( -want => 'Bio::Root::IO' );
  
+ # get a merged SeqFeature::Collection of all hits
+ #  - currently only available with SAM format 
+ $io = $bowtie_fac->result( -want => 'Bio::SeqFeature::Collection' );
+ 
  #... or the file name directly
  $filename = $bowtie_fac->result( -want => 'raw' );
  
@@ -468,10 +472,14 @@
 					}
 					last;
 				};
+				m/^bowtie/i && $want =~ m/^Bio::SeqFeature::Collection/ && do {
+					$self->warn("Don't know how to create a $want object for $cmd with bowtie format - try SAM format.");
+					last;
+				};
 				m/^sam/i && $want =~ m/^Bio::Assembly::Scaffold/ && do {
 					unless (defined $self->{'_result'}->{'object'} &&
 						ref($self->{'_result'}->{'object'}) =~ m/^Bio::Assembly::Scaffold/) {
-							my $bamf = $self->_make_bam($self->{'_result'}->{'file_name'});
+							my $bamf = $self->_make_bam($self->{'_result'}->{'file_name'}, 1);
 							my $inspector = Bio::Tools::Run::Bowtie->new( -command => 'inspect' );
 							my $refdb = $inspector->run($self->{'_result'}->{'index'});
 							$self->{'_result'}->{'object'} =
@@ -479,6 +487,18 @@
 					}
 					last;
 				};
+				m/^sam/i && $want =~ m/^Bio::SeqFeature::Collection/ && do {
+					unless (defined $self->{'_result'}->{'object'} &&
+						ref($self->{'_result'}->{'object'}) =~ m/^Bio::Assembly::Scaffold/) {
+							my $bamf = $self->_make_bam($self->{'_result'}->{'file_name'}, 0);
+							my $convert = Bio::Tools::Run::BEDTools->new( -command => 'bam_to_bed' );
+							my $bedf = $convert->run( -bed => $bamf );
+							my $merge = Bio::Tools::Run::BEDTools->new( -command => 'merge' );
+							$merge->run($self->{'_result'}->{'index'});
+							$self->{'_result'}->{'object'} = $merge->result( -want => $want );
+					}
+					last;
+				};
 				do {
 					$self->warn("Don't know how to create a $want object for $cmd.");
 					return;
@@ -547,24 +567,22 @@
 =head2 _make_bam()
 
  Title   : _make_bam
- Usage   : $bowtiefac->_make_bam( $file )
+ Usage   : $bowtiefac->_make_bam( $file, $sort )
  Function: make a sorted BAM format file from SAM file
  Returns : sorted BAM file name
- Args    : SAM file name
+ Args    : SAM file name and boolean flag to select sorted BAM format
 
 =cut
 
 sub _make_bam {
-        my ($self, $file) = @_;
+        my ($self, $file, $sort) = @_;
         
         $self->throw("'$file' does not exist or is not readable")
                 unless ( -e $file && -r _ );
 
         # make a sorted bam file from a sam file input
         my ($bamh, $bamf) = $self->io->tempfile( -dir => $self->tempdir(), -suffix => '.bam' );
-        my ($srth, $srtf) = $self->io->tempfile( -dir => $self->io->tempdir(CLEANUP=>1), -suffix => '.srt' ); 
-		# shared tempdir, so make new - otherwise it is scrubbed during Bio::DB::Sam
-	$_->close for ($bamh, $srth);
+	$bamh->close;
         
         my $samt = Bio::Tools::Run::Samtools->new( -command => 'view',
                                                    -sam_input => 1,
@@ -572,11 +590,18 @@
 
         $samt->run( -bam => $file, -out => $bamf );
 
-        $samt = Bio::Tools::Run::Samtools->new( -command => 'sort' );
-
-        $samt->run( -bam => $bamf, -pfx => $srtf);
-
-        return $srtf.'.bam'
+	if ($sort) {
+		my ($srth, $srtf) = $self->io->tempfile( -dir => $self->io->tempdir(CLEANUP=>1), -suffix => '.srt' ); 
+			# shared tempdir, so make new - otherwise it is scrubbed during Bio::DB::Sam
+		$srth->close;
+		
+		$samt = Bio::Tools::Run::Samtools->new( -command => 'sort' );
+		$samt->run( -bam => $bamf, -pfx => $srtf);
+		
+		return $srtf.'.bam';
+	} else {
+		return $bamf;
+	}
 }
 
 =head2 _validate_file_input()



More information about the Bioperl-guts-l mailing list