[Biojava-dev] Filter features of a sequence from SequenceDB

Thomas Down thomas at derkholm.net
Wed May 28 10:23:31 EDT 2003


Once upon a time, Y D Sun wrote:
> Dear all,
> 
> I create a sequence database and add EMBL sequences to it using
> BioSQLSequenceDB() and addSequence().
> 
> Then, I read a sequence from the database using getSequence() and filter
> its features like CDS using the code:
> 
>     //make a Filter for "CDS" types
>     FeatureFilter ff = new FeatureFilter.ByType("CDS");
> 
>     //get the filtered Features
>     FeatureHolder fh = seq.filter(ff);
> 
>     //iterate over the Features in fh
>     for (Iterator i = fh.features(); i.hasNext(); ) {
>       Feature f = (Feature)i.next();
>       String s = f.getAnnotation().toString();
> 	System.out.println(s);
>     }
> 
> The output is incorrect:
> 
> org.biojava.bio.seq.db.biosql.BioSQLFeatureAnnotation at 1f2ee1
> org.biojava.bio.seq.db.biosql.BioSQLFeatureAnnotation at 3ecfff
> org.biojava.bio.seq.db.biosql.BioSQLFeatureAnnotation at c99159
> org.biojava.bio.seq.db.biosql.BioSQLFeatureAnnotation at 65a77f
> org.biojava.bio.seq.db.biosql.BioSQLFeatureAnnotation at d7ad1c
> ... ...
> 
> If applying the code to a sequence read from a EMBL file using
> readEmbl(), it can get CDS feature rightly. So, I think this problem may
> be caused by the format of sequence. I haven't specified the format when
> creating DB, addSequence and getSequence. 
> 
> I want to know the correct method to get the feature of a sequence from
> SequenceDB, how to specify the format.

As a general rule, you shouldn't rely on toString() methods
except for debugging.  If you want to write code which prints
out all the properties in an Annotation, best to do it explicitly:

    Annotation anno = ...;
    System.out.print('[');
    for (Iterator i = anno.keys(); i.hasNext(); ) {
        Object key = i.next();
        Object value = anno.getProperty(key);
        System.out.print(key + "->" + value);
        if (i.hasNext()) {
            System.out.print(", ");
        }
    }
    System.out.println(']');

That said, BioSQLFeatureAnnotation probably *ought* to have
a nicer toString method...  I'll add one next time I'm in
that bit of code.

     Thomas.


More information about the biojava-dev mailing list