de.jstacs.data.bioJava
Class BioJavaAdapter

java.lang.Object
  extended by de.jstacs.data.bioJava.BioJavaAdapter

public class BioJavaAdapter
extends Object

This class provides static methods to convert BioJava datatypes ( SequenceIterator, Sequence) to Samples and vice versa.

Here are two small examples how to create a RichSequenceIterator that can be used to create a Sample.

GenbankRichSequenceDB db = new GenbankRichSequenceDB();
org.biojava.bio.seq.Sequence seq = db.getSequence( id );
RichSequenceIterator iter = new RichSequence.IOTools.SingleRichSeqIterator(seq);

or

RichSequenceIterator iter = RichSequence.IOTools.readFile( new File( fName ), null );

Author:
Jens Keilwagen, Jan Grau

Constructor Summary
BioJavaAdapter()
           
 
Method Summary
static SequenceIterator sampleToSequenceIterator(Sample sample, boolean flat)
          Creates a SequenceIterator from the Sample sample preserving as much annotation as possible.
static Sample sequenceIteratorToSample(SequenceIterator it, FeatureFilter filter)
          This method creates a new Sample from a SequenceIterator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BioJavaAdapter

public BioJavaAdapter()
Method Detail

sequenceIteratorToSample

public static Sample sequenceIteratorToSample(SequenceIterator it,
                                              FeatureFilter filter)
                                       throws Exception
This method creates a new Sample from a SequenceIterator. In cases where BioJava does return Sequences instead of a SequenceIterator, you can use a SimpleSequenceIterator to wrap them up.

Parameters:
it - the sequence iterator
filter - null or an arbitrary feature filter that determines which features will be adopted
Returns:
the Sequences in it converted to a Sample
Throws:
Exception - if something went wrong

sampleToSequenceIterator

public static SequenceIterator sampleToSequenceIterator(Sample sample,
                                                        boolean flat)
                                                 throws WrongAlphabetException,
                                                        BioException
Creates a SequenceIterator from the Sample sample preserving as much annotation as possible. This method works only for discrete alphabets.

Parameters:
sample - the Sample
flat - indicates if the features should be flattened, this may be necessary to preserve all features, because some data formats do not support hierarchical features
Returns:
the corresponding SequenceIterator
Throws:
WrongAlphabetException - if the alphabet of the Sample is not discrete
BioException - if forwarded from BioJava