HTML Codes

March 17th, 2009

Here's a quick list with the HTML codes to safely display common characters on web pages.

More details are e.g. here.
See also the list of ASCII codes only.

HTML Code

Browser View

HTML Code

Browser View

HTML Code

Browser View

HTML Code

Browser View

HTML Code

Browser View

© © ! ! _ _   Û Û
® ® " " ` ` ž ž Ü Ü
    # # a a Ÿ Ÿ Ý Ý
" " $ $ b b     Þ Þ
& & % % c c ¡ ¡ ß ß
&lt; < &#38; & &#100; d &#162; ¢ &#224; à
&gt; > &#39; ' &#101; e &#163; £ &#225; á
&Agrave; À &#40; ( &#102; f &#164; ¤ &#226; â
&Aacute; Á &#41; ) &#103; g &#165; ¥ &#227; ã
&Acirc; Â &#42; * &#104; h &#166; ¦ &#228; ä
&Atilde; Ã &#43; + &#105; i &#167; § &#229; å
&Auml; Ä &#44; , &#106; j &#168; ¨ &#230; æ
&Aring; Å &#45; - &#107; k &#169; © &#231; ç
&AElig; Æ &#46; . &#108; l &#170; ª &#232; è
&Ccedil; Ç &#47; / &#109; m &#171; « &#233; é
&Egrave; È &#48; 0 &#110; n &#172; ¬ &#234; ê
&Eacute; É &#49; 1 &#111; o &#173; ­ &#235; ë
&Ecirc; Ê &#50; 2 &#112; p &#174; ® &#236; ì
&Euml; Ë &#51; 3 &#113; q &#175; ¯ &#237; í
&Igrave; Ì &#52; 4 &#114; r &#176; ° &#238; î
&Iacute; Í &#53; 5 &#115; s &#177; ± &#239; ï
&Icirc; Î &#54; 6 &#116; t &#178; ² &#240; ð
&Iuml; Ï &#55; 7 &#117; u &#179; ³ &#241; ñ
&ETH; Ð &#56; 8 &#118; v &#180; ´ &#242; ò
&Ntilde; Ñ &#57; 9 &#119; w &#181; µ &#243; ó
&Otilde; Õ &#58; : &#120; x &#182; &#244; ô
&Ouml; Ö &#59; ; &#121; y &#183; · &#245; õ
&Oslash; Ø &#60; < &#122; z &#184; ¸ &#246; ö
&Ugrave; Ù &#61; = &#123; { &#185; ¹ &#247; ÷
&Uacute; Ú &#62; > &#124; | &#186; º &#248; ø
&Ucirc; Û &#63; ? &#125; } &#187; » &#249; ù
&Uuml; Ü &#64; @ &#126; ~ &#188; ¼ &#250; ú
&Yacute; Ý &#65; A &#127; ? &#189; ½ &#251; û
&THORN; Þ &#66; B &#128; &#190; ¾ &#252 ü
&szlig; ß &#67; C &#129;  &#191; ¿ &#253; ý
&agrave; à &#68; D &#130; &#192; À &#254; þ
&aacute; á &#69; E &#131; ƒ &#193; Á &#255; ÿ
&aring; å &#70; F &#132; &#194; Â    
&aelig; æ &#71; G &#133; &#195; Ã    
&ccedil; ç &#72; H &#134; &#196; Ä    
&egrave; è &#73; I &#135; &#197; Å    
&eacute; é &#74; J &#136; ˆ &#198; Æ    
&ecirc; ê &#75; K &#137; &#199; Ç    
&euml; ë &#76; L &#138; Š &#200; È    
&igrave; ì &#77; M &#139; &#201; É    
&iacute; í &#78; N &#140; Œ &#202; ?    
&icirc; î &#79; O &#141;  &#203; Ë    
&iuml; ï &#80; P &#142; ž &#204; Ì    
&eth; ð &#81; Q &#143;  &#205; Í    
&ntilde; ñ &#82; R &#144;  &#206; Î    
&ograve; ò &#83; S &#145; &#207; Ï    
&oacute; ó &#84; T &#146; &#208; Ð    
&ocirc; ô &#85; U &#147; &#209; Ñ    
&otilde; õ &#86; V &#148; &#210; Ò    
&ouml; ö &#87; W &#149; &#211; Ó    
&oslash; ø &#88; X &#150; &#212; Ô    
&ugrave; ù &#89; Y &#151; &#213; Õ    
&uacute; ú &#90; Z &#152; ˜ &#214; Ö    
&ucirc; û &#91; [ &#153; &#215; ×    
&yacute; ý &#92; \ &#154; š &#216; Ø    
&thorn; þ &#93; ] &#155; &#217; Ù    
&yuml; ÿ &#94; ^ &#156; œ &#218; Ú    

