#!/usr/bin/perl

##-------------------------------------------
## Included modules
##-------------------------------------------
##  Basic Perl modules
use strict;
use warnings;
use diagnostics;

## BioPerl modules
use Bio::DB::Fasta;

## Debug
use Data::Dumper;


&main();
sub main {
	##-------------------------------------------
	# INTRODUCTION
	##-------------------------------------------
	my $self={};
	bless $self;

	##-------------------------------------------
	# Input fasta management
	##-------------------------------------------
	print(" Now opening FASTA file test.fna");
	$self->{fastaObj} =  Bio::DB::Fasta->new("test.fna", -reindex => 1);
	my @seq_ids = $self->{fastaObj}->get_all_ids;
	print(" ids from get_all_ids: ", Dumper @seq_ids, "\n");

	print(" Dumper de BioDBFAsta obj: ", Dumper $self->{fastaObj}, "\n");

	# initialize sequence stream obj
	my $seq_stream = $self->{fastaObj}->get_PrimarySeq_stream();
	#my $seq_stream = $seqObj->get_PrimarySeq_stream();
	print(" Dumper de seq_stream", Dumper $seq_stream, "\n");

	$self->{nbSeqFetchedInStream}=0;

	# loop over all seq in BioDBFasta obj using stream
	while (defined($self->{seq} = $seq_stream->next_seq())){
	#foreach my $seq_id (@seq_ids){
		#$self->{seq} = $self->{fastaObj}->get_Seq_by_id($seq_id); # to use with foreach loop
		print(" New sequence: ", Dumper $self->{seq}, "\n");
		$self->{nbSeqFetchedInStream}++;

	}

	print(" Fetched sequences with _PrimarySeq_stream: $self->{nbSeqFetchedInStream}\n");
}
