[med-svn] [libfreecontact-perl] 32/46: Imported Upstream version 0.06

Laszlo Kajan lkajan at alioth.debian.org
Thu Sep 19 15:55:04 UTC 2013


This is an automated email from the git hooks/post-receive script.

lkajan pushed a commit to branch master
in repository libfreecontact-perl.

commit c8d248ab4956762db7732a59f5c2b3e316db0395
Author: Laszlo Kajan <lkajan at debian.org>
Date:   Mon Jun 17 16:30:13 2013 +0200

    Imported Upstream version 0.06
---
 Changes            |    3 +++
 FreeContact.xs     |    3 +--
 FreeContact.xsp    |   72 +++++++++++++++++++++++++++++++++++++++++++++++-----
 META.yml           |    2 +-
 lib/FreeContact.pm |   59 ++++++++++++++++++++++++++++++++++++------
 t/01FreeContact.t  |    2 +-
 t/02test.t         |   23 ++++++++++++++---
 typemap            |   39 +++++++++++++++++++++++++++-
 typemap.xsp        |    4 +--
 9 files changed, 181 insertions(+), 26 deletions(-)

diff --git a/Changes b/Changes
index 3ab1006..bafb435 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension FreeContact.
 
+0.06  Sun Jun 16 00:36:16 CEST 2013
+	- New method get_seq_weights() for obtaining sequence weight vector and total weight of alignment.
+
 0.05  Fri Jun  7 21:24:38 CEST 2013
 	- New libfreecontact - added timout argument.
 
