1 /**********************************/
2 /* MerDNA proxy class for mer_dna */
3 /**********************************/
4 %{
5   class MerDNA : public jellyfish::mer_dna {
6   public:
7     MerDNA() = default;
MerDNA(const char * s)8     MerDNA(const char* s) : jellyfish::mer_dna(s) { }
MerDNA(const MerDNA & m)9     MerDNA(const MerDNA& m) : jellyfish::mer_dna(m) { }
10     MerDNA& operator=(const jellyfish::mer_dna& m) { *static_cast<jellyfish::mer_dna*>(this) = m; return *this; }
11   };
12 %}
13 
14 #ifdef SWIGRUBY
15 %bang MerDNA::randomize();
16 %bang MerDNA::canonicalize();
17 %bang MerDNA::reverse_complement();
18 %bang MerDNA::polyA();
19 %bang MerDNA::polyC();
20 %bang MerDNA::polyG();
21 %bang MerDNA::polyT();
22 // %predicate MerDNA::is_homopolymer(); // Does not work???
23 %rename("MerDNA::homopolymer?") MerDNA::is_homopolymer();
24 %rename("MerDNA::complement") MerDNA::get_reverse_complement();
25 %rename("MerDNA::canonical") MerDNA::get_canonical();
26 #endif
27 
28 
29 %feature("autodoc", "Class representing a mer. All the mers have the same length, which must be set BEFORE instantiating any mers with jellyfish::MerDNA::k(int)");
30 class MerDNA {
31 public:
32   MerDNA();
33   MerDNA(const char*);
34   MerDNA(const MerDNA&);
35 
36   %feature("autodoc", "Get the length of the k-mers");
37   static unsigned int k();
38   %feature("autodoc", "Set the length of the k-mers");
39   static unsigned int k(unsigned int);
40 
41   %feature("autodoc", "Change the mer to a homopolymer of A");
42   void polyA();
43   %feature("autodoc", "Change the mer to a homopolymer of C");
44   void polyC();
45   %feature("autodoc", "Change the mer to a homopolymer of G");
46   void polyG();
47   %feature("autodoc", "Change the mer to a homopolymer of T");
48   void polyT();
49   %feature("autodoc", "Change the mer to a random one");
50   void randomize();
51   %feature("autodoc", "Check if the mer is a homopolymer");
52   bool is_homopolymer() const;
53 
54   %feature("autodoc", "Shift a base to the left and the leftmost base is return . \"ACGT\", shift_left('A') becomes \"CGTA\" and 'A' is returned");
55   char shift_left(char);
56   %feature("autodoc", "Shift a base to the right and the rightmost base is return . \"ACGT\", shift_right('A') becomes \"AACG\" and 'T' is returned");
57   char shift_right(char);
58 
59   %feature("autodoc", "Change the mer to its canonical representation");
60   void canonicalize();
61   %feature("autodoc", "Change the mer to its reverse complement");
62   void reverse_complement();
63   %feature("autodoc", "Return canonical representation of the mer");
64   MerDNA get_canonical() const;
65   %feature("autodoc", "Return the reverse complement of the mer");
66   MerDNA get_reverse_complement() const;
67 
68   %feature("autodoc", "Equality between mers");
69   bool operator==(const MerDNA&) const;
70   %feature("autodoc", "Lexicographic less-than");
71   bool operator<(const MerDNA&) const;
72   %feature("autodoc", "Lexicographic greater-than");
73   bool operator>(const MerDNA&) const;
74 
75 
76   %extend{
77     %feature("autodoc", "Duplicate the mer");
dup()78     MerDNA dup() const { return MerDNA(*self); }
79     %feature("autodoc", "Return string representation of the mer");
__str__()80     std::string __str__() { return self->to_str(); }
81     %feature("autodoc", "Set the mer from a string");
set(const char * s)82     void set(const char* s) throw(std::length_error) { *static_cast<jellyfish::mer_dna*>(self) = s; }
83 
84 #ifdef SWIGPERL
get_base(unsigned int i)85     char get_base(unsigned int i) { return (char)self->base(i); }
set_base(unsigned int i,char b)86     void set_base(unsigned int i, char b) { self->base(i) = b; }
87 #else
88     %feature("autodoc", "Get base i (0 <= i < k)");
__getitem__(unsigned int i)89     char __getitem__(unsigned int i) { return (char)self->base(i); }
90     %feature("autodoc", "Set base i (0 <= i < k)");
__setitem__(unsigned int i,char b)91     void __setitem__(unsigned int i, char b) { self->base(i) = b; }
92     //    MerDNA __neg__() const { return self->get_reverse_complement(); }
93     %feature("autodoc", "Shift a base to the left and return the mer");
__lshift__(char b)94     MerDNA& __lshift__(char b) { self->shift_left(b); return *self; }
95     %feature("autodoc", "Shift a base to the right and return the mer");
__rshift__(char b)96     MerDNA& __rshift__(char b) { self->shift_right(b); return *self; }
97 #endif
98   }
99 };
100