mySQL Data Types

March 6th, 2009

A quick table to look up the data types used in the mySQL database management system.

Ty p e

S i z e

D e s c r i p t i o n

CHAR[Length]

Length bytes

A fixed-length field from 0 to 255 characters long.

VARCHAR(Length)

String length + 1 bytes

A fixed-length field from 0 to 255 characters long.

TINYTEXT

String length + 1 bytes

A string with a maximum length of 255 characters.

TEXT

String length + 2 bytes

A string with a maximum length of 65,535 characters.

MEDIUMTEXT

String length + 3 bytes

A string with a maximum length of 16,777,215 characters.

LONGTEXT

String length + 4 bytes

A string with a maximum length of 4,294,967,295 characters.

TINYINT[Length]

1 byte

Range of -128 to 127 or 0 to 255 unsigned.

SMALLINT[Length]

2 bytes

Range of -32,768 to 32,767 or 0 to 65535 unsigned.

MEDIUMINT[Length]

3 bytes

Range of -8,388,608 to 8,388,607 or 0 to 16,777,215

unsigned.

INT[Length]

4 bytes

Range of -2,147,483,648 to 2,147,483,647 or 0 to 4,294,967,295

unsigned.

BIGINT[Length]

8 bytes

Range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

or 0 to 18,446,744,073,709,551,615 unsigned.

FLOAT

4 bytes

A small number with a floating decimal point.

DOUBLE[Length, Decimals]

8 bytes

A large number with a floating decimal point.

DECIMAL[Length, Decimals]

Length + 1 or Length + 2 bytes

A DOUBLE stored as a string, allowing for a fixed decimal

point.

DATE

3 bytes

In the format of YYYY-MM-DD.

DATETIME

8 bytes

In the format of YYYY-MM-DD HH:MM:SS.

TIMESTAMP

4 bytes

In the format of YYYYMMDDHHMMSS; acceptable range ends

inthe year 2037.

TIME

3 bytes

In the format of HH:MM:SS

ENUM

1 or 2 bytes

Short for enumeration, which means that each column

can haveone of several possible values.

SET

1, 2, 3, 4, or 8 bytes

Like ENUM except that each column can have more than

one ofseveral possible values.

source: http://www.peachpit.com/, mySQL

SourceAdaptor for Proserver DAS sources

January 28th, 2009

The Distributed Annotation System allows to share data across servers and applications. Some other blog entries about DAS.

To use and serve the data from a specific source (your database or flat file) using the Perl Proserver you need to define a Source-Adaptor. This will translate from your specific data format to the common DAS XML format understood by all DAS servers and clients.

Here are two example SourceAdaptors for Proserver DAS sources using the 1.53e standard (and complying to GENCODE format).

Example 1: Reading data from GFF file

Code

package Bio::Das::ProServer::SourceAdaptor::example;
 
 
 
use strict;
 
#Proserver module:
 
use base qw(Bio::Das::ProServer::SourceAdaptor);
 
#for the datestamp format:
 
use Date::Format;
 
 
 
 
 
# General initialization function
 
# Set metadata such as the commands supported by this source.
 
sub init {
 
  my ($self) = @_;
 
  $self->{'capabilities'} = { 'features' => '1.0' };
 
}
 
 
 
 
 
# General function for "features" DAS command
 
# Gather the features annotated in a given segment of sequence.
 
