[Biojava-l] how to get properties of a Feature from a GenBank file

Martin Jones martin.jones at ed.ac.uk
Thu Mar 27 13:45:50 UTC 2008


Hi,

I'm just getting started with BioJava so this may be a simple
question.  I'm reading a RichSequence from a GenBank file and want to
get the gene name of each CDS feature.  The following code gets hold
of the features I'm interested in

for (Object o : mySeq.getFeatureSet()){
      RichFeature f = (RichFeature) o;
      if (f.getType().equals("CDS")){
            //get gene name here
      }
}

but I'm not sure how best to get the gene name.  The following seems to work:

for (Object o2 : f.getNoteSet()){
     Note n = (Note) o2;
     if (n.getTerm().getName().equals("gene")){
                 System.out.println("gene name is " + n.getValue());
     }
}

but seems overly verbose - ideally I'd like to be able to pass the
Feature to another part of my program,  but writing the above whenever
I want to get the name seems like overkill.  Is there a shorter way -
something along the lines of

String name = f.getNoteByName("gene").getValue();

Thanks in advance for any help.

PS one more question - is there a reason why e.g.  getNoteSet returns
a Set rather than a Set<Feature>, which makes it necessary to do all
the type casts?

Thanks,

Martin



More information about the Biojava-l mailing list