From: martinahansen Date: Thu, 2 Sep 2010 08:01:47 +0000 (+0000) Subject: added scores_to_dec biopiece, wiki, and tests X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=4f11b77e8927625e3d5c8ae4f968412d5f44a534;p=biopieces.git added scores_to_dec biopiece, wiki, and tests git-svn-id: http://biopieces.googlecode.com/svn/trunk@1075 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/scores_to_dec b/bp_bin/scores_to_dec new file mode 100755 index 0000000..9c94454 --- /dev/null +++ b/bp_bin/scores_to_dec @@ -0,0 +1,66 @@ +#!/usr/bin/env ruby + +# Copyright (C) 2007-2010 Martin A. Hansen. + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# This program is part of the Biopieces framework (www.biopieces.org). + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Convert ASCII encoded quality scores in stream to a semi-colon seperated string of decimal values. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +require 'biopieces' + +# Expading class Hash with possibly evil monkey patch. +class Hash + # Method to convert scores from ASCII encode string to + # a semi-colon seperated string of decimal values. + def scores2dec!(base) + if self.has_key? :SCORES + self[:SCORES].gsub! /./ do |score| + score = (score.ord - base).to_s + ";" + end + + self[:SCORES].chomp! ";" + end + + self + end +end + +casts = [] +casts << {:long=>'base', :short=>'b', :type=>'uint', :mandatory=>false, :default=>64, :allowed=>"33,59,64", :disallowed=>nil} + +bp = Biopieces.new + +options = bp.parse(ARGV, casts) + +bp.each_record do |record| + bp.puts record.scores2dec!(options[:base]) +end + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +__END__ diff --git a/bp_test/in/scores_to_dec.in b/bp_test/in/scores_to_dec.in new file mode 100644 index 0000000..e40bdf7 --- /dev/null +++ b/bp_test/in/scores_to_dec.in @@ -0,0 +1,2 @@ +SCORES: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ +--- diff --git a/bp_test/out/scores_to_dec.out.1 b/bp_test/out/scores_to_dec.out.1 new file mode 100644 index 0000000..ddd77d4 --- /dev/null +++ b/bp_test/out/scores_to_dec.out.1 @@ -0,0 +1,2 @@ +SCORES: -31;-30;-29;-28;-27;-26;-25;-24;-23;-22;-21;-20;-19;-18;-17;-16;-15;-14;-13;-12;-11;-10;-9;-8;-7;-6;-5;-4;-3;-2;-1;0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56;57;58;59;60;61;62 +--- diff --git a/bp_test/out/scores_to_dec.out.2 b/bp_test/out/scores_to_dec.out.2 new file mode 100644 index 0000000..00f19b6 --- /dev/null +++ b/bp_test/out/scores_to_dec.out.2 @@ -0,0 +1,2 @@ +SCORES: 0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56;57;58;59;60;61;62;63;64;65;66;67;68;69;70;71;72;73;74;75;76;77;78;79;80;81;82;83;84;85;86;87;88;89;90;91;92;93 +--- diff --git a/bp_test/out/scores_to_dec.out.3 b/bp_test/out/scores_to_dec.out.3 new file mode 100644 index 0000000..c192097 --- /dev/null +++ b/bp_test/out/scores_to_dec.out.3 @@ -0,0 +1,2 @@ +SCORES: -26;-25;-24;-23;-22;-21;-20;-19;-18;-17;-16;-15;-14;-13;-12;-11;-10;-9;-8;-7;-6;-5;-4;-3;-2;-1;0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56;57;58;59;60;61;62;63;64;65;66;67 +--- diff --git a/bp_test/test/test_scores_to_dec b/bp_test/test/test_scores_to_dec new file mode 100755 index 0000000..d4e7076 --- /dev/null +++ b/bp_test/test/test_scores_to_dec @@ -0,0 +1,15 @@ +#!/bin/bash + +source "$BP_DIR/bp_test/lib/test.sh" + +run "$bp -I $in -O $tmp" +assert_no_diff $tmp $out.1 +clean + +run "$bp -I $in -b 33 -O $tmp" +assert_no_diff $tmp $out.2 +clean + +run "$bp -I $in -b 59 -O $tmp" +assert_no_diff $tmp $out.3 +clean