sub build_features {
 
  my ($self, $args) = @_;
 
 
 
  my $segment = $args->{'segment'}; # The query segment ID
 
  my $start   = $args->{'start'};   # The query start position (optional)
 
  my $end     = $args->{'end'};     # The query end position (optional)
 
 
 
  my @features = ();
 
  my %group_start;
 
  my %group_end;
 
  my %group_count;
 
 
 
  #category controlled vocabulary:
 
  #id: ECO:00000067; name: inferred from electronic annotation
 
  my $typecategory = "ECO:00000067";
 
 
 
  #read data from gff file
 
  open FH, '<', '/Users/fsk/great_data/annotation.gff'
 
    or die "Unable to open data file";
 
 
 
  while (defined (my $line = <FH>)) {
 
 
 
    chomp $line;
 
    my ($f_seg, $method, $type, $f_start, $f_end, $score, $strand, $phase, $add) = split /\t/, $line;
 
 
 
    #get extra info from last column
 
    my ($f_id, $stamp) = split(";", $add);
 
 
 
    #replace unwanted characters
 
    $f_id =~ s|\"||g;
 
    $f_seg =~ s/^chr//;
 
 
 
    #create group attributes for new set of features
 
    if($type eq "mRNA"){
 
      $group_start{$f_id} = $f_start;
 
      $group_end{$f_id}   = $f_end;
 
      $group_count{$f_id};
 
      next;
 
    }
 
 
 
    #convert datestamp from machine time format into desired format (2006-04-07T15:15:58+0100)
 
    my $modstamp = time2str("%Y-%m-%dT%H:%M:%S%z", $stamp);
 
 
 
    #index for unique feature id
 
    $group_count{$f_id}++;
 
 
 
    #get the features overlapping this genomic region only
 
    if (($f_seg eq $segment) && ($f_start <= $end && $f_end >= $start) ) {
 
 
 
      #create individual feature
 
      my $feature = {
 
         #unique id
 
         'id'           => $f_id."_".$group_count{$f_id},
 
         #genomic start
 
         'start'        => $f_start,
 
         #genomic end
 
         'end'          => $f_end,
 
         #strand: +/-/0
 
         'ori'          => $strand,
 
         #name of this method/annotation
 
         'method'       => $method,
 
         #type must be exon, intron, etc.
 
         'type'         => $type,
 
         #category type: ECO id
 
         'typecategory' => $typecategory,
 
         #phase: 0/1/2/-
 
         'phase'        => '-',
 
         #score, 0 if n.a.
 
         'score'        => 0,
 
         #note for various fields, key=value pairs
 
         'note'         => [
 
               'lastmod='.$modstamp,
 
               ],
 
         #group of features
 
         'group_id'     => $f_id,
 
         'grouptype'    => $method."_prediction",
 
         'groupnote'    => 'Note='.$group_start{$f_id}."-".$group_end{$f_id},
 
        };
 
 
 
      #store in feature array
 
      push @features, $feature;
 
    }
 
 
 
  }
 
  close FH or warn "Problem closing data file";
 
 
 
  #return entire features array
 
  return @features;
 
}
 
 
 
1;

Example 2: Connecting to a database to serve transcript features

Code

package Bio::Das::ProServer::SourceAdaptor::example2;
 
 
 
use strict;
 
#Proserver module:
 
use base qw(Bio::Das::ProServer::SourceAdaptor);
 
#for accessing mysql dbs
 
#docu eg. at http://www.perl.com/pub/a/1999/10/DBI.html
 
use DBI;
 
 
 
# General initialization function
 
# Set metadata such as the commands supported by this source.
 
sub init {
 
  my ($self) = @_;
 
  $self->{'capabilities'} = { 'features' => '1.0' };
 
}
 
 
 
 
 
# General function for "features" DAS command
 
# Gather the features annotated in a given segment of sequence.
 
