Lab Primer Search

Preface

With the increase of the number of primers synthesized by lab members, it is inpractical to remember all the primers, or find the primer you need today by inspecting a simple table

But if you have the table of the primer sequences you have, it is quite easy to find whethere you have the appropriate primers by as sequence similarity search, such as BLAST, provided you have the sequence you want to amplify.

This document briefly describe the setup of such a primer search system.

Table of Contents

Overview of the system

The system is comprised of three parts as follows

  1. Table editing
  2. Conversion to searchable format
  3. Search interface

Table editing

Table editing may be done with any spreadsheept program such as LibreOffice Calc or Microsoft Excel.

Conversion to searchable format

As the input, the table is written to a comma separated value (CSV) format

To make it searchable with the NCBI BLAST program, the CSV file is converted to fasta format with a script csv2fasta, and further converted to a really searchable binary file with formatdb.

The formatted file is placed on an appropriate place for the search

The above process can be automatically done with a script that is kicked from the web browser

Search Interface

The search is done through the standard NCBI BLAST program

Requirements

A computer with web server
Here after the document assumes Mac OS X, but any Unix/Linux based host should work with minor modification.

Setup

Get the blast binaries (blast-2.X.Y-universal-macosx.tar.gz and wwwblast-universal-macosx.tar.gz or the ones for your system) from ftp://ftp.ncbi.nlm.nih.gov/blast/executables/release/LATEST/ or compile on your system. (I did not check the BLAST+ yet)

formatdb

Extract blast-2.X.Y-universal-macosx.tar.gz and copy formatdb to /usr/local/bin

% tar zxvf downloads/blast-2.2.25-universal-macosx.tar.gz 

If there is no /usr/local/bin make that directory first.

% sudo mkdir /usr/local 
% sudo mkdir /usr/local/bin

copy can be executed as

% sudo cp blast-2.X.Y/bin/formatdb /usr/local/bin

csv2fasta

The following awk program assumes the input file is a CSV file with line separator beeing a CR, as is in Mac systems. The file should have a unique number in the first column, some primer name in the second column, and the sequence in the third colomn. Later column are not seen from this system and thus may be used for any commental purpurses like stock concentration, date of order etc.

#!/usr/bin/awk -f
BEGIN{ RS = "\r"; ORS = "\n"; FS = ","; OFS=" "}
{
  if($3 != "" && $3 !~ /Primer/){
    seq = gsub(/I/,"n",$3);
    print ">gnl|primer|" "P"  $1, $2;
    print $3;
  }
}

This program should be saved in a location like /usr/local/bin/csv2fasta and set the executable bit on. This program assumes you are using a Mac and the CSV file is written with Mac style line separator (CR or "\r").

% ftp http://koke.asrc.kanazawa-u.ac.jp/HOWTO/primer-db/csv2fasta
% sudo install -m 755 csv2fasta /usr/local/bin

wwwblast

Extract wwwblast-2.X.Y-universal-macosx.tar.gz

Extract wwwblast-universal-macosx.tar.gz to /Library/WebServer/Documents/blast

% cd /Library/WebServer/Documents
% tar zxvf $HOME/downloads/wwwblast-2.2.25-universal-macosx.tar.gz

/Library/WebServer/Documents/blast/TmpGifs should be writable from the web server process to enabale the graphic presentation of the hits. In Mac OS X 10.6, the user is _www. To change the owner of the TmpGifs directory:

% sudo chown _www /Library/WebServer/Documents/blast/TmpGifs

Change apache configuration

Edit /private/etc/apache2/httpd.conf to make the cgi programs in the blast directory work as cgi rather than a simple text under the name of .cgi. add the four lines after the last line "</Directory>" or put the four line containing file under /private/etc/apache2/other

<Directory "/Library/WebServer/Documents/blast">
    Options ExecCGI
    AddHandler cgi-script .cgi
</Directory>

Editing is usually done with an editor like vi that works within the terminal.

On the other hand, copying with

% ftp http://koke.asrc.kanazawa-u.ac.jp/HOWTO/primer-db/blast.conf
% sudo cp blast.conf /private/etc/apache2/other

should work.

Start (or restart) the web server

Open "System Preferences"/"Sharing" and check "Web Sharing".

Try access to blast service

In your web browser try to access http://localhost/blast/blast.html and click search to test run.

It is ok if you see

Error 8 in submitting BLAST query

This is indicating that the cgi script is treated as a cgi and a program was executed rather than showing the content.

updateprimerdb

The following script will convert the csv file to fasta and further to the binary format searchable by BLAST programs.

#!/usr/bin/ruby
require 'tmpdir'
inputfilepath="/path/to/the/primer.csv"
Dir.mktmpdir do |tmpdir|
  system "/usr/local/bin/csv2fasta #{inputfilepath} > #{tmpdir}/primer.fasta"
  Dir.chdir tmpdir
  system "/usr/local/bin/formatdb -i primer.fasta -p F -o T -n primer"
  ["primer.nhr", "primer.nin", "primer.nsd", "primer.nsi", "primer.nsq"].each do |file|
    system( "/bin/mv", file , "/Library/WebServer/Documents/blast/db")
  end 
end
print "Content-Type:text/plain\n\n"
puts "please check if the new primers are sesarchable at "
puts  'http://IPorFQDN/blast/blast.html'

"/path/to/the" (third line) and "IPorFQDN" (last line) should be changed to an appropriate value for your setup.

"/path/to/the" should be changed to the path where you will put the primer.csv file.

"IPorFQDN" should be changed to the IP address or the fully qualified domain name of the computer you will use as the server. The IP address are shown when you started the web sharing service from the System Preference. If you are using just for you and not from other computer, it is ok with 127.0.0.1 or localhost.

After editing "/path/to/the" and "IPorFQDN" put the file as /Library/WebServer/CGI-Executables/updateprimerdb with the executable bit set.

Provided that you saved the file as updateprimerdb in the current directory

% sudo install -m 755 updateprimerdb /Library/WebServer/CGI-Executables/

will copy the file and set the executable bit. Note that the file should have unix style new line charactor (LF). If you have made the file with Mac style new line (CR), the new line should be changed prior to installation.

% mv updateprimerdb updateprimerdb.mac
% tr \\r \\n < updateprimerdb.mac > updateprimerdb
% sudo install -m 755 updateprimerdb /Library/WebServer/CGI-Executables/

In addition, /Library/WebServer/Documents/blast/db needs to be writable from the web server account to make the update through cgi. In Mac OS X 10.6, the user is _www. To change the owner of the db directory:

% sudo chown _www /Library/WebServer/Documents/blast/db

Blast configuration

Two files in /Library/WebServer/Documents/blast, namely, blast.html and blast.rc, should be edited to make the primers searchable.

blast.html

blast.rc

Add "primer" in blast.rc in all lines there is test_na_db