我对Java OOP概念相当陌生。在java中实现一些关于遗传学的东西时,我遇到了一些问题。这是场景。Java OOP概念问题
人类细胞含有23对染色体。每对中的每个染色体都有数千个基因。基因的每个拷贝称为等位基因。这些等位基因决定了人类的不同特征(眼睛颜色,身高,头发颜色,遗传病等)。等位基因可以是显性或隐性的。
显性等位基因总是在其携带者的基因组中表达。然而,如果一个等位基因的信息在同一基因的显性等位基因存在时不表达,那么它就是一个隐性等位基因。基因隐性等位基因的特殊性在于它可以存在于基因组中,并在几代中传播而没有在其携带者的表型中表达。如果没有显性等位基因,则该基因的两个拷贝具有相同的隐性等位基因(纯合隐性),然后表达隐性特征。
所以现在,在一对孩子细胞的染色体上,一个染色体来自母亲,另一个染色体来自父亲。因此,让我们说在父亲染色体的位置1上包含负责眼睛颜色的基因的等位基因(显性或隐性),在母体染色体的相同位置上必须包含同一基因的另一个等位基因(显性或隐性)。 那么我该如何表示这些类的等位基因,基因是否正确?这是我到目前为止的内容
Allele.java
/**
*
*/
package project_try;
/**
* @author mkab
*
*/
public class Allele {
private String trait;
private int type;
public Allele(String trait, int type) {
this.trait = trait;
this.type = type;
}
public boolean equals(Allele a){
if(this.getTrait().equals(a.getTrait()) && this.getType()==a.getType())
return true;
return false;
}
/**
* @return the trait
*/
public String getTrait() {
return trait;
}
/**
* @param trait the trait to set
*/
public void setTrait(String trait) {
this.trait = trait;
}
/**
* @param type the type to set
*/
public void setType(int type) {
this.type = type;
}
/**
* @return the type either recessive(0) or dominant(1)
*/
public int getType() {
return type;
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Allele [trait=" + trait + ", type=" +
(this.getType()==0?"recessive":"dominant")+ "]";
}
}
Gene.java
/**
*
*/
package project_try;
import java.util.Random;
/**
* @author mkab
*
*/
public class Gene implements Cloneable {
private Allele allele;
public Gene(){
super();
}
public Gene(Allele allele){
super();
this.allele = allele;
}
/**
* Randomly selects a trait from trait1 or trait2 and returns a new Gene with that trait
* @param trait1
* @param trait2
*
* @return a new Gene
*/
public Gene randomAllele(Allele trait1, Allele trait2){
Allele allele = null;
Random rand = new Random();
int i = rand.nextInt(2);// generate between 0 and 2: only 2 possibilities: 0 or 1
switch(i){
case 0:
allele = trait1;
break;
case 1:
allele = trait2;
break;
}
return new Gene(allele);
}
/**
* Clones a gene
*/
public Gene clone() throws CloneNotSupportedException{
Gene g;
g = (Gene) super.clone();
return g;
}
public boolean equals(Gene g){
if(this.getAllele().equals(g.getAllele()) &&
this.getAlleleType() == g.getAlleleType())
return true;
return false;
}
/**
* @param allele the allele to set
*/
public void setAllele(Allele allele) {
this.allele = allele;
}
/**
*
* @return - the allele
*/
public Allele getAllele() {
return allele;
}
/**
*
* @return the trait of the gene or allele
*/
public String getAlleleTrait(){
return allele.getTrait();
}
/**
*
* @return allele type. Either recessive or dominant
*/
public int getAlleleType(){
return allele.getType();
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Gene [" + allele +"]";
}
}
我怎样才能代表类染色体?我正在考虑使用基因类型的数组列表。但使用这个问题是,我不能定义例如阵列的第一个位置应该用于眼睛的颜色,第二个位置的高度等。 任何建议吗?由于
'染色体'应该是接口IMO – dantuch 2011-04-02 12:48:50
这就是我在想什么。 “染色体”应该是一个接口还是一个抽象类。但问题是染色体应该包含基因。使用上述方法,我将染色体含有染色体。 – mkab 2011-04-02 13:14:30