Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Interface creation

by yuvraj_ghaly (Sexton)
on Aug 26, 2013 at 06:45 UTC ( #1050903=perlquestion: print w/replies, xml ) Need Help??
yuvraj_ghaly has asked for the wisdom of the Perl Monks concerning the following question:

with PerlMonks I'm successfully created program for calculation of isoelectric point, molecular weight and amino acid types.
I'm thankful for all PerlMonks who helped me.
I now Seeking a major help in creating an interface for all these program where following specifications can be done:
(1) user can either paste their sequence or upload protein sequence in fasta format to calculate protein features discussed above.
(2) this interface can be incorporated into website.

Replies are listed 'Best First'.
Re: Interface creation
by daxim (Chaplain) on Aug 26, 2013 at 06:57 UTC
    If you want to do this yourself, learn Web programming. If I'm not mistaken, Anonymous Monk will appear soon with his famous link dump to info in order to get you started.

    You have such a broad problem, I can only give you a broad hint: you need at least a form and a Web program that processes the form input and returns some result document. If you need more details, edit your question to provide more specific information about your program and how people are supposed to interact with it.

      I have a perl program for calculation of molecular weight of the protein sequences. I need to integrate into the interface in such a way that the user either upload a protein file in fasta format or paste the sequence in a space available for sequences and hit a button named calculate molecular weight. The result or output will come in pop up display webpage

        A small Plack application to get you started. I have not tested this code much.

        Learn the basics of Web programming. Add error checking. Add HTML escaping of the output. Replace this piecewise output of HTML with templating. Consider migrating this code to a micro Web framework.

        use 5.010; use strictures; use Plack::Request qw(); use HTTP::Status qw(HTTP_OK HTTP_METHOD_NOT_ALLOWED); use Local::MyFastaThing qw(process_fasta); sub html_head { return <<''; <!DOCTYPE html> <html xmlns=""> <head> <title>MyFastaThing Web front-end</title> </head> <body> } sub form { my ($where_am_i) = @_; return <<""; <form action="$where_am_i" method="POST"> <label for="sequence">paste sequence</label> <textarea id="sequence" name="sequence"></textarea> <label for="fasta">upload fasta</label> <input id="fasta" name="fasta" type="file" /> <input type="submit" /> </form> } sub html_tail { return <<''; </body> </html> } my $app = sub { my ($env) = @_; my $req = Plack::Request->new($env); if ('GET' eq $req->method) { return [HTTP_OK, ['Content-Type' => 'application/xhtml+xml'], +[html_head, form($req->uri), html_tail]]; } elsif ('POST' eq $req->method) { return [HTTP_OK, ['Content-Type' => 'application/xhtml+xml'], +[html_head, '<p>', process_fasta($req->upload('fasta') // $req->body_paramete +rs->{sequence}), '</p>', html_tail]]; } else { return [HTTP_METHOD_NOT_ALLOWED, [],[]]; } };

        Your requirements are simply enough to use just a plain old CGI script, i.e. one Perl script either renders the page with the input/upload fields or, if input has been made, use your calculator to process the input and render the results page.
        This is not the most modern way of web programming but it's still good enough for a one-page-process-one-thing site like yours and it's also a good way of getting into web programming without having to learn an entire framework.

        Get started here. There is a section describing how to handle file uploads but to get started I would leave that and get it to work with a simple text field for pasting the protein sequence. Once you have cracked that it will be easy enough to add on handling of an uploaded file.

        In the end a CGI script is nothing magical, except that your web server must be configured to use it. It's just another Perl script that is run by your web server if someone visits your web site. All it does is to print text (the html of the web page) that is sent to the browser of the site visitor. So you need to write a script that checks if there is user input and then either prints the html for the page with the input forms or it prints the results page (or adds a results section to the page with the input forms. The perldoc explains all about getting user input but it's worth learning a little bit about how browsers and servers communicate with each other and what GET and POST requests are.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1050903]
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-05-24 08:40 GMT
Find Nodes?
    Voting Booth?