7

I'm programming genetic processes in java for my project and I want simulate the mitosis of a human cell. A human cell contains 23 pairs of chromosome. Mitosis is basically a cell division, or reproduction, in which a cell gives rise to two genetically identical daughter cells. You can find a picture about it here (scroll a little bit down the page):

Mitosis

I think that this mitosis would be like a java method in a class "Cell" for example. So i made a class Chromosome with it's own methods to represent a single chromosome and made a class "Cell" containing 23 pairs of chromosomes. I plan on putting the method mitosis in the class Cell but the problem is that this method should return 2 identical cells and I think it's impossible to create a method that returns 2 cells in this class. I thought about making a method that would return an array of 2 cells it doesn't work. Any suggestions an how to create this method? Or maybe another approach than the one i'm using? Thanks.

Tom Castle
  • 2,198
  • 1
  • 16
  • 20
mkab
  • 73
  • 2
  • 1
    "I thought about making a method that would return an array of 2 cells it doesn't work." What doesn't work exactly? Because it should. – hoha Mar 18 '11 at 23:55

4 Answers4

3

Actually that's what I'm even using to clone my cells. But it's not the cloning of the cells that's my problem, it's what the method "mitosis" should return. As long as mitosis(biologically) is concerned, two identical cells are produced.

You are getting hung up over trying to make Java behave like a real world object.

What you should be focusing on is having the right number of the right kind of cells after mitosis, not on making the method signatures directly mirror the real-world events.

Mitosis is where one cell splits into two. IMO, any of the following are valid "models" in Java:

  • a method on this Cell that returns the other one:

    public Cell mitosis() {
        return this.clone();  // ... or equivalent
    }
    
  • a method on this Cell that returns two cells:

    public Cell[] mitosis() {
        return new Cell[]{this, this.clone()};  // ... note - must return this as one 
                                                // of the objects
    }
    
  • a static method that returns two cells:

    public static Cell[] mitosis(Cell one) {
        return new Cell[]{one, one.clone()}; 
    }
    

Even the following might be right ... if the caller takes care to remove all references to the original cell.

    public static Cell[] mitosis(Cell original) {
        return new Cell[]{original.clone(), original.clone()}; 
    }

But my point is that it doesn't really matter what the signatures are. What matters is that after the method (and the caller) have done there stuff, the new model has the right Cell objects in the right relationships.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Yeah I'm so hung up in trying to make Java behave like a real world object. So it I should use of the following methods above should I create a class "Individual" for example having as a variable an ArrayList of Cells? So that each time a cell undergo mitosis I add the resulting cells to this ArrayList? Hope I'm not thinking to much in real world? – mkab Mar 19 '11 at 00:51
1

As an alternative to Cloneable, consider a copy constructor or a copy factory, the static factory analog of a copy constructor.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I read up on those a bit and it gave some information about the differences but i think Cloneable is ok for me. Thanks for the suggestion – mkab Mar 19 '11 at 00:33
  • You're welcome; it's just an implementation detail. As suggested by others, you should focus on what aspect of cell metabolism you want to model: mitosis is only one phase. – trashgod Mar 19 '11 at 00:42
1

I would suggest that Cell implements Cloneable and use the copy constructor idiom on clone() method.

On doMitosis() method in Cell you basically do something like this:

public Cell[] doMitosis() {
    Cell[] cells = new Cell[]{this.clone(), this.clone()};
    return cells;
}

PS. Code is a rough sketch, not actual implementation. Also, this code takes into consideration that the parent cell must be killed (and garbage collected) so that the 2 identical cells can have right of way.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • Isn't that having cell 1 create a seperate cell 2 and cell 3, meaning the system now has 3 cells? For mytosis you would return Cell[] cells = {this, this.clone()}; – Martin Milan Mar 19 '11 at 00:06
  • Aaah, thanks, I was looking at it in a way where the parent cell split itself into 2 identical cells. My code assumes that the parent cell would we "wiped off" and Garbage collected. – Buhake Sindi Mar 19 '11 at 00:12
  • +1 for encapsulation. The question raised by @Martin Milan highlights the need to know what is being modeled. E.g., do cells accumulate random mutations? – trashgod Mar 19 '11 at 00:32
  • During mitosis there is no random mutations. It's just the replication of 1 cell of a human body with all the 23 pairs of chromosomes in it in to two identical cells. So assuming an organism has 1 cell, after it undergoes mitosis, it would have 2 cells and not 3 cells. – mkab Mar 19 '11 at 00:36
  • @mkab: Mitosis lacks perfect fidelity; random mutations _do_ accumulate. Eukaryotic cells have several mechanism for repairing (apparently) random defects, such as those caused by background radiation. You may mean to contrast mitosis with the genetic diversity engendered by [meiosis](http://en.wikipedia.org/wiki/Meiosis). – trashgod Mar 19 '11 at 00:52
  • @trashgod, I think this is going too far! In AI, there's not random mutation on Genetic Programming (unless there's a paper I never read about). – Buhake Sindi Mar 19 '11 at 00:53
  • @The Elite Gentleman: _Mea culpa_, I got a little carried away. :-) – trashgod Mar 19 '11 at 01:01
  • @trashgod I see. But for my java project I'll just consider that mitosis produce 2 identical cells. My project isn't really deep genetic programming. It's just that my teacher gave me that in order to learn on how to manipulate classes, java methods, abstract classes etc.. – mkab Mar 19 '11 at 01:02
  • @mkab: It's a good exercise. It may help to know that it's not always easy to draw the [line](http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/4832170f4c4f6098) between world and model. – trashgod Mar 19 '11 at 01:11
  • I stand corrected, there are random mutation in GA but mitosis (in AI) generally produces 2 identical cells. Mutations occurs later. – Buhake Sindi Mar 19 '11 at 01:14
  • @trashgod: Yeah. I'm starting to feel that now. I find it hard not thinking too much about real life object when modelling them especially that I was even taught Object programming with reference to real world objects. By the way interesting link there. :) – mkab Mar 19 '11 at 01:23
0

This turns out to be something you have to do in real Java programs---check out the Cloneable interface.

Jacob
  • 1,516
  • 9
  • 7
  • Actually that's what I'm even using to clone my cells. But it's not the cloning of the cells that's my problem, it's what the method "mitosis" should return. As long as mitosis(biologically) is concerned, two identical cells are produced. But my method is returning just one cell instead of 2. So if i want to test it, I have for example `Cell c = new Cell(); Cell d = new Cell(); Cell e = new Cell(); try{ d = c.mitosis(); e = c.mitosis();} catch(CloneNotSupportedException e){}` – mkab Mar 19 '11 at 00:00
  • It's been a while since I took biology, but you can certainly think of mitosis as involving a "parent" and "child" cell. e.g. `Cell c = new Cell; Cell d = c.mitosis()`. Look: two cells! – Jacob Mar 19 '11 at 00:08