如何利用BioJava创建一个特征feature

评论1,159

在Biojava中,特征(Feature)有点象具有位置(Location)属性的注释(Annotation)。各种类型的特征必须都实现特征接口。所有的特征实现都包含一个叫做模版(Template)的内类。模版内类定义了创建特征必需的最小信息。当这个模版被当作参数传递给一个实现了特征拥有者(FeatureHolder)接口的实例的createFeature()方法时,特征才被创建。

序列(Sequence)是特征拥有者(FeatureHolder)的子接口。所以序列能够拥有特征。注意:标志链(SymbolList)不能拥有特征。有趣的是,特征也是特征拥有者的子接口。所以特征能够拥有子特征形成一种嵌套层次。这种设计能够让基因特征拥有外显子特征,外显子特征拥有snp特征等等。特征拥有一个内置的安全机制能够避免自我包含。特征模版可以重新创建,也能从已有的特征中拷贝。下面的例子使用了两种方法。

[code lang="java"]
import org.biojava.bio.*;
import org.biojava.bio.seq.*;
import org.biojava.bio.symbol.*;
import org.biojava.util.*;
public class MakeFeature {
public static void main(String[] args){
// 从链状特征中得到一个特征模版
strandedFeature.Template templ = new StrandedFeature.Template();
// 填充模版
templ.annotation = Annotation.EMPTY_ANNOTATION;
templ.location = new RangeLocation(3,6);
templ.strand = StrandedFeature.POSITIVE;
templ.type = "interesting motif";

try {
// 拥有这个特征的序列
Sequence seq = DNATools.createDNASequence("atgcgcttaag","seq1");
System.out.println(seq.getName()+" contains "+seq.countFeatures()+" features");

System.out.println("adding new feature...");

// 创建一个序列特征
Feature f = seq.createFeature(templ);
System.out.println(seq.getName()+" contains "+seq.countFeatures()+" features");

// 创建一个和序列特征的模版一致的模版
templ =(StrandedFeature.Template)f.makeTemplate();

// 重新设置特征位置和类型
templ.location = new PointLocation(4);
templ.type = "point mutation";

System.out.println("adding nested feature...");

// 将新特征变成旧特征的嵌套特征
f.createFeature(templ);

// 注意countFeature()方法如何仅仅计算顶级(top level)特征
System.out.println(seq.getName()+" contains "+seq.countFeatures()+" features ");
System.out.println(f.getSource()+" contains "+seq.countFeatures()+" features ");
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
[/code]

发表评论

匿名网友