Changeset 78

Show
Ignore:
Timestamp:
11/28/06 00:42:17 (2 years ago)
Author:
t
Message:

Python interface to the N-way comparison stuff.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/paircomp/lib/NwayComparison.cc

    r77 r78  
    9797std::vector<NwayPath> NwayComparison::filter() 
    9898{ 
     99  do_comparisons(); 
     100 
    99101  std::string seq0 = _sequences[0]; 
    100102  std::vector<NwayPath> ret_paths; 
  • trunk/paircomp/lib/paircomp.hh

    r11 r78  
    1111#include "MutableComparison.hh" 
    1212#include "ImmutableComparison.hh" 
     13#include "NwayComparison.hh" 
    1314 
    1415#include "algorithms.hh" 
  • trunk/paircomp/python/c++-ext/_paircomp_parser.cc

    r50 r78  
    550550 
    551551  return ret; 
     552} 
     553 
     554static PyObject * create_nway(PyObject * self, PyObject * args) 
     555{ 
     556  unsigned int windowsize; 
     557  float threshold; 
     558 
     559  if (!PyArg_ParseTuple(args, "If", &windowsize, &threshold)) { 
     560    return NULL; 
     561  } 
     562 
     563  NwayComparison * nway = new NwayComparison(windowsize, threshold); 
     564 
     565  return PyCObject_FromVoidPtr(nway, NULL); // @CTB 
     566} 
     567 
     568static PyObject * add_sequence_to_nway(PyObject * self, PyObject * args) 
     569{ 
     570  char * seq; 
     571  PyObject * p; 
     572 
     573  if (!PyArg_ParseTuple(args, "Os", &p, &seq)) { 
     574    return NULL; 
     575  } 
     576 
     577  NwayComparison * nway = (NwayComparison *) PyCObject_AsVoidPtr(p); 
     578  nway->add_sequence(seq); 
     579 
     580  Py_INCREF(Py_None); 
     581  return Py_None; 
     582} 
     583 
     584std::string print_poso_v(NwayPath v) 
     585{ 
     586  char buf[50]; 
     587  std::string ret; 
     588  for (unsigned int i = 0; i < v.size(); i++) { 
     589    PosAndO p = v[i]; 
     590    sprintf(buf, "%d(%c) ", p.pos, p.orient > 0 ? '+' : '-'); 
     591    ret += buf; 
     592  } 
     593  ret += "\n"; 
     594 
     595  return ret; 
     596} 
     597 
     598static PyObject * get_nway_filtered_paths(PyObject * self, PyObject * args) 
     599{ 
     600  PyObject * p; 
     601 
     602  if (!PyArg_ParseTuple(args, "O", &p)) { 
     603    return NULL; 
     604  } 
     605 
     606  NwayComparison * nway = (NwayComparison *) PyCObject_AsVoidPtr(p); 
     607 
     608  std::string ret; 
     609  std::vector<NwayPath> paths = nway->filter(); 
     610  for (unsigned int i = 0; i < paths.size(); i++) { 
     611    NwayPath path = paths[i]; 
     612    ret += print_poso_v(path); 
     613  } 
     614   
     615  return PyString_FromString(ret.c_str()); 
    552616} 
    553617 
     
    577641  { "is_empty", is_empty, METH_VARARGS }, 
    578642  { "subtract", subtract, METH_VARARGS }, 
     643  { "create_nway", create_nway, METH_VARARGS }, 
     644  { "add_sequence_to_nway", add_sequence_to_nway, METH_VARARGS }, 
     645  { "get_nway_filtered_paths", get_nway_filtered_paths, METH_VARARGS }, 
    579646  { NULL, NULL } 
    580647}; 
  • trunk/paircomp/tests/nway.py

    r77 r78  
    322322if __name__ == '__main__': 
    323323    test() 
     324 
     325    from paircomp import _paircomp_parser 
     326    o = _paircomp_parser.create_nway(10, 0.7) 
     327    _paircomp_parser.add_sequence_to_nway(o, 'AAAAAAAAAA') 
     328    _paircomp_parser.add_sequence_to_nway(o, 'AAAAAAAAAA') 
     329    _paircomp_parser.add_sequence_to_nway(o, 'AAAAAAAAAA') 
     330    _paircomp_parser.add_sequence_to_nway(o, 'TTTTTTTTTT') 
     331    print _paircomp_parser.get_nway_filtered_paths(o)