ProDBWiki/DeveloperDocumentation/copyDB

From BRF-Software
Jump to navigation Jump to search

CopyDB.cgi

Overview

CopyDB.cgi is a script at the mascot server. It handles the setting and getting from a database. To write this script had two different reasons. First the function reduce_search_space (ProDBWiki/DeveloperDocumentation/reduceSearchSpace) from msanalysis.cgi needed to send a database to mascot, so that it can make a search against the database. Therefore you can use the function set_database. Second, the search tool emowse needed to get the selected databases, from the search form, from mascot to submit his searches to the databases. For this problem you can use the function get_database.

A request is send via HTTP to this script. To use one of the functions you need to set different attributes set = 1 for set_database and get = 1 for get_database. You'll find further informations in the sections to the funtions.

set_database

To call this function, you need to include the packages HTTP::Request, HTTP::Request::Common and HTTP::Response. Here is an example for the request:

# header for the Mascot request
my $browser = 'Mozilla/4.77C-CCK-MCD  [en] (X11; U; SunOS 5.8 sun4u; Nav)';
my @request_data = (Connection => 'Keep-Alive',
    Accept => 'image/gif, image/jpeg, image/png, */*',
    Accept_Charset  => 'iso-8859-1,*,utf-8',
    Accept_Encoding => 'gzip',
    Accept_Language => 'de, en',
    Host => 'mascot',
    User_Agent => $browser,
    Content_Type => "multipart/form-data",
    );

# creates a new User Agent
my $ua = LWP::UserAgent::->new();

# create the URL object
my $url = new URI::URL("http://mascot/cgi/copyDB.cgi");

# sends the temporary database to mascot
my $resp = $ua->request(POST $url, @request_data, Content => [file   => ["$file"], name => 'Super', set => '1'],);

It is important, that the attribute Content_Type in @request_data is "multipart/form-data". You need this to send a file. $file contains the path to the temporary database. After it is send, copyDB.cgi at first loads $file up and than saves it to /var/data/mascot/incoming/prodb-tmp_1.faa. From there the file is moved to /var/data/mascot/current where all databases from mascot are. If everything went fine, copyDB.cgi returns the path to the database, else it returns "Didn't work".

To use this function you have to be sure that no one else is using it at the moment. Otherwise the file from the first user would be overwritten

get_database

With this function you can get a database from mascot. To call this function you can use get_database_from_mascot from MSTools.pm. get_database_from_mascot expects a reference on an array. The array have to contains the name of databases as you can see them in the search form. get_database_from_mascot handles the HTTP request and returns the path to the database, normally /vol/tmp/... .

In copyDB.cgi the filenames are compared to the names from /vol/mascot/config/mascot.dat. The file mascot.dat contains the names of the databases as be displayed in the search from and the path to the database. So copyDB.cgi gets the path from it and generates a HTTP request to send the databases to the ProDB-Server to copyDBProDB.cgi. Here the file is uploaded and saved to /vol/tmp/. If everything worked correctly, the path is returned to copyDB.cgi and from there to get_database_from_mascot. Otherwise an error is returned.

Author: Nicole de la Chaux