#!/usr/bin/perl -w
use strict;

#person in charge of this script
#this should be the person currently in charge of scripts for the SGN project
my $script_maintainer='Dan Ilut <dci1@cornell.edu>';

use lib '/data/shared/pgn_data_processing/scripts/perllib';

#local packages to use
use runtime;
use db_link;
use projects;


@ARGV or print "No input parameters, proceeding with default.\n";

my @arg_pairs = split (/\-/, (join ' ', @ARGV));

my %args=();

foreach (@arg_pairs){

    $_ or next;
    my ($flag, $val)=split /\s+/;
    $args{$flag}=$val;
}

my $in_file=$args{'i'};
my $project='fgn';

$in_file or die "Please specify a list of ESTs to check using the -i flag\n";
$project or die "Please specify a project (cgn, fgn, pgn) using the -p flag\n";

my ($db, $usr) = @{projects::get_db_info($project)};
$db or die "No known database for project $project";


#main body of script
#####################

my $start_time=time;

# try to open the database
my $dbh = db_link::connect_db($db, $usr) or die "couldn't open database link\n";
my ($stm, $sth, $rv, $rc);


open FILEIN, $in_file or die "Couldn't open $in_file for read\n";

while (<FILEIN>){

    chomp;

#get the sequence id
    my $seq_id;
    $stm = "select local_db_id from other_identifier where external_id='$_' and external_id_type='1'";
    $sth = $dbh->prepare($stm) 
	|| die "Can't prepare statement: $DBI::errstr";
    $rv = $sth->execute
	|| die "Can't execute statement: $DBI::errstr";
    $rc = $sth->bind_columns(\$seq_id);
    unless ($sth->fetch){
	print "No identifier found for $_\n";
	next;
    }

#mark the sequence delayed
    $stm = "update genbank_submission set delay_for_cause='1' where seq_id='$seq_id'";
    $sth = $dbh->prepare($stm)  
	|| die "Can't prepare statement: $DBI::errstr";
    $rv = $sth->execute 
	|| die "Can't execute statement: $DBI::errstr";
}



db_link::disconnect_db($dbh);



# runtime::runtime_print($start_time, "Pulling EST contig siblings");


