Commit 3a6c7ae5 authored by Sebastien Carrere's avatar Sebastien Carrere
parents 0a9fe9a8 affbf56c
......@@ -8,7 +8,7 @@ sub Upload
my $userid = &__GetUserId(\$o_webbuilder);
my $o_cgi = new CGI;
if (&MODE_TEST == 1) {$userid = "michel@gmail.com";}
if (&MODE_TEST == 1) {$userid = "michel\@gmail.com";}
my %h_param = (
'success' => 0,
......@@ -66,4 +66,121 @@ sub Upload
}
sub ZipUpload
{
my $o_webbuilder = shift;
my $o_param = $o_webbuilder->GetObjectParam;
my $userid = &__GetUserId(\$o_webbuilder);
my $o_cgi = new CGI;
my %h_param = (
'success' => 0,
'message' => 'Problem while uploading file'
);
if (defined $userid)
{
if (!defined $o_cgi->param("zipFile"))
{
$h_param{"message"} = "No file specified";
print to_json(\%h_param);
return;
}
my $original_file_name = $o_cgi->param("zipFile");
my $fh_original = $o_cgi->upload("zipFile");
if (!defined $fh_original)
{
$h_param{"message"} = "Error while copying file";
print to_json(\%h_param);
return;
}
my $original_path = $o_cgi->tmpFileName($fh_original);
my $tmp_dir = $o_webbuilder->GetSessionPath();
my $uploaded_file = $tmp_dir . "/" . basename($original_path);
File::Copy::move($original_path, $uploaded_file);
my $cmd = "mkdir $tmp_dir/unzip; cd $tmp_dir/unzip; unzip -q $uploaded_file";
&System("$cmd");
my @a_zipcontent = `ls $tmp_dir/unzip/*`;
chomp @a_zipcontent;
my $rh_param = &__ValidZipContent(\@a_zipcontent);
%h_param = %{$rh_param};
}
print to_json(\%h_param);
return;
}
sub __ValidZipContent
{
my $ra_zipcontent = shift;
my @a_fastafiles = grep (/(\w+)\.fas?t?a?$/, @{$ra_zipcontent});
my @a_iprscan = grep (/(\w+)\.iprscan$/, @{$ra_zipcontent});
my @a_desc = grep (/(\w+)\.txt$/, @{$ra_zipcontent});
my %h_param = (
'success' => 0,
'message' => 'Problem while uploading file'
);
if (scalar (@a_fastafiles) == 0)
{
$h_param{'message'} = 'ERROR - No fasta file found in your zip file';
return \%h_param;
}
if (scalar (@a_iprscan) > 0 && scalar (@a_iprscan) < scalar (@a_fastafiles))
{
$h_param{'message'} = 'ERROR - Not same number of fasta files and iprscan files in your zip file';
return \%h_param;
}
my @a_references = ();
if (-e "$dirname/references.txt")
{
@a_references = split ('\n', &Cat("$dirname/references.txt"));
}
my %h_data = ();
foreach my $file (@a_fastafiles)
{
my $dirname = dirname ($file);
my ($code) = ($file =~ /(\w+)\.fas?t?a?$/);
$h_data{$code} = {'fasta' => $file};
if (scalar @a_iprscan > 0 && ! -e "$dirname/$code.iprscan")
{
$h_param{'message'} = 'ERROR - Iprscan file not found for $code in your zip file';
return \%h_param;
}
else
{
$h_data{$code}->{'iprscan'} = "$dirname/$code.iprscan";
}
if (-e "$dirname/$code.txt")
{
$h_data{$code}->{'title'} = &Cat("$dirname/$code.txt");
}
$h_data{$code}->{'reference'} = &FALSE;
$h_data{$code}->{'reference'} = &TRUE if (grep (/^$code$/, @a_references));
}
$h_param{'success'} = 1;
$h_param{'message'} = scalar (keys %h_data) . ' proteome found in your zip file';
$h_param{'zipdata'} = \%h_data;
return \%h_param;
}
1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment