>>>>> "Robert" == Robert Stones <[EMAIL PROTECTED]> writes:

    Robert> Could anyone give me an example where you can remove
    Robert> features from a Sequence Object.

Try something like

import java.io.*;
import java.util.*;

import org.biojava.bio.*;
import org.biojava.bio.seq.*;
import org.biojava.bio.seq.io.*;

public class RemoveFeatures
{
    public static void main(String [] argv) throws Exception
    {
        BufferedReader br = new BufferedReader(new FileReader(argv[0]));

        SequenceIterator seqI = SeqIOTools.readEmbl(br);

        while (seqI.hasNext())
        {
            Sequence seq = seqI.nextSequence();
            FeatureHolder fh =
                seq.filter(new FeatureFilter.StrandFilter(StrandedFeature.POSITIVE));

            for (Iterator i = fh.features(); i.hasNext();)
            {
                seq.removeFeature((Feature) i.next());
            }

            SeqIOTools.writeEmbl(System.out, seq);
        }
    }
}

Run this on e.g. demos/files/AL121903.embl and it will only print the
complement strand features (compiled & tested here). Filtering creates
a new holder and eliminates the concurrent modification error as Mark
described.

In general you will most likely be better off using a FeatureFilter
like this rather than individually checking Feature types (in your
previous example you need FeatureFilter.ByType) because wou will be
more likely to benefit from any filtering optimizations present in the
implementation of Sequence which you are using.

hth, Keith

-- 

- Keith James <[EMAIL PROTECTED]> bioinformatics programming support -
- Pathogen Sequencing Unit, The Wellcome Trust Sanger Institute, UK -

_______________________________________________
Biojava-l mailing list  -  [EMAIL PROTECTED]
http://biojava.org/mailman/listinfo/biojava-l

Reply via email to