diff --git a/FreeContact.xs b/FreeContact.xs
index 54966d7..09fa024 100644
--- a/FreeContact.xs
+++ b/FreeContact.xs
@@ -17,6 +17,7 @@ extern "C" {
 using namespace freecontact;
 typedef freecontact::predictor::cont_res_t	cont_res_t;
 typedef freecontact::predictor::time_res_t	time_res_t;
+typedef freecontact::predictor::freq_vec_t	freq_vec_t;
 
 #define _XPUSHS_GET_PS(__ps) \
         XPUSHs(sv_2mortal(newSVpvn("clustpc", 7)));\
@@ -41,8 +42,6 @@ typedef freecontact::predictor::time_res_t	time_res_t;
         XPUSHs(sv_2mortal(newSViv((__ps).cov20)));\
         XPUSHs(sv_2mortal(newSVpvn("gap_incovm", 10)));\
         XPUSHs(sv_2mortal(newSViv((__ps).gap_incovm)));\
-        XPUSHs(sv_2mortal(newSVpvn("veczw", 5)));\
-        XPUSHs(sv_2mortal(newSViv((__ps).veczw)));\
         XPUSHs(sv_2mortal(newSVpvn("rho", 3)));\
         XPUSHs(sv_2mortal(newSVnv((__ps).rho)));
 
diff --git a/FreeContact.xsp b/FreeContact.xsp
index 76bf990..6c7e5ad 100644
--- a/FreeContact.xsp
+++ b/FreeContact.xsp
@@ -31,20 +31,49 @@ get_ps_psicov_sd()
                     %name{_new} predictor(bool __dbg = false);
                     ~predictor();
 
+/*    void            get_seq_weights(
+                        freq_vec_t& __aliw, double& __wtot,
+                        ali_t& __ali, double __clustpc,
+                        bool __veczw = true, int __num_threads = 0
+                    );*/
+
+%{
+void
+predictor::_get_seq_weights( freq_vec_t* __aliw, double* __wtot, ali_t& __ali, double __clustpc, bool __veczw = true, int __num_threads = 0 )
+  PREINIT:
+    freq_vec_t aliw;
+    double wtot;
+  CODE:
+    __aliw = &aliw; __wtot = &wtot;
+    try {
+      THIS->get_seq_weights( *( __aliw ), *( __wtot ), __ali, __clustpc, __veczw, __num_threads );
+    }
+    catch (std::exception& e) {
+      croak("Caught C++ exception of type or derived from 'std::exception': %s", e.what());
+    }
+    catch (...) {
+      croak("Caught C++ exception of unknown type");
+    }
+  OUTPUT:
+    __aliw
+    __wtot
+%}
+
 // lkajan: I apparently can not use this to add an INIT: block to the XS
-/*    cont_res_t      _run( ali_t& __ali, double __cp, double __dens, double __gapth, U16 __mincontsep,
+/*    cont_res_t      run( ali_t& __ali, double __cp,
+                        double __density, double __gapth, U16 __mincontsep,
                         double __pseudocnt, double __pscnt_weight, bool __estimate_ivcov, double __shrink_lambda,
-                        bool __cov20, bool __gap_incovm, bool __vecw, double __rho,
-                        int __num_threads = 0, time_res_t *__timing = NULL
+                        bool __cov20, bool __gap_incovm, double __rho,
+                        bool __veczw = true, int __num_threads = 0, time_res_t *__timing = NULL
                     );*/
 };
 
 %{
 cont_res_t
-predictor::_run( __ali, __cp, __dens, __gapth, __mincontsep, __pseudocnt, __pscnt_weight, __estimate_ivcov, __shrink_lambda, __cov20, __gap_incovm, __vecw, __rho, __num_threads = 0, __icme_timeout = 1800, __timing = NULL )
+predictor::_run( __ali, __cp, __density, __gapth, __mincontsep, __pseudocnt, __pscnt_weight, __estimate_ivcov, __shrink_lambda, __cov20, __gap_incovm, __rho, __veczw = true, __num_threads = 0, __icme_timeout = 1800, __timing = NULL )
     ali_t& __ali
     double __cp
-    double __dens
+    double __density
     double __gapth
     U16 __mincontsep
     double __pseudocnt
@@ -53,8 +82,8 @@ predictor::_run( __ali, __cp, __dens, __gapth, __mincontsep, __pseudocnt, __pscn
     double __shrink_lambda
     bool __cov20
     bool __gap_incovm
-    bool __vecw
     double __rho
+    bool __veczw
     int __num_threads
     time_t __icme_timeout
     time_res_t* __timing
@@ -63,7 +92,36 @@ predictor::_run( __ali, __cp, __dens, __gapth, __mincontsep, __pseudocnt, __pscn
   CODE:
     try {
       if(items>=17 && SvROK(ST(16)) && SvTYPE(SvRV(ST(16))) == SVt_PVHV) __timing = &timing;
-      RETVAL = THIS->run( __ali, __cp, __dens, __gapth, __mincontsep, __pseudocnt, __pscnt_weight, __estimate_ivcov, __shrink_lambda, __cov20, __gap_incovm, __vecw, __rho, __num_threads, __icme_timeout, __timing );
+      RETVAL = THIS->run( __ali, __cp, __density, __gapth, __mincontsep, __pseudocnt, __pscnt_weight, __estimate_ivcov, __shrink_lambda, __cov20, __gap_incovm, __rho, __veczw, __num_threads, __icme_timeout, __timing );
+    }
+    catch (freecontact::icme_timeout_error& e)
+    {
+      croak("Caught FreeContact timeout exception: %s", e.what());
+    }
+    catch (std::exception& e) {
+      croak("Caught C++ exception of type or derived from 'std::exception': %s", e.what());
+    }
+    catch (...) {
+      croak("Caught C++ exception of unknown type");
+    }
+  OUTPUT:
+    __timing
+    RETVAL
+%}
+
+%{
+cont_res_t
+predictor::_run_with_seq_weights(ali_t& __ali, freq_vec_t &__aliw, double __wtot, double __density, double __gapth, U16 __mincontsep, double __pseudocnt, double __pscnt_weight, bool __estimate_ivcov, double __shrink_lambda, bool __cov20, bool __gap_incovm, double __rho, int __num_threads = 0, time_t __icme_timeout = 1800, time_res_t *__timing = NULL)
+  PREINIT:
+    time_res_t timing;
+  CODE:
+    try {
+      if(items>=17 && SvROK(ST(16)) && SvTYPE(SvRV(ST(16))) == SVt_PVHV) __timing = &timing;
+      RETVAL = THIS->run( __ali, __aliw, __wtot,
+        __density, __gapth, __mincontsep,
+        __pseudocnt, __pscnt_weight, __estimate_ivcov, __shrink_lambda,
+        __cov20, __gap_incovm, __rho,
+        __num_threads, __icme_timeout, __timing );
     }
     catch (freecontact::icme_timeout_error& e)
     {
diff --git a/META.yml b/META.yml
index 48f94f2..a0bea3e 100644
--- a/META.yml
+++ b/META.yml
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:               FreeContact
-version:            0.05
+version:            0.06
 abstract:           fast protein contact predictor
 author:
     - Laszlo Kajan <lkajan at rostlab.org>
diff --git a/lib/FreeContact.pm b/lib/FreeContact.pm
index c5ec6c2..8447299 100644
--- a/lib/FreeContact.pm
+++ b/lib/FreeContact.pm
@@ -35,7 +35,7 @@ our @EXPORT = qw(
 	
 );
 
-our $VERSION = '0.05';
+our $VERSION = '0.06';
 
 require XSLoader;
 XSLoader::load('FreeContact', $VERSION);
@@ -51,16 +51,42 @@ sub                 FreeContact::Predictor::new
     );
 }
 
+sub                 FreeContact::Predictor::get_seq_weights
+{
+    my $self = shift(@_);
+    if(scalar(@_)%2){ confess("Odd number of arguments"); }
+    my %args = (get_ps_evfold(), @_);
+    my ($aliw, $wtot);
+    $self->_get_seq_weights($aliw, $wtot,
+        $args{ali}, $args{clustpc},
+        defined($args{veczw}) ? $args{veczw} : 1, $args{num_threads} || 0
+    );
+    return ($aliw, $wtot);
+}
+
 sub                 FreeContact::Predictor::run
 {
     my $self = shift(@_);
     if(scalar(@_)%2){ confess("Odd number of arguments"); }
     my %args = (get_ps_evfold(), @_);
-    return $self->_run($args{ali},
-        $args{clustpc}, $args{density}, $args{gapth}, $args{mincontsep},
+    return $self->_run($args{ali}, $args{clustpc},
+        $args{density}, $args{gapth}, $args{mincontsep},
+        $args{pseudocnt}, $args{pscnt_weight}, $args{estimate_ivcov}, $args{shrink_lambda},
+        $args{cov20}, $args{gap_incovm}, $args{rho},
+        defined($args{veczw}) ? $args{veczw} : 1, $args{num_threads} || 0, defined($args{icme_timeout}) ? $args{icme_timeout} : 1800, $args{timing}
+    );
+}
+
+sub                 FreeContact::Predictor::run_with_seq_weights
+{
+    my $self = shift(@_);
+    if(scalar(@_)%2){ confess("Odd number of arguments"); }
+    my %args = (get_ps_evfold(), @_);
+    return $self->_run_with_seq_weights($args{ali}, $args{aliw}, $args{wtot},
+        $args{density}, $args{gapth}, $args{mincontsep},
         $args{pseudocnt}, $args{pscnt_weight}, $args{estimate_ivcov}, $args{shrink_lambda},
-        $args{cov20}, $args{gap_incovm}, $args{veczw}, $args{rho},
-        $args{num_threads} || 0, $args{icme_timeout} || 1800, $args{timing}
+        $args{cov20}, $args{gap_incovm}, $args{rho},
+        $args{num_threads} || 0, defined($args{icme_timeout}) ? $args{icme_timeout} : 1800, $args{timing}
     );
 }
 
@@ -85,7 +111,11 @@ FreeContact - fast protein contact predictor
 
   my $predictor = FreeContact::Predictor->new();
   my %parset = FreeContact::get_ps_evfold();
-  my $contacts = $predictor->run(ali => \@aln, %parset, num_threads => 1 );
+  my $contacts = $predictor->run(ali => \@aln, %parset, num_threads => 1);
+
+  my $predictor = FreeContact::Predictor->new();
+  my($aliw, $wtot) = $predictor->get_seq_weights(ali => \@aln, num_threads => 1);
+  my $contacts = $predictor->run_with_seq_weights(ali => \@aln, aliw => $aliw, wtot => $wtot, num_threads => 1);
 
 =head1 DESCRIPTION
 
@@ -114,12 +144,19 @@ can be used to generate the alignments, for example.
 
 =item get_ps_evfold()
 
+Get parameters for EVfold-mfDCA operating mode.
+
 =item get_ps_psicov()
 
+Get parameters for PSICOV (best performance) operating mode.
+
 =item get_ps_psicov_sd()
 
-These functions return a hash of arguments (clustpc => I<num>,...,rho => I<num>) that can be used
-with run(). The arguments correspond to the published parametrization of the
+Get parameters for PSICOV 'sensible default' operating mode. This is much faster than PSICOV for a
+slight loss of precision.
+
+These get_ps_() functions return a hash of arguments (clustpc => I<num>,...,rho => I<num>) that can be used
+with get_seq_weights(), run() or run_with_seq_weights(). The arguments correspond to the published parametrization of the
 respective method.
 
 =back
@@ -140,6 +177,10 @@ Creates an "FreeContact::Predictor".
 
 =over
 
+=item get_seq_weights() TODO
+
+Defaults for the arguments are obtained with get_ps_evfold().
+
 =item run( ali => I<[]>, clustpc => dbl, density => dbl, gapth => dbl, mincontsep => uint,
     pseudocnt => dbl, pscnt_weight => dbl, estimate_ivcov => bool, shrink_lambda => dbl,
     cov20 => bool, gap_incovm => bool, veczw => bool, rho => dbl,
@@ -198,6 +239,8 @@ run() returns a hash reference of contact prediction results:
     l1norm => ...
   }
 
+'fro' scores are recommended in EVfold
+
 =back
 
 =head1 AUTHOR
diff --git a/t/01FreeContact.t b/t/01FreeContact.t
index 4d365c6..f9e76c0 100644
--- a/t/01FreeContact.t
+++ b/t/01FreeContact.t
@@ -15,6 +15,6 @@ BEGIN { use_ok('FreeContact') };
 
 {
     can_ok('FreeContact', qw(get_ps_evfold get_ps_psicov get_ps_psicov_sd));
-    can_ok('FreeContact::Predictor', qw(new _run run));
+    can_ok('FreeContact::Predictor', qw(new _get_seq_weights get_seq_weights _run run));
 }
 # vim:et:ts=4:ai:
diff --git a/t/02test.t b/t/02test.t
index 13b3f17..f99063e 100644
--- a/t/02test.t
+++ b/t/02test.t
@@ -2,14 +2,13 @@ use strict;
 use warnings;
 
 use Scalar::Util 'reftype';
-use Test::More tests => 8;
+use Test::More tests => 10;
 BEGIN { use_ok('FreeContact') };
 
 # /usr/share/doc/libextutils-xspp-perl/examples/Object-WithIntAndString/t/02test.t
 sub check_obj {
     my $o = shift;
-    isa_ok($o, 'FreeContact::Predictor' );
-    can_ok($o, qw(new run _run) );
+    isa_ok($o, 'FreeContact::Predictor');
 }
 
 {
@@ -30,8 +29,12 @@ sub check_obj {
 
     my $res = FreeContact::Predictor->new(dbg => 1)->run(ali => \@aln, num_threads => $num_threads, timing => $timing);
 
+    my $evfold_24_42 = 0.0129471030086279; # 0-based indices
+
     is(reftype($res), 'HASH');
-    ok(($res->{fro}->[126+125]->[2]-8.08998)/8.08998 < 1e-6, 'precision test'); # [ 2, 3, 8.08998+- ]
+
+    #use Data::Dumper; warn(Dumper($res));
+    ok(abs($res->{fro}->[2741]->[2]-$evfold_24_42)/$evfold_24_42 < 1e-6, 'precision test'); # 25 K 43 N 0.230969 0.0129471
     ok($timing->{num_threads} == $num_threads, "timing results test");
 
     #use Data::Dumper; warn(Dumper($timing));
@@ -41,6 +44,18 @@ sub check_obj {
         $res = FreeContact::Predictor->new(dbg => 1)->run(%test_parset, ali => \@aln, num_threads => $num_threads, icme_timeout => 2, timing => $timing);
     };
     like($@, qr/^Caught FreeContact timeout exception:/);
+
+    # aliw+wtot start test
+    {
+        my($aliw, $wtot) = FreeContact::Predictor->new(dbg => 1)->get_seq_weights(ali => \@aln, num_threads => $num_threads);
+        #use Data::Dumper; warn(Dumper($aliw, \$wtot));
+        is(@$aliw, 1000);
+        ok(abs($wtot-620.777)/620.777 < 1e-6, 'wtot test');
+
+        my $res = FreeContact::Predictor->new(dbg => 1)->run_with_seq_weights(ali => \@aln, aliw => $aliw, wtot => $wtot, num_threads => $num_threads, timing => $timing);
+warn($res->{fro}->[2741]->[2]);
+        ok(abs($res->{fro}->[2741]->[2]-$evfold_24_42)/$evfold_24_42 < 1e-6, 'wtot precision test'); # [ 2, 3, 8.08998+- ]
+    }
 }
 
 # vim:et:ts=4:ai:
diff --git a/typemap b/typemap
index a0cef51..3c814c6 100644
--- a/typemap
+++ b/typemap
@@ -6,9 +6,11 @@
 # Example: /usr/share/perl/5.10.1/ExtUtils/typemap perlobject.map
 TYPEMAP
 cont_res_t			T_CONT_RES
+double*				T_DOUBLE_PTR
+freq_vec_t          T_FREQ_VEC
+freq_vec_t*         T_FREQ_VEC_PTR
 predictor*			O_OBJECT
 ali_t				T_ALI
-std::string			T_PV
 time_res_t*			T_TIME_RES_PTR
 
 INPUT
@@ -50,6 +52,29 @@ T_ALI
 		}
 		else croak(\"${Package}::$func_name() -- $var is not an AV reference\");
 	}
+T_DOUBLE_PTR
+T_FREQ_VEC
+	{
+		if(SvROK($arg) && SvTYPE(SvRV($arg)) == SVt_PVAV)
+		{
+			// form vector out of $arg = [ 1, 0.9, 0.7, ... ]
+			AV *arr = (AV*)SvRV($arg);
+			I32 wcnt = av_len(arr)+1; // av_len returns highest index
+			if(wcnt > 0)
+			{
+				$var = $type(wcnt);
+				for(I32 k = 0; k < wcnt; ++k)
+				{
+					SV** svptr = av_fetch(arr, k, false);
+					if(svptr != NULL && SvNIOK(*svptr))
+						($var)[k] = SvNV(*svptr);
+					else croak(\"${Package}::$func_name() -- $var\[%d\] is not a number\", k);
+				}
+			}
+		}
+		else croak(\"${Package}::$func_name() -- $var is not an AV reference\");
+	}
+T_FREQ_VEC_PTR
 T_TIME_RES_PTR
 
 OUTPUT
@@ -80,6 +105,18 @@ T_CONT_RES
 
 		sv_setsv($arg, newRV((SV*)res));
 	}
+T_DOUBLE_PTR
+	sv_setnv($arg, (double)*$var);
+T_FREQ_VEC_PTR
+	{
+		// return [ 1, 0.9, 0.7, ... ]
+		AV* res = (AV*)sv_2mortal((SV*)newAV()); av_extend(res, $var->size()-1); // extend to index
+
+		for(freq_vec_t::const_iterator fv_i = $var->begin(), fv_e = $var->end(); fv_i != fv_e; ++fv_i)
+			av_push(res, newSVnv(*fv_i));
+
+		sv_setsv($arg, newRV((SV*)res));
+	}
 T_TIME_RES_PTR
 	if($var && SvROK($arg) && SvTYPE(SvRV($arg)) == SVt_PVHV)
 	{
diff --git a/typemap.xsp b/typemap.xsp
index ba8e849..eb7ebfe 100644
--- a/typemap.xsp
+++ b/typemap.xsp
@@ -8,11 +8,11 @@
 %typemap{parset_t}{simple};
 %typemap{predictor*}{simple};
 %typemap{ali_t&}{simple};
-%typemap{double}{simple};
+%typemap{double};
 %typemap{U16}{simple};
 %typemap{bool}{simple};
 %typemap{std::map}{simple};
-%typemap{std::string}{simple};
+%typemap{freq_vec_t};
 %typemap{time_res_t*}{simple};
 
 // vim:noet:syntax=cpp:ts=4:

-- 
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/libfreecontact-perl.git



More information about the debian-med-commit mailing list