[Bioperl-l] Passing/Storing "Bio::SeqIO" object to a function

Abhishek Pratap abhishek.vit at gmail.com
Thu Jun 24 16:26:02 UTC 2010


Sure. Here is the full subroutine where I am opening the file handle and
storing them

Thanks for your help,
-A

sub createBins {
 my $SUB ='createBins';
my $PWD = `pwd`;
my $outpath = shift @_;
my $lane = shift @_ ;

 foreach my $bin (keys %{ $indexes->{$lane} })
 {
my $sample_name = $indexes->{$lane}->{$bin}->{'sample'};
my $path="$outpath".'/'."$sample_name";
mkpath( $path, { verbose => 1, mode => 0711 });
 my $out = Bio::SeqIO->new(-format=>'fastq-illumina', -file =>
">$outpath/$sample_name/$fastQFile");
 $bins{$bin}=$out;
 }
}


On Thu, Jun 24, 2010 at 12:22 PM, Warren W. Kretzschmar <wkretzsch at gmail.com
> wrote:

> Where are you getting the filehandles from? That is, How are you
> opening them? Can you show me the code?
>
> Warren
>
> On Thu, Jun 24, 2010 at 12:19 PM, Abhishek Pratap
> <abhishek.vit at gmail.com> wrote:
> > Dear Warren
> > Thanks for your quick reply.  I am doing something very close to what you
> > have suggested but I see errors which might be due to some silly mistake
> I
> > am making. The difference is instead of array I am using a hash to help
> me
> > extract file names by key value later.
> > I am writing data like this.
> > my $file_handle = $bins{$bin_name};
> >  $file_handle->write_seq($data);
> > Gives me an error
> > Can't call method "write_seq" on an undefined value at
> > /home/apratap/dev/eclipse_workspace/Illumina/demultiplex_GA_data.pl line
> > 139, <GEN12> line 5.
> > -Abhi
> > On Thu, Jun 24, 2010 at 11:24 AM, Warren W. Kretzschmar
> > <wkretzsch at gmail.com> wrote:
> >>
> >> Hi,
> >> My understanding is that you are using a SeqIO object in order to
> >> create correctly parsed output files.
> >>
> >> In that case for each SeqIO object, open it like this:
> >>
> >> for (0..9){
> >> $file = "my_file_$_";
> >> push @outseqIOs, Bio::SeqIO->new(-file   => ">$file", -format => $format
> >> );
> >> }
> >>
> >> simply make $file correspond to the file (or bin) you want to put your
> >> data into.
> >>
> >> then pass @outseqIOs to your other subroutine and once you've created
> >> a seq object, write it to the bin you want it to go to (in this case
> >> file number "7"):
> >>
> >> $outseqIOs[7]->write_seq($seq);
> >>
> >> I haven't tested the code, but that's the kind of thing I think you're
> >> looking for. For more info, look at the howto:
> >> http://www.bioperl.org/wiki/HOWTO:SeqIO
> >>
> >> Warren
> >>
> >> On Thu, Jun 24, 2010 at 10:20 AM, Abhishek Pratap
> >> <abhishek.vit at gmail.com> wrote:
> >> > Hi All
> >> >
> >> > I may be hitting a problem which probably hints at my grip of the
> >> > language.
> >> > I am trying to store Bio::SeqIO object in a hash. I have creates
> couple
> >> > of
> >> > Bio::SeqIO objects in a method and storing them as a hash reference.
> The
> >> > goal is to use them in another subroutine for writing out data to each
> >> > file.
> >> > The script is trying to bin data into different files.
> >> >
> >> >
> >> > Any idea how I could achieve creating file handles  thru "Bio::SeqIO"
> >> > object
> >> > in one routine and pass them to another for writing.
> >> >
> >> >
> >> > Thanks!
> >> > -Abhi
> >> >
> >> > foreach my $bin (keys %{ $indexes->{$lane} })
> >> >  {
> >> > my $sample_name = $indexes->{$lane}->{$bin}->{'sample'};
> >> >  my $path="$outpath".'/'."$sample_name";
> >> > mkpath( $path, { verbose => 1, mode => 0711 });
> >> >        my $out = Bio::SeqIO->new(-format=>'fastq-illumina', -file =>
> >> > ">$outpath/$sample_name/$fastQFile");
> >> > $indexes->{$lane}->{$bin}->{'file_handle'}=$out;
> >> >  }
> >> > }
> >> > _______________________________________________
> >> > Bioperl-l mailing list
> >> > Bioperl-l at lists.open-bio.org
> >> > http://lists.open-bio.org/mailman/listinfo/bioperl-l
> >> >
> >
> >
>



More information about the Bioperl-l mailing list