From: martinahansen Date: Thu, 17 Nov 2011 09:34:12 +0000 (+0000) Subject: added requirement of RubyInline X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=db8e4454c9c278ac274b9a997d95324218045d8d;p=biopieces.git added requirement of RubyInline git-svn-id: http://biopieces.googlecode.com/svn/trunk@1656 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/uclust_seq b/bp_bin/uclust_seq index bd63df8..b20a29c 100755 --- a/bp_bin/uclust_seq +++ b/bp_bin/uclust_seq @@ -58,6 +58,13 @@ class Uclust File.rename "#{@infile}.sort", @infile end + # Method to execute clustering de novo. + def cluster + @command << "usearch --cluster #{@infile} --uc #{@outfile} --id #{@options[:identity]}" + + execute + end + # Method to execute database search. def usearch # usearch --query query.fasta --db db.fasta --uc results.uc --id 0.90 [--evalue E] @@ -67,13 +74,6 @@ class Uclust execute end - # Method to execute clustering de novo. - def cluster - @command << "usearch --cluster #{@infile} --uc #{@outfile} --id #{@options[:identity]}" - - execute - end - # Method to execute clustering to database plus de novo if not matched. def usearch_uclust # usearch --cluster seqs_sorted.fasta --db db.fasta --uc results.uc --id 0.90 @@ -129,7 +129,7 @@ class Uclust end end -ok_methods = "usearch,uclust,usearch_uclust" +ok_methods = "uclust,usearch,usearch_uclust" casts = [] casts << {:long=>'no_sort', :short=>'n', :type=>'flag', :mandatory=>false, :default=>nil, :allowed=>nil, :disallowed=>nil} @@ -141,6 +141,10 @@ casts << {:long=>'e_val', :short=>'e', :type=>'float', :mandatory=>false, :d options = Biopieces.options_parse(ARGV, casts) +# At high identities, around 96% and above, compressed indexes are often more sensitive, faster +# and use less RAM. Compressed indexes are disabled by default, so I generally recommend that +# you specify the --slots and --w options when clustering at high identities. + tmpdir = Biopieces.mktmpdir infile = File.join(tmpdir, "in.fna") outfile = File.join(tmpdir, "out.uc") @@ -157,13 +161,12 @@ Biopieces.open(options[:stream_in], options[:stream_out]) do |input, output| end uclust = Uclust.new(infile, outfile, options) - uclust.sort unless options[:no_sort] + uclust.sort unless options[:no_sort] or options[:method] == "usearch" case options[:method].to_s - when "usearch" then uclust.usearch when "uclust" then uclust.cluster + when "usearch" then uclust.usearch when "usearch_uclust" then uclust.usearch_uclust - else raise "Unknown method: #{options[:method]}" end uclust.each do |record| diff --git a/bp_scripts/biopieces_installer-0.42.sh b/bp_scripts/biopieces_installer-0.42.sh deleted file mode 100755 index 50c5f94..0000000 --- a/bp_scripts/biopieces_installer-0.42.sh +++ /dev/null @@ -1,567 +0,0 @@ -#!/bin/bash - -# Install script for Biopieces. -# October 2011, Martin A. Hansen - -bp_code="$HOME/biopieces" -bp_data="$HOME/BP_DATA" - bp_log="/var/log" - bp_tmp="/tmp" - -# Function that renders a given message in ASCII green. -function echo_green -{ - local msg=$1 - - echo -e "\033[32;38m$msg\033[0m" -} - -# Function that renders a given message in ASCII yellow. -function echo_yellow -{ - local msg=$1 - - echo -e "\033[33;38m$msg\033[0m" -} - -# Function that renders a given message in ASCII red. -function echo_red -{ - local msg=$1 - - echo -e "\033[31;38m$msg\033[0m" -} - -# Function to output an abort message and exit -function exit_abort -{ - echo_red "abort" - - exit -} - -# Function to output an success message and exit -function exit_success -{ - echo "" - echo_green "Congratulations - you have now installed Biopieces." - echo "" - echo " To list all available Biopieces try 'list_biopieces'" - echo "" - echo " To see the synopsis of a Biopiece try 'read_fastq'" - echo "" - echo " To see the full description and exampels try 'read_fastq -?'" - echo "" - echo " Don't forget to join the Biopieces Google Group for important" - echo " messages, questions, discussion, and suggestions:" - echo "" - echo " http://groups.google.com/group/biopieces" - echo "" - echo " And of cause there is the introduction:" - echo "" - echo " http://code.google.com/p/biopieces/wiki/Introduction" - echo "" - echo " Happy hacking!" - echo "" - - exit -} - -# Function to create a directory if it doesn't exist. -function dir_create -{ - local dir=$1 - - echo -n "Creating $dir: " - - if error=$( mkdir $dir 2>&1 ); then - echo_green "OK" - else - echo_red "FAIL" - echo " $error" - exit_abort - fi -} - -# Function check if a directory is writable. -function dir_writable -{ - local dir=$1 - local file="$dir/bp_writable" - - echo -n "Writable? $dir: " - - if error=$( touch $file 2>&1 ); then - echo_green "OK" - rm $file - else - echo_red "FAIL" - echo " $error" - exit_abort - fi -} - -# Function to prompt for continuation of installation. -function prompt_install -{ - echo "" - echo "Welcome to the Biopieces installer." - echo "" - echo " This installer is experimental, and is being evaluated to replace" - echo " the previous, tedious way:" - echo "" - echo " http://code.google.com/p/biopieces/wiki/Installation" - echo "" - echo " The installer will now do the following:" - echo "" - echo " * Check for existing Biopieces installation." - echo " * Check prerequisites:" - echo " - Subversion client" - echo " - Perl" - echo " - Perl modules" - echo " - Ruby" - echo " - Ruby gems" - echo " - Auxillary programs" - echo "" - echo " * Create installation directories." - echo " * Download code from repository." - echo " * Set environment in .bashrc." - echo " * Run tests" - echo "" - echo " Problems? Check out the FAQ:" - echo "" - echo " http://code.google.com/p/biopieces/wiki/FAQ" - echo "" - echo " Help is available at the Biopieces Google Group:" - echo "" - echo " http://groups.google.com/group/biopieces" - echo "" - echo " Bugs & issues:" - echo "" - echo " http://code.google.com/p/biopieces/issues/list" - echo "" - - while true; do - read -p "Continue (yes/no)? " answer - case $answer in - [Yy]* ) break;; - [Nn]* ) exit_abort;; - esac - done -} - -# Function to prompt the checking of any existing Biopieces installation. -function prompt_install_existing -{ - echo "Checking for existing Biopieces installation:" - - if [ $BP_DIR ]; then - echo_yellow " WARNING: \$BP_DIR is already set to: $BP_DIR" - found=1 - fi - - if [ $BP_DATA ]; then - echo_yellow " WARNING: \$BP_DATA is already set to: $BP_DATA" - found=1 - fi - - if [ $BP_TMP ]; then - echo_yellow " WARNING: \$BP_TMP is already set to: $BP_TMP" - found=1 - fi - - if [ $BP_LOG ]; then - echo_yellow " WARNING: \$BP_LOG is already set to: $BP_LOG" - found=1 - fi - - if [ $found ]; then - echo "" - echo " An old installation of Biopeices appears to exists." - else - echo "" - echo " No installation of Biopeices found." - fi - - while true; do - read -p "Continue (yes/no)? " answer - case $answer in - [Yy]* ) break;; - [Nn]* ) exit_abort;; - esac - done -} - -# Function to prompt the testing of prerequisites. -function prompt_test_prerequisites -{ - echo "Testing prerequisites:" - - test_bash - test_svn - test_perl - test_perl_module "Inline" - test_perl_module "JSON::XS" - test_perl_module "SVG" - test_perl_module "Bit::Vector" - test_perl_module "Time::HiRes" - test_ruby - test_ruby_gem "gnuplot" - test_ruby_gem "narray" - test_aux_program "blastall" - test_aux_program "blat" - test_aux_program "bwa" - test_aux_program "bowtie" - test_aux_program "formatdb" - test_aux_program "gnuplot" - test_aux_program "idba" - test_aux_program "muscle" - test_aux_program "mummer" - test_aux_program "mysql" - test_aux_program "prodigal" - test_aux_program "Ray" - test_aux_program "scan_for_matches" - test_aux_program "uclust" - test_aux_program "velveth" - test_aux_program "velvetg" - test_aux_program "vmatch" - - echo "" - echo " Any WARNINGs indicate that the executable for that auxillary" - echo " program could not be found. While not critical, this will" - echo " cause some Biopieces to FAIL." - - while true; do - read -p "Continue (yes/no)? " answer - case $answer in - [Yy]* ) break;; - [Nn]* ) exit_abort;; - esac - done -} - -# Function to prompt the selection of the code directory. -function prompt_install_dir_code -{ - read -p "Enter directory for the Biopieces code (default: $bp_code): " answer; - - bp_code=${answer:-"$bp_code"} - - if [ ! -d "$bp_code" ]; then - while true; do - read -p "Create directory: $bp_code (yes/no)? " answer - case $answer in - [Yy]* ) dir_create $bp_code && break;; - [Nn]* ) exit_abort;; - esac - done - fi - - dir_writable $bp_code -} - -# Function to prompt the selection of the data directory. -function prompt_install_dir_data -{ - read -p "Enter directory for the Biopieces data (default: $bp_data): " answer; - - bp_data=${answer:-"$bp_data"} - - if [ ! -d "$bp_data" ]; then - while true; do - read -p "Create directory: $bp_data (yes/no)? " answer - case $answer in - [Yy]* ) dir_create $bp_data && break;; - [Nn]* ) exit_abort;; - esac - done - fi - - dir_writable $bp_data -} - -# Function to prompt the selection of the log directory. -function prompt_install_dir_log -{ - read -p "Enter directory for the Biopieces log file (default: $bp_log): " answer; - - bp_log=${answer:-"$bp_log"} - - if [ ! -d "$bp_log" ]; then - while true; do - read -p "Create directory: $bp_log (yes/no)? " answer - case $answer in - [Yy]* ) dir_create $bp_log && break;; - [Nn]* ) exit_abort;; - esac - done - fi - - dir_writable $bp_log -} - -# Function to prompt the selection of the tmp directory. -function prompt_install_dir_tmp -{ - read -p "Enter directory for the Biopieces temporary files (default: $bp_tmp): " answer; - - bp_tmp=${answer:-"$bp_tmp"} - - if [ ! -d "$bp_tmp" ]; then - while true; do - read -p "Create directory: $bp_tmp (yes/no)? " answer - case $answer in - [Yy]* ) dir_create $bp_tmp && break;; - [Nn]* ) exit_abort;; - esac - done - fi - - dir_writable $bp_tmp -} - -# Function to prompt the appending of a section to bashrc. -function prompt_append_bashrc -{ - local skip=0 - local section=" - -# >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<< - -export BP_DIR=\"$bp_code\" -export BP_DATA=\"$bp_data\" -export BP_TMP=\"$bp_tmp\" -export BP_LOG=\"$bp_log\" - -source \"\$BP_DIR/bp_conf/bashrc\" - -# >>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<< - -" - - echo "" - echo "We need to append the below section to your .bashrc file." - - echo_yellow "$section" - - while true; do - read -p "Append (yes/no/abort)? " answer - case $answer in - [Yy]* ) skip=0 && break;; - [Nn]* ) skip=1 && break;; - [Aa]* ) exit_abort;; - esac - done - - if [ $skip == 1 ]; then - echo "Skipping" - else - if [ -f "$HOME/.bashrc" ]; then - echo "Existing .bashrc file located: $HOME/.bashrc" - echo -n "Creating backup: " - - if ! cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"; then - echo_red "FAIL" - abort - else - echo_green "OK" - echo " Backup is $HOME/.bashrc_biopieces" - fi - fi - - echo -n "Appending $HOME/.bashrc: " - - if ! echo "$section" >> "$HOME/.bashrc"; then - echo_red "FAIL" - abort - else - echo_green "OK" - fi - - echo -n "Sourcing $HOME/.bashrc: " - - if ! source "$HOME/.bashrc"; then - echo_red "FAIL" - abort - else - echo_green "OK" - fi - - echo "" - echo " \$BP_DIR is now set to: $BP_DIR" - echo " \$BP_DATA is now set to: $BP_DATA" - echo " \$BP_TMP is now set to: $BP_TMP" - echo " \$BP_LOG is now set to: $BP_LOG" - echo "" - fi -} - -# Function to test if we are running bash. -function test_bash -{ - echo -n " Testing if the running shell is bash: " - - if [ `echo $SHELL | grep "bash"` ]; then - echo_green "OK" - else - echo_red "FAIL" - echo " Biopieces requires bash shell not - $SHELL." - exit_abort - fi -} - -# Function to test if subversion client is in $PATH. -function test_svn -{ - local program="svn" - - echo -n " Testing subversion client - \"$program\": " - - if command -v $program >/dev/null; then - echo_green "OK" - else - echo_red "FAIL" - echo " Subversion client $program was not found." - exit_abort - fi -} - -# Function to test if the required version of Perl is installed. -function test_perl -{ - echo -n " Testing Perl version: " - - if error=$( perl -e 'use 5.8.0;' 2>&1 ); then - echo_green "OK" - else - echo_red "FAIL" - echo " $error" | sed "s/, stopped.*//" - exit_abort - fi -} - -# Function to test if a given Perl module is installed. -function test_perl_module -{ - local module=$1 - - echo -n " Testing required Perl module - \"$module\": " - - if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then - echo_red "FAIL" - echo " Try: perl -MCPAN -e 'install $module'" - exit_abort - else - echo_green "OK" - fi -} - -# Function to test if the required version of Ruby is installed. -function test_ruby -{ - echo -n " Testing Ruby version: " - - if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then - echo_green "OK" - else - echo_red "FAIL" - exit_abort - fi -} - -# Function to test if a given Ruby gem is installed. -function test_ruby_gem -{ - local gem=$1 - - echo -n " Testing required Ruby gem - \"$gem\": " - - if error=$( gem list --local | grep $gem ); then - echo_green "OK" - else - echo_red "FAIL" - echo " Try: gem install $gem" - exit_abort - fi -} - -# Function to test is a given auxillary program is in $PATH. -function test_aux_program -{ - local program=$1 - - echo -n " Testing auxiliary program - \"$program\": " - - if command -v $program >/dev/null; then - echo_green "OK" - else - echo_yellow "WARNING" - fi -} - -# Function to checkout the Biopieces code from subversion. -function checkout_code -{ - echo -n "Downloading Biopieces code from repository (please wait): " - - if error=$( svn checkout http://biopieces.googlecode.com/svn/trunk/ $bp_code ); then - echo_green "OK" - else - echo_red "FAIL" - echo " $error" - exit_abort - fi -} - -# Function to checkout the Biopieces wiki from subversion. -function checkout_wiki -{ - echo -n "Downloading Biopieces wiki from repository (please wait): " - - if error=$( svn checkout http://biopieces.googlecode.com/svn/wiki/ "$bp_code/bp_usage" ); then - echo_green "OK" - else - echo_red "FAIL" - echo " $error" - exit_abort - fi -} - -# Function to run the Biopieces tests. -function prompt_test_biopieces -{ - echo "Running the Biopieces test suite:" - echo "" - - "$BP_DIR/bp_test/test_all" - - echo "" - echo " Any FAIL indicates broken Biopieces. This is probably because of" - echo " missing prerequisites (see WARNINGs). You can verify this later by" - echo " inspecting the documentation for those Biopieces. Otherwise - seek help!" - - while true; do - read -p "Continue (yes/no)? " answer - case $answer in - [Yy]* ) break;; - [Nn]* ) exit_abort;; - esac - done -} - -prompt_install -prompt_install_existing -prompt_test_prerequisites -prompt_install_dir_code -prompt_install_dir_data -prompt_install_dir_log -prompt_install_dir_tmp - -checkout_code -checkout_wiki - -prompt_append_bashrc -prompt_test_biopieces - -exit_success - diff --git a/bp_scripts/biopieces_installer-0.43.sh b/bp_scripts/biopieces_installer-0.43.sh new file mode 100755 index 0000000..b4599b8 --- /dev/null +++ b/bp_scripts/biopieces_installer-0.43.sh @@ -0,0 +1,568 @@ +#!/bin/bash + +# Install script for Biopieces. +# October 2011, Martin A. Hansen + +bp_code="$HOME/biopieces" +bp_data="$HOME/BP_DATA" + bp_log="/var/log" + bp_tmp="/tmp" + +# Function that renders a given message in ASCII green. +function echo_green +{ + local msg=$1 + + echo -e "\033[32;38m$msg\033[0m" +} + +# Function that renders a given message in ASCII yellow. +function echo_yellow +{ + local msg=$1 + + echo -e "\033[33;38m$msg\033[0m" +} + +# Function that renders a given message in ASCII red. +function echo_red +{ + local msg=$1 + + echo -e "\033[31;38m$msg\033[0m" +} + +# Function to output an abort message and exit +function exit_abort +{ + echo_red "abort" + + exit +} + +# Function to output an success message and exit +function exit_success +{ + echo "" + echo_green "Congratulations - you have now installed Biopieces." + echo "" + echo " To list all available Biopieces try 'list_biopieces'" + echo "" + echo " To see the synopsis of a Biopiece try 'read_fastq'" + echo "" + echo " To see the full description and exampels try 'read_fastq -?'" + echo "" + echo " Don't forget to join the Biopieces Google Group for important" + echo " messages, questions, discussion, and suggestions:" + echo "" + echo " http://groups.google.com/group/biopieces" + echo "" + echo " And of cause there is the introduction:" + echo "" + echo " http://code.google.com/p/biopieces/wiki/Introduction" + echo "" + echo " Happy hacking!" + echo "" + + exit +} + +# Function to create a directory if it doesn't exist. +function dir_create +{ + local dir=$1 + + echo -n "Creating $dir: " + + if error=$( mkdir $dir 2>&1 ); then + echo_green "OK" + else + echo_red "FAIL" + echo " $error" + exit_abort + fi +} + +# Function check if a directory is writable. +function dir_writable +{ + local dir=$1 + local file="$dir/bp_writable" + + echo -n "Writable? $dir: " + + if error=$( touch $file 2>&1 ); then + echo_green "OK" + rm $file + else + echo_red "FAIL" + echo " $error" + exit_abort + fi +} + +# Function to prompt for continuation of installation. +function prompt_install +{ + echo "" + echo "Welcome to the Biopieces installer." + echo "" + echo " This installer is experimental, and is being evaluated to replace" + echo " the previous, tedious way:" + echo "" + echo " http://code.google.com/p/biopieces/wiki/Installation" + echo "" + echo " The installer will now do the following:" + echo "" + echo " * Check for existing Biopieces installation." + echo " * Check prerequisites:" + echo " - Subversion client" + echo " - Perl" + echo " - Perl modules" + echo " - Ruby" + echo " - Ruby gems" + echo " - Auxillary programs" + echo "" + echo " * Create installation directories." + echo " * Download code from repository." + echo " * Set environment in .bashrc." + echo " * Run tests" + echo "" + echo " Problems? Check out the FAQ:" + echo "" + echo " http://code.google.com/p/biopieces/wiki/FAQ" + echo "" + echo " Help is available at the Biopieces Google Group:" + echo "" + echo " http://groups.google.com/group/biopieces" + echo "" + echo " Bugs & issues:" + echo "" + echo " http://code.google.com/p/biopieces/issues/list" + echo "" + + while true; do + read -p "Continue (yes/no)? " answer + case $answer in + [Yy]* ) break;; + [Nn]* ) exit_abort;; + esac + done +} + +# Function to prompt the checking of any existing Biopieces installation. +function prompt_install_existing +{ + echo "Checking for existing Biopieces installation:" + + if [ $BP_DIR ]; then + echo_yellow " WARNING: \$BP_DIR is already set to: $BP_DIR" + found=1 + fi + + if [ $BP_DATA ]; then + echo_yellow " WARNING: \$BP_DATA is already set to: $BP_DATA" + found=1 + fi + + if [ $BP_TMP ]; then + echo_yellow " WARNING: \$BP_TMP is already set to: $BP_TMP" + found=1 + fi + + if [ $BP_LOG ]; then + echo_yellow " WARNING: \$BP_LOG is already set to: $BP_LOG" + found=1 + fi + + if [ $found ]; then + echo "" + echo " An old installation of Biopeices appears to exists." + else + echo "" + echo " No installation of Biopeices found." + fi + + while true; do + read -p "Continue (yes/no)? " answer + case $answer in + [Yy]* ) break;; + [Nn]* ) exit_abort;; + esac + done +} + +# Function to prompt the testing of prerequisites. +function prompt_test_prerequisites +{ + echo "Testing prerequisites:" + + test_bash + test_svn + test_perl + test_perl_module "Inline" + test_perl_module "JSON::XS" + test_perl_module "SVG" + test_perl_module "Bit::Vector" + test_perl_module "Time::HiRes" + test_ruby + test_ruby_gem "gnuplot" + test_ruby_gem "narray" + test_ruby_gem "RubyInline" + test_aux_program "blastall" + test_aux_program "blat" + test_aux_program "bwa" + test_aux_program "bowtie" + test_aux_program "formatdb" + test_aux_program "gnuplot" + test_aux_program "idba" + test_aux_program "muscle" + test_aux_program "mummer" + test_aux_program "mysql" + test_aux_program "prodigal" + test_aux_program "Ray" + test_aux_program "scan_for_matches" + test_aux_program "usearch" + test_aux_program "velveth" + test_aux_program "velvetg" + test_aux_program "vmatch" + + echo "" + echo " Any WARNINGs indicate that the executable for that auxillary" + echo " program could not be found. While not critical, this will" + echo " cause some Biopieces to FAIL." + + while true; do + read -p "Continue (yes/no)? " answer + case $answer in + [Yy]* ) break;; + [Nn]* ) exit_abort;; + esac + done +} + +# Function to prompt the selection of the code directory. +function prompt_install_dir_code +{ + read -p "Enter directory for the Biopieces code (default: $bp_code): " answer; + + bp_code=${answer:-"$bp_code"} + + if [ ! -d "$bp_code" ]; then + while true; do + read -p "Create directory: $bp_code (yes/no)? " answer + case $answer in + [Yy]* ) dir_create $bp_code && break;; + [Nn]* ) exit_abort;; + esac + done + fi + + dir_writable $bp_code +} + +# Function to prompt the selection of the data directory. +function prompt_install_dir_data +{ + read -p "Enter directory for the Biopieces data (default: $bp_data): " answer; + + bp_data=${answer:-"$bp_data"} + + if [ ! -d "$bp_data" ]; then + while true; do + read -p "Create directory: $bp_data (yes/no)? " answer + case $answer in + [Yy]* ) dir_create $bp_data && break;; + [Nn]* ) exit_abort;; + esac + done + fi + + dir_writable $bp_data +} + +# Function to prompt the selection of the log directory. +function prompt_install_dir_log +{ + read -p "Enter directory for the Biopieces log file (default: $bp_log): " answer; + + bp_log=${answer:-"$bp_log"} + + if [ ! -d "$bp_log" ]; then + while true; do + read -p "Create directory: $bp_log (yes/no)? " answer + case $answer in + [Yy]* ) dir_create $bp_log && break;; + [Nn]* ) exit_abort;; + esac + done + fi + + dir_writable $bp_log +} + +# Function to prompt the selection of the tmp directory. +function prompt_install_dir_tmp +{ + read -p "Enter directory for the Biopieces temporary files (default: $bp_tmp): " answer; + + bp_tmp=${answer:-"$bp_tmp"} + + if [ ! -d "$bp_tmp" ]; then + while true; do + read -p "Create directory: $bp_tmp (yes/no)? " answer + case $answer in + [Yy]* ) dir_create $bp_tmp && break;; + [Nn]* ) exit_abort;; + esac + done + fi + + dir_writable $bp_tmp +} + +# Function to prompt the appending of a section to bashrc. +function prompt_append_bashrc +{ + local skip=0 + local section=" + +# >>>>>>>>>>>>>>>>>>>>>>> Enabling Biopieces <<<<<<<<<<<<<<<<<<<<<<< + +export BP_DIR=\"$bp_code\" +export BP_DATA=\"$bp_data\" +export BP_TMP=\"$bp_tmp\" +export BP_LOG=\"$bp_log\" + +source \"\$BP_DIR/bp_conf/bashrc\" + +# >>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<< + +" + + echo "" + echo "We need to append the below section to your .bashrc file." + + echo_yellow "$section" + + while true; do + read -p "Append (yes/no/abort)? " answer + case $answer in + [Yy]* ) skip=0 && break;; + [Nn]* ) skip=1 && break;; + [Aa]* ) exit_abort;; + esac + done + + if [ $skip == 1 ]; then + echo "Skipping" + else + if [ -f "$HOME/.bashrc" ]; then + echo "Existing .bashrc file located: $HOME/.bashrc" + echo -n "Creating backup: " + + if ! cp "$HOME/.bashrc" "$HOME/.bashrc_biopieces"; then + echo_red "FAIL" + abort + else + echo_green "OK" + echo " Backup is $HOME/.bashrc_biopieces" + fi + fi + + echo -n "Appending $HOME/.bashrc: " + + if ! echo "$section" >> "$HOME/.bashrc"; then + echo_red "FAIL" + abort + else + echo_green "OK" + fi + + echo -n "Sourcing $HOME/.bashrc: " + + if ! source "$HOME/.bashrc"; then + echo_red "FAIL" + abort + else + echo_green "OK" + fi + + echo "" + echo " \$BP_DIR is now set to: $BP_DIR" + echo " \$BP_DATA is now set to: $BP_DATA" + echo " \$BP_TMP is now set to: $BP_TMP" + echo " \$BP_LOG is now set to: $BP_LOG" + echo "" + fi +} + +# Function to test if we are running bash. +function test_bash +{ + echo -n " Testing if the running shell is bash: " + + if [ `echo $SHELL | grep "bash"` ]; then + echo_green "OK" + else + echo_red "FAIL" + echo " Biopieces requires bash shell not - $SHELL." + exit_abort + fi +} + +# Function to test if subversion client is in $PATH. +function test_svn +{ + local program="svn" + + echo -n " Testing subversion client - \"$program\": " + + if command -v $program >/dev/null; then + echo_green "OK" + else + echo_red "FAIL" + echo " Subversion client $program was not found." + exit_abort + fi +} + +# Function to test if the required version of Perl is installed. +function test_perl +{ + echo -n " Testing Perl version: " + + if error=$( perl -e 'use 5.8.0;' 2>&1 ); then + echo_green "OK" + else + echo_red "FAIL" + echo " $error" | sed "s/, stopped.*//" + exit_abort + fi +} + +# Function to test if a given Perl module is installed. +function test_perl_module +{ + local module=$1 + + echo -n " Testing required Perl module - \"$module\": " + + if ! error=$( perl -M$module -e '' 2>&1 > /dev/null ); then + echo_red "FAIL" + echo " Try: perl -MCPAN -e 'install $module'" + exit_abort + else + echo_green "OK" + fi +} + +# Function to test if the required version of Ruby is installed. +function test_ruby +{ + echo -n " Testing Ruby version: " + + if error=$( ruby -e 'raise "Ruby version 1.9 required--this is only #{RUBY_VERSION}" if RUBY_VERSION < "1.9"' 2>&1 ); then + echo_green "OK" + else + echo_red "FAIL" + exit_abort + fi +} + +# Function to test if a given Ruby gem is installed. +function test_ruby_gem +{ + local gem=$1 + + echo -n " Testing required Ruby gem - \"$gem\": " + + if error=$( gem list --local | grep $gem ); then + echo_green "OK" + else + echo_red "FAIL" + echo " Try: gem install $gem" + exit_abort + fi +} + +# Function to test is a given auxillary program is in $PATH. +function test_aux_program +{ + local program=$1 + + echo -n " Testing auxiliary program - \"$program\": " + + if command -v $program >/dev/null; then + echo_green "OK" + else + echo_yellow "WARNING" + fi +} + +# Function to checkout the Biopieces code from subversion. +function checkout_code +{ + echo -n "Downloading Biopieces code from repository (please wait): " + + if error=$( svn checkout http://biopieces.googlecode.com/svn/trunk/ $bp_code ); then + echo_green "OK" + else + echo_red "FAIL" + echo " $error" + exit_abort + fi +} + +# Function to checkout the Biopieces wiki from subversion. +function checkout_wiki +{ + echo -n "Downloading Biopieces wiki from repository (please wait): " + + if error=$( svn checkout http://biopieces.googlecode.com/svn/wiki/ "$bp_code/bp_usage" ); then + echo_green "OK" + else + echo_red "FAIL" + echo " $error" + exit_abort + fi +} + +# Function to run the Biopieces tests. +function prompt_test_biopieces +{ + echo "Running the Biopieces test suite:" + echo "" + + "$BP_DIR/bp_test/test_all" + + echo "" + echo " Any FAIL indicates broken Biopieces. This is probably because of" + echo " missing prerequisites (see WARNINGs). You can verify this later by" + echo " inspecting the documentation for those Biopieces. Otherwise - seek help!" + + while true; do + read -p "Continue (yes/no)? " answer + case $answer in + [Yy]* ) break;; + [Nn]* ) exit_abort;; + esac + done +} + +prompt_install +prompt_install_existing +prompt_test_prerequisites +prompt_install_dir_code +prompt_install_dir_data +prompt_install_dir_log +prompt_install_dir_tmp + +checkout_code +checkout_wiki + +prompt_append_bashrc +prompt_test_biopieces + +exit_success + diff --git a/bp_test/test_all b/bp_test/test_all index afed9f1..4a1aa13 100755 --- a/bp_test/test_all +++ b/bp_test/test_all @@ -15,6 +15,7 @@ test_perl_module "Time::HiRes" test_ruby test_ruby_gem "gnuplot" test_ruby_gem "narray" +test_ruby_gem "RubyInline" test_aux_program "blastall" test_aux_program "blat" test_aux_program "bwa" @@ -28,7 +29,7 @@ test_aux_program "mysql" test_aux_program "prodigal" test_aux_program "Ray" test_aux_program "scan_for_matches" -test_aux_program "uclust" +test_aux_program "usearch" test_aux_program "velveth" test_aux_program "velvetg" test_aux_program "vmatch" diff --git a/code_ruby/lib/maasha/backtrack.rb b/code_ruby/lib/maasha/backtrack.rb index 02eb047..f5e581b 100644 --- a/code_ruby/lib/maasha/backtrack.rb +++ b/code_ruby/lib/maasha/backtrack.rb @@ -56,7 +56,7 @@ module BackTrack # matches are returned in an Array of Match objects. def patscan(pattern, offset = 0, max_mismatches = 0, max_insertions = 0, max_deletions = 0) raise BackTrackError, "Bad pattern: #{pattern}" unless pattern.downcase =~ OK_PATTERN - raise BackTrackError, "offset: #{offset} out of range (0 ... #{self.length - 1})" unless (0 ... self.length).include? offset + raise BackTrackError, "offset: #{offset} out of range (0 ... #{self.length - 1})" unless (0 ... self.length).include? offset raise BackTrackError, "max_mismatches: #{max_mismatches} out of range (0 .. #{MAX_MIS})" unless (0 .. MAX_MIS).include? max_mismatches raise BackTrackError, "max_insertions: #{max_insertions} out of range (0 .. #{MAX_INS})" unless (0 .. MAX_INS).include? max_insertions raise BackTrackError, "max_deletions: #{max_deletions} out of range (0 .. #{MAX_DEL})" unless (0 .. MAX_DEL).include? max_deletions @@ -83,10 +83,14 @@ module BackTrack inline do |builder| builder.add_static "id_seq", 'rb_intern("@seq")', "ID" + # Macro for matching nucleotides including ambiguity codes. builder.prefix %{ #define MATCH(A,B) ((bitmap[(unsigned short) A] & bitmap[(unsigned short) B]) != 0) } + # Bitmap for matching nucleotides including ambiguity codes. + # For each value bits are set from the left: bit pos 1 for A, + # bit pos 2 for T, bit pos 3 for C, and bit pos 4 for G. builder.prefix %{ unsigned short bitmap[256] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -108,7 +112,9 @@ module BackTrack }; } - # ss is the start of the string, used only for reporting the match endpoints. + # Backtrack algorithm for matching a pattern (p) starting in a sequence (s) allowing for mm + # mismatches, ins insertions and del deletions. ss is the start of the sequence, used only for + # reporting the match endpoints. builder.prefix %{ unsigned int backtrack(char* ss, char* s, char* p, int mm, int ins, int del) { @@ -129,8 +135,8 @@ module BackTrack } } - # Find all occurrences of p starting at pos in s, with at most - # mm mismatches, ins insertions and del deletions. + # Find pattern (p) in a sequence (@seq) starting at pos, with at most mm mismatches, ins + # insertions and del deletions. builder.c %{ static VALUE track(char* p, unsigned int pos, int mm, int ins, int del) { @@ -165,6 +171,7 @@ module BackTrack } end + # Class containing match information. class Match attr_reader :pos, :length, :match diff --git a/code_ruby/lib/maasha/seq.rb b/code_ruby/lib/maasha/seq.rb index db93dc2..598d0a2 100644 --- a/code_ruby/lib/maasha/seq.rb +++ b/code_ruby/lib/maasha/seq.rb @@ -24,7 +24,7 @@ require 'maasha/patternmatcher' require 'maasha/bits' -#require 'maasha/backtrack' +require 'maasha/backtrack' require 'maasha/digest' #require 'maasha/patscan' @@ -46,7 +46,7 @@ class SeqError < StandardError; end class Seq #include Patscan include PatternMatcher -# include BackTrack + include BackTrack include Digest attr_accessor :seq_name, :seq, :type, :qual diff --git a/code_ruby/test/maasha/test_backtrack.rb b/code_ruby/test/maasha/test_backtrack.rb index 2c271aa..b2bc7f7 100644 --- a/code_ruby/test/maasha/test_backtrack.rb +++ b/code_ruby/test/maasha/test_backtrack.rb @@ -27,12 +27,12 @@ $:.unshift File.join(File.dirname(__FILE__),'..','lib') require 'test/unit' require 'maasha/seq' -require 'stringio' -require 'pp' class BackTrackTest < Test::Unit::TestCase def setup - @seq = Seq.new("test", "tacgatgctagcatgcacg") + # 0 1 + # 01234567890123456789 + @seq = Seq.new("test", "tacgatgctagcatgcacgg") end def test_BackTrack_patscan_with_bad_pattern_raises @@ -42,37 +42,102 @@ class BackTrackTest < Test::Unit::TestCase end def test_BackTrack_patscan_with_OK_pattern_dont_raise - ["N"].each { |pattern| + ["N", "atcg"].each { |pattern| assert_nothing_raised { @seq.patscan(pattern) } } end def test_BackTrack_patscan_with_bad_pos_raises + [-1, 20].each { |pos| + assert_raise(BackTrackError) { @seq.patscan("N", pos) } + } end def test_BackTrack_patscan_with_OK_pos_dont_raise + [0, 19].each { |pos| + assert_nothing_raised { @seq.patscan("N", pos) } + } end def test_BackTrack_patscan_with_bad_mis_raises + [-1, 6].each { |mis| + assert_raise(BackTrackError) { @seq.patscan("N", 0, mis) } + } end def test_BackTrack_patscan_with_OK_mis_dont_raise + [0, 5].each { |mis| + assert_nothing_raised { @seq.patscan("N", 0, mis) } + } end def test_BackTrack_patscan_with_bad_ins_raises + [-1, 6].each { |ins| + assert_raise(BackTrackError) { @seq.patscan("N", 0, 0, ins) } + } end def test_BackTrack_patscan_with_OK_ins_dont_raise + [0, 5].each { |ins| + assert_nothing_raised { @seq.patscan("N", 0, 0, ins) } + } end def test_BackTrack_patscan_with_bad_del_raises + [-1, 6].each { |del| + assert_raise(BackTrackError) { @seq.patscan("N", 0, 0, 0, del) } + } end def test_BackTrack_patscan_with_OK_del_dont_raise + [0, 5].each { |del| + assert_nothing_raised { @seq.patscan("N", 0, 0, 0, del) } + } + end + + def test_BackTrack_patscan_perfect_left_is_ok + assert_equal("0:7:tacgatg", @seq.patscan("TACGATG").first.to_s) + end + + def test_BackTrack_patscan_perfect_right_is_ok + assert_equal("13:7:tgcacgg", @seq.patscan("TGCACGG").first.to_s) + end + + def test_BackTrack_patscan_ambiguity_is_ok + assert_equal("13:7:tgcacgg", @seq.patscan("TGCACNN").first.to_s) + end + + def test_BackTrack_patscan_pos_is_ok + assert_equal("10:1:g", @seq.patscan("N", 10).first.to_s) + assert_equal("19:1:g", @seq.patscan("N", 10).last.to_s) + end + + def test_BackTrack_patscan_mis_left_is_ok + assert_equal("0:7:tacgatg", @seq.patscan("Aacgatg", 0, 1).first.to_s) + end + + def test_BackTrack_patscan_mis_right_is_ok + assert_equal("13:7:tgcacgg", @seq.patscan("tgcacgA", 0, 1).first.to_s) + end + + def test_BackTrack_patscan_ins_left_is_ok + assert_equal("0:7:tacgatg", @seq.patscan("Atacgatg", 0, 0, 1).first.to_s) + end + + def test_BackTrack_patscan_ins_right_is_ok + assert_equal("13:7:tgcacgg", @seq.patscan("tgcacggA", 0, 0, 1).first.to_s) + end + + def test_BackTrack_patscan_del_left_is_ok + assert_equal("0:7:tacgatg", @seq.patscan("acgatg", 0, 0, 0, 1).first.to_s) + end + + def test_BackTrack_patscan_del_right_is_ok + assert_equal("12:8:atgcacgg", @seq.patscan("tgcacgg", 0, 0, 0, 1).first.to_s) end - def test_BackTrack_patscan -# assert_equal("0:4:tacg", @seq.patscan("TACG").first.to_s) + def test_BackTrack_patscan_ambiguity_mis_ins_del_all_ok + assert_equal("0:20:tacgatgctagcatgcacgg", @seq.patscan("tacatgcNagGatgcCacgg", 0, 1, 1, 1).first.to_s) end end