Class SequenceSelectionWithDocuments
- java.lang.Object
-
- com.biomatters.geneious.publicapi.plugin.SequenceSelectionWithDocuments
-
- All Implemented Interfaces:
XMLSerializable
,XMLSerializable.OldVersionCompatible
public class SequenceSelectionWithDocuments extends java.lang.Object implements XMLSerializable, XMLSerializable.OldVersionCompatible
This class associates aSequenceSelection
with theList
ofAnnotatedPluginDocument
that it is defined on.- Since:
- API 4.40 (Geneious 5.4.0)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SequenceSelectionWithDocuments.DocumentsInvalidException
Thrown to indicate that a group of documents is not valid to have a SequenceSelectionWithDocuments upon.static class
SequenceSelectionWithDocuments.ExtractionStrategy
Instances of this allow calling code to fine tune howgetSequences()
returns SequenceDocuments from its selection and documents.static class
SequenceSelectionWithDocuments.SelectedDocumentsModifiedException
Thrown when the selected documents are modified between the moment when the SequenceSelectionWithDocuments is constructed and the documents within it are accessed.-
Nested classes/interfaces inherited from interface com.biomatters.geneious.publicapi.documents.XMLSerializable
XMLSerializable.OldVersionCompatible, XMLSerializable.VersionSupportType
-
-
Field Summary
Fields Modifier and Type Field Description static SequenceSelectionWithDocuments.ExtractionStrategy
DEFAULT_EXTRACTION_STRATEGY
The default ExtractionStrategy used to return sequences.static SequenceSelectionWithDocuments.ExtractionStrategy
TRIMMING_EXTRACTION_STRATEGY
An ExtractionStrategy that does whatSequenceSelectionWithDocuments.DefaultExtractionStrategy
does, but additionally performs trimming on the sequences, such that any leading or trailing trim annotations are respected and these portions of the sequence are left out of the extraction.-
Fields inherited from interface com.biomatters.geneious.publicapi.documents.XMLSerializable
ROOT_ELEMENT_NAME
-
-
Constructor Summary
Constructors Constructor Description SequenceSelectionWithDocuments(java.util.List<AnnotatedPluginDocument> documents)
SequenceSelectionWithDocuments(java.util.List<AnnotatedPluginDocument> documents, SequenceSelection selection)
SequenceSelectionWithDocuments(java.util.List<AnnotatedPluginDocument> documents, SequenceSelection selection, SequenceSelectionWithDocuments.ExtractionStrategy extractionStrategy)
Constructs an SequenceSelectionWithDocuments for the given documents and given SelectionSelection on those documents.SequenceSelectionWithDocuments(java.util.List<AnnotatedPluginDocument> documents, SequenceSelectionWithDocuments.ExtractionStrategy extractionStrategy)
Constructor which "selects all" from the given documents.
It infers theSequenceType
andSequenceSelection.SequenceDocumentType
from the documents.
If the documents contain a mixture of nucleotide and amino acid sequences, this will throw an DocumentsInvalidException.SequenceSelectionWithDocuments(org.jdom.Element element)
Construct a SequenceSelectionWithDocuments from the results oftoXML()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fromXML(org.jdom.Element element)
Restore the object from the JDOM Element returned byXMLSerializable.toXML()
.AnnotatedPluginDocument
getContainingDocument(int index)
java.util.List<AnnotatedPluginDocument>
getDocuments()
java.util.List<SequenceAlignmentDocument.ReferencedSequence>
getReferenceSequences()
If everything in the documents in this SequenceSelection is selected, return a list of the ReferencedSequences representing the AnnotatedPluginDocument which each sequence in the selection appears in and its index therein.java.util.List<SequenceDocument>
getSequences()
Returns the sequences referred to by this object's SequenceSelection for its List of AnnotatedPluginDocument, as a List of SequenceDocument, applying the given ExtractionStrategy in order to extract sequences.SequenceSelection
getSequenceSelection()
Geneious.MajorVersion
getVersionSupport(XMLSerializable.VersionSupportType versionType)
Gets either the latest version this class can serialize to viaXMLSerializable.OldVersionCompatible.toXML(Geneious.MajorVersion, ProgressListener)
or the most recent version in which the XML returned fromXMLSerializable.OldVersionCompatible.toXML(Geneious.MajorVersion, ProgressListener)
last changed.void
setDoRevisionNumberChecks(boolean doRevisionNumberChecks)
WhengetSequences()
is called, checks are made to make sure that the revision of the document hasn't changed and will throw aSequenceSelectionWithDocuments.SelectedDocumentsModifiedException
if so.SequenceSelectionWithDocuments
subSelection(int... sequenceIndices)
Given a set of indices specifying some of this class's SequenceSelection's intervals, determines which AnnotatedPluginDocuments are referenced by those SelectionIntervals, and groups them together into a List.org.jdom.Element
toXML()
Convert object to a JDOM element.org.jdom.Element
toXML(Geneious.MajorVersion majorVersion, jebl.util.ProgressListener progressListener)
Serializes this class to XML format, potentially to a format readable by an earlier version of Geneious.
-
-
-
Field Detail
-
DEFAULT_EXTRACTION_STRATEGY
public static final SequenceSelectionWithDocuments.ExtractionStrategy DEFAULT_EXTRACTION_STRATEGY
The default ExtractionStrategy used to return sequences.- Since:
- API 4.600 (Geneious 6.0.0)
-
TRIMMING_EXTRACTION_STRATEGY
public static final SequenceSelectionWithDocuments.ExtractionStrategy TRIMMING_EXTRACTION_STRATEGY
An ExtractionStrategy that does whatSequenceSelectionWithDocuments.DefaultExtractionStrategy
does, but additionally performs trimming on the sequences, such that any leading or trailing trim annotations are respected and these portions of the sequence are left out of the extraction.- Since:
- API 4.600 (Geneious 6.0.0)
-
-
Constructor Detail
-
SequenceSelectionWithDocuments
public SequenceSelectionWithDocuments(java.util.List<AnnotatedPluginDocument> documents, SequenceSelection selection) throws com.biomatters.geneious.publicapi.plugin.DocumentOperationException
InvokesSequenceSelectionWithDocuments(java.util.List, SequenceSelection, com.biomatters.geneious.publicapi.plugin.SequenceSelectionWithDocuments.ExtractionStrategy)
withDEFAULT_EXTRACTION_STRATEGY
.- Parameters:
documents
- the List of Documents for which this SequenceSelectionWithDocuments's SequenceSelection is defined on. Must not be null, but can be an empty list.selection
- the SequenceSelection to group together with its List of Documents. Must not be null.- Throws:
com.biomatters.geneious.publicapi.plugin.DocumentOperationException
- if there was an error loading the PluginDocument from one of documents
-
SequenceSelectionWithDocuments
public SequenceSelectionWithDocuments(java.util.List<AnnotatedPluginDocument> documents, SequenceSelection selection, SequenceSelectionWithDocuments.ExtractionStrategy extractionStrategy) throws com.biomatters.geneious.publicapi.plugin.DocumentOperationException
Constructs an SequenceSelectionWithDocuments for the given documents and given SelectionSelection on those documents.- Parameters:
documents
- the List of Documents for which this SequenceSelectionWithDocuments's SequenceSelection is defined on. Must not be null, and must not contain nulls, but can be an empty list.selection
- the SequenceSelection to group together with its List of Documents. Must not be null.extractionStrategy
- theExtractionStrategy
which determines how this SequenceSelectionWithDocuments will return sequences whengetSequences()
is called. At present, there are two choices:DEFAULT_EXTRACTION_STRATEGY
andTRIMMING_EXTRACTION_STRATEGY
.- Throws:
com.biomatters.geneious.publicapi.plugin.DocumentOperationException
- if there was an error loading the PluginDocument from one of documents- Since:
- API 4.600 (Geneious 6.0.0)
-
SequenceSelectionWithDocuments
public SequenceSelectionWithDocuments(java.util.List<AnnotatedPluginDocument> documents) throws com.biomatters.geneious.publicapi.plugin.DocumentOperationException
InvokesSequenceSelectionWithDocuments(java.util.List, ExtractionStrategy)
withDEFAULT_EXTRACTION_STRATEGY
.- Parameters:
documents
- the List of Documents for which this SequenceSelectionWithDocuments's SequenceSelection is defined on. Must not be null, but can be an empty list.- Throws:
com.biomatters.geneious.publicapi.plugin.DocumentOperationException
- if there was an error loading the PluginDocument from one of documentsjava.lang.IllegalArgumentException
- if documents is empty, or if they're not valid to create a selection over.
-
SequenceSelectionWithDocuments
public SequenceSelectionWithDocuments(java.util.List<AnnotatedPluginDocument> documents, SequenceSelectionWithDocuments.ExtractionStrategy extractionStrategy) throws com.biomatters.geneious.publicapi.plugin.DocumentOperationException
Constructor which "selects all" from the given documents.
It infers theSequenceType
andSequenceSelection.SequenceDocumentType
from the documents.
If the documents contain a mixture of nucleotide and amino acid sequences, this will throw an DocumentsInvalidException. If the documents areCombinedAlignmentAndSequenceDocument
this will return a selection for the sequences instead of the alignments. If there are a mixture of documents of different types (sequence vs alignment) this will throw an IllegalArgumentException.- Parameters:
documents
- the List of Documents for which this SequenceSelectionWithDocuments's SequenceSelection is defined on. Must not be null, but can be an empty list.extractionStrategy
- theExtractionStrategy
to use when getting sequences.- Throws:
com.biomatters.geneious.publicapi.plugin.DocumentOperationException
- if there was an error loading the PluginDocument from one of documentsSequenceSelectionWithDocuments.DocumentsInvalidException
- if there is a mixture of nucleotide and amino acid sequencesjava.lang.IllegalArgumentException
- if documents is empty, or if the documents are not valid to create a selection over.- Since:
- API 4.600 (Geneious 6.0.0)
-
SequenceSelectionWithDocuments
public SequenceSelectionWithDocuments(org.jdom.Element element) throws XMLSerializationException, com.biomatters.geneious.publicapi.plugin.DocumentOperationException
Construct a SequenceSelectionWithDocuments from the results oftoXML()
- Parameters:
element
- an element returned fromtoXML()
- Throws:
XMLSerializationException
- if XML does not conform to our unpublished specificationcom.biomatters.geneious.publicapi.plugin.DocumentOperationException
- if one occurred when getting a PluginDocument from one of the AnnotatedPluginDocument taken from the deserialized list.- Since:
- API 4.40 (Geneious 5.4.0)
-
-
Method Detail
-
setDoRevisionNumberChecks
public void setDoRevisionNumberChecks(boolean doRevisionNumberChecks)
WhengetSequences()
is called, checks are made to make sure that the revision of the document hasn't changed and will throw aSequenceSelectionWithDocuments.SelectedDocumentsModifiedException
if so. However in some cases you may want to disable this behaviour and manually handle the revision numbers.
The associated field will not get serialized to XML.- Parameters:
doRevisionNumberChecks
- true to throw an exception if the revision number has changed since the SequenceSelection was created whengetSequences()
or most other methods in this class are accessed, false otherwise- Since:
- API 4.703 (Geneious 7.0.3)
-
getDocuments
public java.util.List<AnnotatedPluginDocument> getDocuments()
- Returns:
- the documents for which the SequenceSelection returned by
getSequenceSelection()
is defined on.
-
getReferenceSequences
public java.util.List<SequenceAlignmentDocument.ReferencedSequence> getReferenceSequences()
If everything in the documents in this SequenceSelection is selected, return a list of the ReferencedSequences representing the AnnotatedPluginDocument which each sequence in the selection appears in and its index therein. If this was a partial selection, return null.- Returns:
- referencedSequences representing the AnnotatedPluginDocument which each sequence in the selection appears in and its index therein
- Since:
- API 4.700 (Geneious 7.0.0)
-
getSequenceSelection
public SequenceSelection getSequenceSelection()
- Returns:
- the SequenceSelection that this SequenceSelectionWithDocuments object wraps. will never be null.
-
getContainingDocument
public AnnotatedPluginDocument getContainingDocument(int index)
- Parameters:
index
- the index of the sequence in question, in the List of SelectionInterval returned bygetSequenceSelection()
.getIntervals(true)
- Returns:
- the AnnotatedPluginDocument referred to by the SelectionInterval at intervalIndex.
- Throws:
SequenceSelection.SequenceIndex.SelectionWrongForDocumentsException
- if the selection index doesn't correspond to these documents.
-
getSequences
public java.util.List<SequenceDocument> getSequences()
Returns the sequences referred to by this object's SequenceSelection for its List of AnnotatedPluginDocument, as a List of SequenceDocument, applying the given ExtractionStrategy in order to extract sequences. May return 0-length sequences. The length of this list will be equal to the sum of the number of sequences in each interval
NOTE: since API 4.600 (Geneious 6.0.0), this method's behaviour will depend on theExtractionStrategy
passed in as an argument to this class's constructor. SequenceSelectionWithDocuments serialized before this time will be deserialized withDefaultExtractionStrategy
, and their behaviour will remain unchanged.- Returns:
- the sequences referred to by this object's SequenceSelection for its List of AnnotatedPluginDocument, as a List of SequenceDocument
- See Also:
getSequences()
-
subSelection
public SequenceSelectionWithDocuments subSelection(int... sequenceIndices)
Given a set of indices specifying some of this class's SequenceSelection's intervals, determines which AnnotatedPluginDocuments are referenced by those SelectionIntervals, and groups them together into a List. A new SequenceSelection containing only the given SelectionInterval objects is created, which is defined on the new List of referenced AnnotatedPluginDocument. The List of AnnotatedPluginDocument and the SelectionInterval are wrapped together in a new SequenceSelectionWithDocuments and returned.- Parameters:
sequenceIndices
- a list of the indices of the SequenceIntervals in this object's SequenceSelection, to create a new SelectionSelection for. This must be a subset of the ones returned bygetSequenceSelection()
andSequenceSelection.getIntervals()
- Returns:
- the resulting SequenceSelectionWithDocuments
-
toXML
public org.jdom.Element toXML()
Description copied from interface:XMLSerializable
Convert object to a JDOM element. The representation should be complete so thatXMLSerializable.fromXML(org.jdom.Element)
can completely restore the object's representation. It is recommended that the returned element useXMLSerializable.ROOT_ELEMENT_NAME
as its name, in which case it must not define an attribute called "type". In this case, fromXML, will be called with an element whose name may differ from the element return from this function. This recommendation allows a more compact representation of the XML can be stored. This method generally should not be called directly. Instead, you should usually callXMLSerializer.classToXML(String, XMLSerializable)
which calls this method internally. PluginDocument implementations of this method may choose to throw anXMLSerializationException
, enclosed in aRuntimeException
.- Specified by:
toXML
in interfaceXMLSerializable
- Returns:
- some XML for use with
SequenceSelectionWithDocuments(org.jdom.Element)
- Since:
- API 4.40 (Geneious 5.4.0)
-
getVersionSupport
public Geneious.MajorVersion getVersionSupport(XMLSerializable.VersionSupportType versionType)
Description copied from interface:XMLSerializable.OldVersionCompatible
Gets either the latest version this class can serialize to viaXMLSerializable.OldVersionCompatible.toXML(Geneious.MajorVersion, ProgressListener)
or the most recent version in which the XML returned fromXMLSerializable.OldVersionCompatible.toXML(Geneious.MajorVersion, ProgressListener)
last changed. Example implementation:switch (versionType) { case FormatLastExtended: //added a new tag to xml in 10.0 that can be safely ignored by older versions return Geneious.MajorVersion.Version10_0; case FormatLastChanged: //renamed a tag in 9.1 meaning that older versions can no longer read the xml from 9.1 return Geneious.MajorVersion.Version9_1; case OldestVersionSerializableTo: //this document class can export xml that is compatible with 9.0 return Geneious.MajorVersion.Version9_0; default: throw new IllegalArgumentException("Unrecognized VersionSupportType"); }
- Specified by:
getVersionSupport
in interfaceXMLSerializable.OldVersionCompatible
- Parameters:
versionType
- specifies which version property to return- Returns:
- the major version of Geneious corresponding to the versionType for this classes toXML method.
-
toXML
public org.jdom.Element toXML(Geneious.MajorVersion majorVersion, jebl.util.ProgressListener progressListener)
Description copied from interface:XMLSerializable.OldVersionCompatible
Serializes this class to XML format, potentially to a format readable by an earlier version of Geneious. It is acceptable for the XML to include unnecessary tags that will be ignored by the earlier version. For example if the implementation has only extended the XML since the earlier version, then the XML returned may be identical to the XML returned for the current version. SeeXMLSerializable.toXML()
for a more detailed description of what it means to serialize to XML. All classes that implement this method must also implement XMLSerializable.toXML() and should delegate back to this method using Geneious.getMajorVersion() and ProgressListener.EMPTY as parameters.- Specified by:
toXML
in interfaceXMLSerializable.OldVersionCompatible
- Parameters:
majorVersion
- the major version of Geneious to serialize to XML for. For example "6.0" but not "6.0.0". This must be a version returned greater or equal to a version returned fromgetVersionSupport
(VersionSupportType.OldestVersionSerializableTo
) and must never be greater than the current version (Geneious.getMajorVersion())progressListener
- for reporting progress and cancelling- Returns:
- object encoded as a JDOM element
-
fromXML
public void fromXML(org.jdom.Element element) throws XMLSerializationException
Description copied from interface:XMLSerializable
Restore the object from the JDOM Element returned byXMLSerializable.toXML()
. This method generally should not be called directly. Instead, you should usually callXMLSerializer.classFromXML(org.jdom.Element)
orXMLSerializer.classFromXML(org.jdom.Element, Class)
which calls this method internally. It is optional to implement this method. Instead of implementing an empty constructor and implementing this method properly, the implementation may instead throw an UnsupportedOperationException and implement a constructor that takes a singleElement
as a parameter. This allows for cleaner code such as support for final fields in the XMLSerializable class. The element parameter should not be modified since it may be reused. If you need a modified version of it, take a copy withElement.clone()
.- Specified by:
fromXML
in interfaceXMLSerializable
- Parameters:
element
- representation from a previous call toXMLSerializable.toXML()
- Throws:
XMLSerializationException
- if the Element can't be converted into this type of object
-
-