
package get_fasta;

use strict;
use OORepository;
use WrapDBI;
#
#
# For use with giraffe. 
#  -mng
#
#
#

#
# Create a new module object.
#
sub new {
    my ($type) = shift;
    my $self = {};    
    bless  $self, $type;
    return $self;
}


#
# Return if project is online.
#
sub is_project_online {

    my ($type,$project) = @_;

    my $repos;
    eval {
	$repos = new OORepository;	
    };
    if($@){
	print STDERR "ERROR: $@ \n";
	return;
    }    

    $repos->get_online_path_from_project($project);
    
    if(!defined $repos->{online_path}){
        return 0;
    }else{
        if(($repos->is_project_nearlined($project)) || ($repos->is_project_archived($project))){
            return 0;
        }else{
            return 1;
        }     
    }
}
#
# Get the organism and chromosome from the project. (HUMAN ONLY).
#
sub get_organism_from_project {
    my ($sub,$project) = @_;

    my $dbh;
    eval {
	$dbh = WrapDBI->connect('reports', {RaiseError => 1});
    };
    if($@) {
	warn"ERROR:$@\n";
    }
    my $org = $dbh->fetch_scalar("  select species.speciesname  from species,clone,clone_project,project
                                    where project.projectname = clone_project.projectname
                                    and clone.clonename = clone_project.clonename
                                    and clone.speciesname = species.speciesname
                                    and project.projectname = '$project'
                          ");

    $dbh->disconnect if defined $dbh;
    return($org);
}


#
# Get the EMBL submission name.
#
sub get_embl_name {
    my ($sub,$project)=@_;
    my $dbh;
    eval {
	$dbh = WrapDBI->connect('reports', {RaiseError => 1});
    };
    if($@) {
	warn"ERROR:$@\n";
    }
    my $name = $dbh->fetch_scalar("select name from embl_submission 
                             where accession in ( select accession from finished_submission where projectname = '$project')
                            ");

    $dbh->disconnect if defined $dbh;
    return($name);
}



sub get_fasta_accession {
    my ($sub,$pr) = @_;
    
    my $dbh;
    eval {
        $dbh = WrapDBI->connect('reports', {RaiseError => 1});
    };
    if($@) {
        warn"ERROR:$@\n";
    }
    my $name = $dbh->fetch_scalar("select accession from unfinished_submission where projectname = '$pr'");
    
    
    $dbh->disconnect if defined $dbh;
    return($name);
}





1;



