T
- the type of sequence elements (tokens) used by the underlying alignment model objectpublic class AlignmentModelDataAdapter<T> extends info.bioinfweb.jphyloio.dataadapters.implementations.NoCharDefsNoSetsMatrixDataAdapter implements info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter
AlignmentModel
to an implementation of JPhyloIOEventWriter
.
Whether the sequence start events link an associated OTU or not can be defined by the constructor parameter
linkOTUs
. If OTUs shall be linked, it will be assumed that such an OTU will have an ID consisting of the
concatenation of ReadWriteConstants.DEFAULT_OTU_ID_PREFIX
and the sequence ID used in the underlying
AlignmentModel
. If a more complex OTU linking is necessary, the method #getLinkedOTUID(int)
can
be overwritten accordingly.
This implementation does not write any metadata associated with sequences or the alignment as a whole. If such data
shall be written the methods #writeMetadata(JPhyloIOEventReceiver)
or
writeSequenceMetadata(JPhyloIOEventReceiver, String)
should be overwritten accordingly. If character
definitions or sets shall be written, the according methods need to be overwritten as well.
Constructor and Description |
---|
AlignmentModelDataAdapter(java.lang.String idPrefix,
info.bioinfweb.jphyloio.events.LinkedLabeledIDEvent startEvent,
AlignmentModel<T> model,
boolean linkOTUs)
Creates a new instance of this class.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsLongTokens(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters) |
long |
getColumnCount(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters)
Returns the number of columns in the underlying
AlignmentModel instance if all sequences have an equal length. |
java.lang.String |
getIDPrefix()
Returns the ID prefix used by this instance.
|
protected java.lang.String |
getLinkedOTUID(java.lang.String sequenceID)
Returns the ID of the JPhyloIO OTU that shall be linked with the specified sequence.
|
long |
getSequenceCount(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters) |
java.util.Iterator<java.lang.String> |
getSequenceIDIterator(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters) |
long |
getSequenceLength(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters,
java.lang.String sequenceID) |
info.bioinfweb.jphyloio.events.LinkedLabeledIDEvent |
getSequenceStartEvent(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters,
java.lang.String sequenceID) |
info.bioinfweb.jphyloio.events.LinkedLabeledIDEvent |
getStartEvent(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters) |
info.bioinfweb.jphyloio.dataadapters.ObjectListDataAdapter<info.bioinfweb.jphyloio.events.TokenSetDefinitionEvent> |
getTokenSets(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters) |
boolean |
isLinkOTUs() |
protected java.lang.String |
jPhyloIOByModelSequenceID(java.lang.String modelSequenceID)
Returns the JPhyloIO sequence ID to be used for the specified sequence ID used in the underlying model.
|
protected java.lang.String |
modelByJPhyloIOSequenceID(java.lang.String jPhyloIOsequenceID)
Returns the LibrAlign model sequence ID associated with the specified JPhyloIO sequence ID.
|
protected void |
writeSequenceMetadata(info.bioinfweb.jphyloio.dataadapters.JPhyloIOEventReceiver receiver,
java.lang.String sequenceID)
Can be used to write metadata associated with a sequence.
|
void |
writeSequencePartContentData(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters,
info.bioinfweb.jphyloio.dataadapters.JPhyloIOEventReceiver receiver,
java.lang.String sequenceID,
long startColumn,
long endColumn) |
getCharacterDefinitions, getCharacterSets, getSequenceSets
writeMetadata
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public AlignmentModelDataAdapter(java.lang.String idPrefix, info.bioinfweb.jphyloio.events.LinkedLabeledIDEvent startEvent, AlignmentModel<T> model, boolean linkOTUs)
idPrefix
- the ID prefix to be used for all generated JPhyloIO IDs of sequences and token sets.
(Must be a valid NCName
or an empty string. See getIDPrefix()
for further details.)startEvent
- the JPhyloIO alignment start event to be usedmodel
- the LibrAlign alignment model which shall be the source for this adapterlinkOTUs
- Specify true
here, if each sequence shall link an OTU or false
otherwise.
(See #getLinkedOTUID(int)
for details on how OTU IDs are generated.)public java.lang.String getIDPrefix()
The prefix is added to LibrAlign sequence IDs to create JPhyloIO sequences IDs from them. It may be an empty string, otherwise it needs to be a valid NCName. If multiple instance of this class are combined to write a file containing multiple alignments (e.g. possible in NeXML or Nexus) the prefixes of each instance need to be different in order to avoid ID conflicts.
public boolean isLinkOTUs()
public info.bioinfweb.jphyloio.events.LinkedLabeledIDEvent getStartEvent(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters)
getStartEvent
in interface info.bioinfweb.jphyloio.dataadapters.ElementDataAdapter<info.bioinfweb.jphyloio.events.LinkedLabeledIDEvent>
public long getSequenceCount(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters)
getSequenceCount
in interface info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter
public long getColumnCount(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters)
AlignmentModel
instance if all sequences have an equal length.
If at least two of these sequences differ in their length, -1 is returned.getColumnCount
in interface info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter
MatrixDataAdapter.getColumnCount(info.bioinfweb.jphyloio.ReadWriteParameterMap)
public boolean containsLongTokens(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters)
containsLongTokens
in interface info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter
public info.bioinfweb.jphyloio.dataadapters.ObjectListDataAdapter<info.bioinfweb.jphyloio.events.TokenSetDefinitionEvent> getTokenSets(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters)
getTokenSets
in interface info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter
getTokenSets
in class info.bioinfweb.jphyloio.dataadapters.implementations.NoCharDefsNoSetsMatrixDataAdapter
protected java.lang.String jPhyloIOByModelSequenceID(java.lang.String modelSequenceID)
This default implementation returns the concatenation of getIDPrefix()
and sequenceID
. It can be
overwritten to use a different pattern.
modelSequenceID
- the ID of the sequence used in the underlying AlignmentModel
instanceprotected java.lang.String modelByJPhyloIOSequenceID(java.lang.String jPhyloIOsequenceID) throws java.lang.IllegalArgumentException
This default implementation extracts the integer ID that was used to create such an ID using
#jPhyloIOByModelSequenceID(int)
. If #jPhyloIOByModelSequenceID(int)
was overwritten this method
must be overwritten accordingly.
Note that this method does not test, if the extracted ID actually exists in the underlying LibrAlign alignment model.
jPhyloIOsequenceID
- the sequence ID used by JPhyloIOjava.lang.IllegalArgumentException
- if no integer ID can be extracted from the specified IDprotected java.lang.String getLinkedOTUID(java.lang.String sequenceID)
This default implementation returns the concatenation of ReadWriteConstants.DEFAULT_OTU_ID_PREFIX
and
sequenceID
if isLinkOTUs()
returns true
or null
if isLinkOTUs()
returns
false
.
Note that the ID prefix for sequences and token sets, which can be specified in the constructor will not be used for IDs creates by this method.
This method can be overwritten to use a different pattern of OTU linking.
sequenceID
- the ID of the sequence used in the underlying AlignmentModel
instancenull
if no OTU shall be linked.public java.util.Iterator<java.lang.String> getSequenceIDIterator(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters)
getSequenceIDIterator
in interface info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter
public info.bioinfweb.jphyloio.events.LinkedLabeledIDEvent getSequenceStartEvent(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters, java.lang.String sequenceID)
getSequenceStartEvent
in interface info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter
public long getSequenceLength(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters, java.lang.String sequenceID) throws java.lang.IllegalArgumentException
getSequenceLength
in interface info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter
java.lang.IllegalArgumentException
protected void writeSequenceMetadata(info.bioinfweb.jphyloio.dataadapters.JPhyloIOEventReceiver receiver, java.lang.String sequenceID) throws java.io.IOException, java.lang.IllegalArgumentException
This default implementation is empty, but can be overwritten by inherited classes.
receiver
- the receiver to write the events tosequenceID
- the ID of the sequence carrying the metadatajava.io.IOException
- if an I/O error occurs while receiver
is trying to write the datajava.lang.IllegalArgumentException
- if not sequence with the specified ID existspublic void writeSequencePartContentData(info.bioinfweb.jphyloio.ReadWriteParameterMap parameters, info.bioinfweb.jphyloio.dataadapters.JPhyloIOEventReceiver receiver, java.lang.String sequenceID, long startColumn, long endColumn) throws java.io.IOException, java.lang.IllegalArgumentException
writeSequencePartContentData
in interface info.bioinfweb.jphyloio.dataadapters.MatrixDataAdapter
java.io.IOException
java.lang.IllegalArgumentException