“Find those numbers whose first digit is the total of zeros, the second digit the total ones … and so.”
Example: 21200
Solution from one Perl script:
Solution 1: 21200 Solution 2: 3211000 Solution 3: 42101000
“Find those numbers whose first digit is the total of zeros, the second digit the total ones … and so.”
Example: 21200
Solution from one Perl script:
Solution 1: 21200 Solution 2: 3211000 Solution 3: 42101000
There’s a Wiki-based website for SNPs, called www.snpedia.com. A sample entry, accessible using dbSNP accession number is http://www.snpedia.com/index.php/Rs1815739.
The http://snp-nexus.org/ seem interesting too.
SFF files are the binary output given by the Roche 454 sequencers. They holds both the flowgrams, and thus the sequences, and a manifest of the run itself. To see it you can use the following command:
sffinfo -m file.sff > manifest.xml
A Perl hash containing the genetic code in terms of CODON -> AMINO ACID. It can be used for RNA translation, or for DNA remembering to substitute Ts with Us. Continue reading “Genetic code perl hash”
Perl & MySQL summary
A simple snippet of a JavaScript function to toggle visibility of an element called by ID.
<script type="text/javascript"> <!--
function toggle_visibility(id) { var e = document.getElementById(id); if(e.style.display == 'block') e.style.display = 'none'; else e.style.display = 'block';
}//--> </script>
Sometimes you want to incorporate a dynamically generated image into a web page, like this:
<img src="scripts/counter.pl?title=MySite" />
The barebone of this program looks like:
#!/usr/bin/perl use GD; use CGI qw/:standard/; print header(-type=>'image/png'); # Allocate the image and the colors we need my $im = new GD::Image($imagew, $imageh); my $grey = $im->colorAllocate(230,230,230); my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate( 0, 0, 0); # Draw the picture... $im->line(2, $topy, $rightx, $topy, $black); $im->line(2, $boty, $rightx, $boty, $black); $im->line($leftx, 2, $leftx, $boty, $black); $im->line($rightx, 2, $rightx, $boty, $black); #Print image print $im->png;
This simple template shows how to create a Perl script to print output to a web browser, and how to get parameters. It’s important to make the script executable before invoking it. The “param” function works both with parameters passed via POST and via GET.
Tested with DreamHost (no particular directory to store script, like old ‘cgi-bin’).
#!/usr/bin/perl use CGI qw(:standard); $name = param('username') || 'anonymous'; $code = param('usercode') || '0000'; print "Content-type: text/html\n\n"; # elaborate data... # print output (in HTML)
Here is the script.
#!/usr/local/bin/perl # Program to do the common "Hello World" print 'Hello world.'; # This line prints a message
What’s in this?
Every perl program starts off with this as its very first line:
#!/usr/bin/perl
although this may vary from system to system. This line tells the machine what to do with the file when it is executed (ie it tells it to run the file through Perl). This is not a Perl instruction, but is for (Linux) shell. Write #! followed by the path of the perl program. If you are unsure, write the command whereis perl at the shell prompt, then copy and paste the path.
Comments can be inserted into a program with the # symbol, and anything from the # to the end of the line is ignored (with the exception of the first line). The only way to stretch comments over several lines is to use a # on each line. Everything else is a Perl statement which must end with a semicolon, like the last line above.
The print function outputs some information. In the above case it prints out the the literal string Hello world. and of course the statement ends with a semicolon. You may find the above program produces an slightly unexpected result. So the next thing to do is to run it!
Save it as hello.pl (that is the commonly used extension for Perl scripts). Then you can run it like this:$ perl hello.plIn this case the first line is not required, as you invoke perl by yourself. But you can also make it executable and then launch it calling only its file name. In this case the first line is required. So let’s try:
$ chmod 755 hello.pl
$ ./hello.pl