[BioPython] first steps into python

Iddo Friedberg idoerg@cc.huji.ac.il
Sat, 24 Feb 2001 18:08:21 +0200 (GMT+0200)


Hi Ewan,

On Sat, 24 Feb 2001, Ewan Birney wrote:

:
: Ok. To help Ensembl-->python (probably via CORBA) integration. I have
: downloaded biopython and biopython-corba.
:
: I am, therefore, belated learning python. Don't expect any road-to-damscus
: type conversions (yet) however...

Hehe.. well, nobody expects the Spanish Inquisition!

(Sorry, couldn't help myself).

:
: Some questions
:
: (a) what is the difference between def __name__ and def name functions?

"def name" is used for defining functions (not in classes) and methods (in
classes). The double underscore wrapping is used for specially named
methods (not functions)  providing extra class behavior. For example
__init__ is a constructor, __del__ is an instance's destructor, __add__
overloads the "+" operator.  They are also called "hook" methods. The
underscore wrapping is simply a way to avoid clashes between hook methods
and stuff we define ourselves.


:
: (b) how is inhertiance done in python

"Instance objects inherit attributes (methods & members) from their class,
and all accessible superclasses, according to a depth-first, left-to-right
search through superclass links. Inheritance occurs when an object is
qualified:
object.attribute" (Mark Lutz, Programming Python)

>From this I hope you gather that Python supports multiple inheritance as
well.

Let's demonstrate inheritance with a stack class (no multiples here):

class MyStack:
   def __init__(self):
      self.stack = []

   def push(self, inobject):
      self.stack.append(inobject)

   def pop(self):
      retval, self.stack = self.stack[-1], self.stack[:-1]
      return retval

OK, that bit of code is hopefully obvious. I have a constructor method
(__init__), a "push" and a "pop".

Now, I am not happy with this class somebody provided, because I would
like to add a "isempty" boolean method. So I subclass like this:

class MySuperStack(MyStack):
   # return true if stack is empty, false if otherwise
   def isempty(self):
      return not self.stack

MySuperStack has the same methods (__init__, pop, push) and members
(stack) as in MyStack, with the addition of the "isempty" method.

Now I can create instances: (the ">>>" is the Python interpreter's prompt,
not part of code, just a convention):

>>> my_not_perfect_stack = MyStack()
>>> my_perfect_stack = MySuperStack()

and work with them:

>>> my_perfect_stack.push(5)
>>> my_perfect_stack.push(7)

>>> a = my_perfect_stack.pop()
>>> print a
7

:
: (c) is there any concept/files for interfaces either expliciting (java) or
: "just documentation" like bioperl's "I" files

I'll let someone who understands the question answer that.... :)

:
: (d) could some one sketch out an easy biopython script like:

Ooops, look at the time! No, seriously, if somebody else doesn't do that
by tomorrow, I'll fill in this blank.


:
:  read embl file.
:
: 	test whether there is a cacaca repeat in there
:
: 	if yes, dump a genbank file.
:
:
:
: yours from the rough-and-ready world of Perl...
:

Iddo

--

Iddo Friedberg                                  | Tel: +972-2-6758647
Dept. of Molecular Genetics and Biotechnology   | Fax: +972-2-6757308
The Hebrew University - Hadassah Medical School | email: idoerg@cc.huji.ac.il
POB 12272, Jerusalem 91120                      |
Israel                                          |
http://bioinfo.md.huji.ac.il/marg/people-home/iddo/