sub build_features {
 
  my ($self, $args) = @_;
 
 
 
  my $config = $self->config;
 
 
 
  #the region of interest
 
  my $qchrom = $args->{'segment'}; # The query segment ID
 
  my $qstart = $args->{'start'};   # The query start position (optional)
 
  my $qend   = $args->{'end'};     # The query end position (optional)
 
 
 
  my @features = ();
 
  my %group_start;
 
  my %group_end;
 
  my %group_count;
 
 
 
  #category, controlled vocabulary:
 
  #example: id: ECO:00000067; name: inferred from electronic annotation
 
  my $typecategory = "ECO:00000067";
 
 
 
  #method used to create genes/transcripts
 
  my $method = "CAPS_analysis";
 
 
 
  #read data from mysql database
 
  #connection parameters are given in the proserver config (ini) file
 
  my $dsn = "DBI:".$config->{driver}.":".$config->{dbname}.":".
 
            $config->{host}.":".$config->{port};
 
  my $db  = DBI->connect($dsn, $config->{user}, $config->{dbpass})
 
    or die "cant connect to database ".$config->{dbname}."\n";
 
 
 
  #example query to get transcripts overlapping roi
 
  my $type  = "transcript";
 
  my $query = "SELECT transcript_name, chromosome, start, end, ".
 
              "strand, phase, gene_name, lastmod ".
 
              "FROM transcripts ORDER BY chromosome, start ".
 
        "WHERE chromosome = ? AND start >= ? AND end <= ?";
 
  my $handle = $db->prepare($query);
 
  $handle->execute($qchrom, $qend, $qstart);
 
  while (my ($name, $chromosome, $start, $end, $strand,
 
             $phase, $gene_name, $lastmod) = $handle->fetchrow_array) {
 
 
 
    #create individual feature
 
    my $feature = {
 
       #unique id
 
       'id'           => $name,
 
       #genomic start
 
       'start'        => $start,
 
       #genomic end
 
       'end'          => $end,
 
       #strand: +/-/0
 
       'ori'          => $strand,
 
       #name of this method/annotation
 
       'method'       => $method,
 
       #type must be exon, intron, etc.
 
       'type'         => $type,
 
       #category type: ECO id
 
       'typecategory' => $typecategory,
 
       #phase: 0/1/2/-
 
       'phase'        => $phase,
 
       #score, - if n.a.
 
       'score'        => '-',
 
       #note for various fields, key=value pairs
 
       'note'         => [
 
              'lastmod='.$lastmod,
 
             ],
 
      };
 
 
 
    #store in feature array
 
    push @features, $feature;
 
  }
 
 
 
  $handle->finish();
 
  $db->disconnect();
 
 
 
  #return entire features array
 
  return @features;
 
}
 
 
 
1;

Ruby & MySQL

January 12th, 2009

Using MySQL from Ruby

Ruby can connect to a MySQL database using the Ruby/MySQL module. There is a complete introduction into the subject can be found here:

http://www.kitebird.com/articles/ruby-mysql.html

The core functions of the modules are explained here:

http://www.tmtm.org/en/mysql/ruby/

To establish a connection:


   require "mysql"

   begin

     # connect to the MySQL server

     dbh = Mysql.real_connect("localhost", "testuser", "testpass", "test")



     # .....



     # disconnect

     dbh.close

   end

To run a basic query you can simply do the following:


   # issue a retrieval query, perform a fetch loop, print

   # the row count, and free the result set



   res = dbh.query("SELECT name, category FROM animal")



   while row = res.fetch_row do

     printf "%s, %s\n", row[0], row[1]

   end

   puts "Number of rows returned: #{res.num_rows}"



   res.free

This can also help to try out small queries from within a Rails application, eg. like this:

     @issue_count = ActiveRecord::Base.connection.execute(

         "SELECT default_count from tmp").fetch_row[0].to_i

Rails Optimization

January 8th, 2009

Find bottlenecks with NewRelic RPM

  1. Register at https://rpm.newrelic.com for the free light version of the RPM benchmarking tool.
  2. An email will be sent with a configuration file which goes into rails-application/config/.
  3. Go into rails-application/ and run
    script/plugin install http://svn.newrelic.com/rpm/agent/newrelic_rpm
    This will automatically fetch and install the plugin.
  4. Restart the server
  5. Play around with your rails app like any user would. The benchmarking results will be available almost instantly when you go back to https://rpm.newrelic.com (requires being logged in).