2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import jalview.analysis.AlignSeq;
24 import jalview.api.DBRefEntryI;
25 import jalview.datamodel.features.SequenceFeatures;
26 import jalview.datamodel.features.SequenceFeaturesI;
27 import jalview.util.Comparison;
28 import jalview.util.DBRefUtils;
29 import jalview.util.MapList;
30 import jalview.util.StringUtils;
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.Collections;
35 import java.util.Enumeration;
36 import java.util.List;
37 import java.util.Vector;
39 import com.stevesoft.pat.Regex;
41 import fr.orsay.lri.varna.models.rna.RNA;
45 * Implements the SequenceI interface for a char[] based sequence object.
50 public class Sequence extends ASequence implements SequenceI
52 private static final Regex limitrx = new Regex(
53 "[/][0-9]{1,}[-][0-9]{1,}$");
55 private static final Regex endrx = new Regex("[0-9]{1,}$");
57 SequenceI datasetSequence;
61 private char[] sequence;
69 Vector<PDBEntry> pdbIds;
78 * This annotation is displayed below the alignment but the positions are tied
79 * to the residues of this sequence
81 * TODO: change to List<>
83 Vector<AlignmentAnnotation> annotation;
86 * The index of the sequence in a MSA
90 private SequenceFeatures sequenceFeatureStore;
93 * Creates a new Sequence object.
98 * string to form a possibly gapped sequence out of
100 * first position of non-gap residue in the sequence
102 * last position of ungapped residues (nearly always only used for
105 public Sequence(String name, String sequence, int start, int end)
108 initSeqAndName(name, sequence.toCharArray(), start, end);
111 public Sequence(String name, char[] sequence, int start, int end)
114 initSeqAndName(name, sequence, start, end);
118 * Stage 1 constructor - assign name, sequence, and set start and end fields.
119 * start and end are updated values from name2 if it ends with /start-end
126 protected void initSeqAndName(String name2, char[] sequence2, int start2,
130 this.sequence = sequence2;
142 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
145 // Does sequence have the /start-end signature?
146 if (limitrx.search(name))
148 name = limitrx.left();
149 endrx.search(limitrx.stringMatched());
150 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
151 endrx.matchedFrom() - 1)));
152 setEnd(Integer.parseInt(endrx.stringMatched()));
156 void checkValidRange()
159 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
162 for (int j = 0; j < sequence.length; j++)
164 if (!jalview.util.Comparison.isGap(sequence[j]))
183 * default constructor
187 sequenceFeatureStore = new SequenceFeatures();
191 * Creates a new Sequence object.
198 public Sequence(String name, String sequence)
200 this(name, sequence, 1, -1);
204 * Creates a new Sequence object with new AlignmentAnnotations but inherits
205 * any existing dataset sequence reference. If non exists, everything is
209 * if seq is a dataset sequence, behaves like a plain old copy
212 public Sequence(SequenceI seq)
214 this(seq, seq.getAnnotation());
218 * Create a new sequence object with new features, DBRefEntries, and PDBIds
219 * but inherits any existing dataset sequence reference, and duplicate of any
220 * annotation that is present in the given annotation array.
223 * the sequence to be copied
224 * @param alAnnotation
225 * an array of annotation including some associated with seq
227 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
230 initSeqFrom(seq, alAnnotation);
234 * does the heavy lifting when cloning a dataset sequence, or coping data from
235 * dataset to a new derived sequence.
238 * - source of attributes.
239 * @param alAnnotation
240 * - alignment annotation present on seq that should be copied onto
243 protected void initSeqFrom(SequenceI seq,
244 AlignmentAnnotation[] alAnnotation)
246 char[] oseq = seq.getSequence();
247 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
248 seq.getStart(), seq.getEnd());
250 description = seq.getDescription();
251 if (seq != datasetSequence)
253 setDatasetSequence(seq.getDatasetSequence());
257 * only copy DBRefs and seqfeatures if we really are a dataset sequence
259 if (datasetSequence == null)
261 if (seq.getDBRefs() != null)
263 DBRefEntry[] dbr = seq.getDBRefs();
264 for (int i = 0; i < dbr.length; i++)
266 addDBRef(new DBRefEntry(dbr[i]));
271 * make copies of any sequence features
273 for (SequenceFeature sf : seq.getSequenceFeatures())
275 addSequenceFeature(new SequenceFeature(sf));
279 if (seq.getAnnotation() != null)
281 AlignmentAnnotation[] sqann = seq.getAnnotation();
282 for (int i = 0; i < sqann.length; i++)
284 if (sqann[i] == null)
288 boolean found = (alAnnotation == null);
291 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
293 found = (alAnnotation[apos] == sqann[i]);
298 // only copy the given annotation
299 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
300 addAlignmentAnnotation(newann);
304 if (seq.getAllPDBEntries() != null)
306 Vector<PDBEntry> ids = seq.getAllPDBEntries();
307 for (PDBEntry pdb : ids)
309 this.addPDBId(new PDBEntry(pdb));
315 public void setSequenceFeatures(List<SequenceFeature> features)
317 if (datasetSequence != null)
319 datasetSequence.setSequenceFeatures(features);
322 sequenceFeatureStore = new SequenceFeatures(features);
326 public synchronized boolean addSequenceFeature(SequenceFeature sf)
328 if (sf.getType() == null)
330 System.err.println("SequenceFeature type may not be null: "
335 if (datasetSequence != null)
337 return datasetSequence.addSequenceFeature(sf);
340 return sequenceFeatureStore.add(sf);
344 public void deleteFeature(SequenceFeature sf)
346 if (datasetSequence != null)
348 datasetSequence.deleteFeature(sf);
352 sequenceFeatureStore.delete(sf);
362 public List<SequenceFeature> getSequenceFeatures()
364 if (datasetSequence != null)
366 return datasetSequence.getSequenceFeatures();
368 return sequenceFeatureStore.getAllFeatures();
372 public SequenceFeaturesI getFeatures()
374 return datasetSequence != null ? datasetSequence.getFeatures()
375 : sequenceFeatureStore;
379 public boolean addPDBId(PDBEntry entry)
383 pdbIds = new Vector<PDBEntry>();
388 for (PDBEntry pdbe : pdbIds)
390 if (pdbe.updateFrom(entry))
395 pdbIds.addElement(entry);
406 public void setPDBId(Vector<PDBEntry> id)
414 * @return DOCUMENT ME!
417 public Vector<PDBEntry> getAllPDBEntries()
419 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
425 * @return DOCUMENT ME!
428 public String getDisplayId(boolean jvsuffix)
430 StringBuffer result = new StringBuffer(name);
433 result.append("/" + start + "-" + end);
436 return result.toString();
446 public void setName(String name)
455 * @return DOCUMENT ME!
458 public String getName()
470 public void setStart(int start)
478 * @return DOCUMENT ME!
481 public int getStart()
493 public void setEnd(int end)
501 * @return DOCUMENT ME!
512 * @return DOCUMENT ME!
515 public int getLength()
517 return this.sequence.length;
527 public void setSequence(String seq)
529 this.sequence = seq.toCharArray();
534 public String getSequenceAsString()
536 return new String(sequence);
540 public String getSequenceAsString(int start, int end)
542 return new String(getSequence(start, end));
546 public char[] getSequence()
554 * @see jalview.datamodel.SequenceI#getSequence(int, int)
557 public char[] getSequence(int start, int end)
563 // JBPNote - left to user to pad the result here (TODO:Decide on this
565 if (start >= sequence.length)
570 if (end >= sequence.length)
572 end = sequence.length;
575 char[] reply = new char[end - start];
576 System.arraycopy(sequence, start, reply, 0, end - start);
582 public SequenceI getSubSequence(int start, int end)
588 char[] seq = getSequence(start, end);
593 int nstart = findPosition(start);
594 int nend = findPosition(end) - 1;
595 // JBPNote - this is an incomplete copy.
596 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
597 nseq.setDescription(description);
598 if (datasetSequence != null)
600 nseq.setDatasetSequence(datasetSequence);
604 nseq.setDatasetSequence(this);
610 * Returns the character of the aligned sequence at the given position (base
611 * zero), or space if the position is not within the sequence's bounds
616 public char getCharAt(int i)
618 if (i >= 0 && i < sequence.length)
635 public void setDescription(String desc)
637 this.description = desc;
643 * @return DOCUMENT ME!
646 public String getDescription()
648 return this.description;
654 * @see jalview.datamodel.SequenceI#findIndex(int)
657 public int findIndex(int pos)
659 // returns the alignment position for a residue
662 // Rely on end being at least as long as the length of the sequence.
663 while ((i < sequence.length) && (j <= end) && (j <= pos))
665 if (!jalview.util.Comparison.isGap(sequence[i]))
673 if ((j == end) && (j < pos))
684 public int findPosition(int i)
688 int seqlen = sequence.length;
689 while ((j < i) && (j < seqlen))
691 if (!jalview.util.Comparison.isGap(sequence[j]))
703 * Returns an int array where indices correspond to each residue in the
704 * sequence and the element value gives its position in the alignment
706 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
707 * residues in SequenceI object
710 public int[] gapMap()
712 String seq = jalview.analysis.AlignSeq.extractGaps(
713 jalview.util.Comparison.GapChars, new String(sequence));
714 int[] map = new int[seq.length()];
718 while (j < sequence.length)
720 if (!jalview.util.Comparison.isGap(sequence[j]))
732 public int[] findPositionMap()
734 int map[] = new int[sequence.length];
737 int seqlen = sequence.length;
741 if (!jalview.util.Comparison.isGap(sequence[j]))
752 public List<int[]> getInsertions()
754 ArrayList<int[]> map = new ArrayList<int[]>();
755 int lastj = -1, j = 0;
757 int seqlen = sequence.length;
760 if (jalview.util.Comparison.isGap(sequence[j]))
771 map.add(new int[] { lastj, j - 1 });
779 map.add(new int[] { lastj, j - 1 });
786 public void deleteChars(int i, int j)
788 int newstart = start, newend = end;
789 if (i >= sequence.length || i < 0)
794 char[] tmp = StringUtils.deleteChars(sequence, i, j);
795 boolean createNewDs = false;
796 // TODO: take a (second look) at the dataset creation validation method for
797 // the very large sequence case
798 int eindex = -1, sindex = -1;
799 boolean ecalc = false, scalc = false;
800 for (int s = i; s < j; s++)
802 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
812 sindex = findIndex(start) - 1;
817 // delete characters including start of sequence
818 newstart = findPosition(j);
819 break; // don't need to search for any more residue characters.
823 // delete characters after start.
826 eindex = findIndex(end) - 1;
831 // delete characters at end of sequence
832 newend = findPosition(i - 1);
833 break; // don't need to search for any more residue characters.
838 newend--; // decrease end position by one for the deleted residue
839 // and search further
845 // deletion occured in the middle of the sequence
846 if (createNewDs && this.datasetSequence != null)
848 // construct a new sequence
849 Sequence ds = new Sequence(datasetSequence);
850 // TODO: remove any non-inheritable properties ?
851 // TODO: create a sequence mapping (since there is a relation here ?)
852 ds.deleteChars(i, j);
853 datasetSequence = ds;
861 public void insertCharAt(int i, int length, char c)
863 char[] tmp = new char[sequence.length + length];
865 if (i >= sequence.length)
867 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
872 System.arraycopy(sequence, 0, tmp, 0, i);
882 if (i < sequence.length)
884 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
891 public void insertCharAt(int i, char c)
893 insertCharAt(i, 1, c);
897 public String getVamsasId()
903 public void setVamsasId(String id)
909 public void setDBRefs(DBRefEntry[] dbref)
911 if (dbrefs == null && datasetSequence != null
912 && this != datasetSequence)
914 datasetSequence.setDBRefs(dbref);
920 DBRefUtils.ensurePrimaries(this);
925 public DBRefEntry[] getDBRefs()
927 if (dbrefs == null && datasetSequence != null
928 && this != datasetSequence)
930 return datasetSequence.getDBRefs();
936 public void addDBRef(DBRefEntry entry)
938 if (datasetSequence != null)
940 datasetSequence.addDBRef(entry);
946 dbrefs = new DBRefEntry[0];
949 for (DBRefEntryI dbr : dbrefs)
951 if (dbr.updateFrom(entry))
954 * found a dbref that either matched, or could be
955 * updated from, the new entry - no need to add it
962 * extend the array to make room for one more
964 // TODO use an ArrayList instead
965 int j = dbrefs.length;
966 DBRefEntry[] temp = new DBRefEntry[j + 1];
967 System.arraycopy(dbrefs, 0, temp, 0, j);
968 temp[temp.length - 1] = entry;
972 DBRefUtils.ensurePrimaries(this);
976 public void setDatasetSequence(SequenceI seq)
980 throw new IllegalArgumentException(
981 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
983 if (seq != null && seq.getDatasetSequence() != null)
985 throw new IllegalArgumentException(
986 "Implementation error: cascading dataset sequences are not allowed.");
988 datasetSequence = seq;
992 public SequenceI getDatasetSequence()
994 return datasetSequence;
998 public AlignmentAnnotation[] getAnnotation()
1000 return annotation == null ? null : annotation
1001 .toArray(new AlignmentAnnotation[annotation.size()]);
1005 public boolean hasAnnotation(AlignmentAnnotation ann)
1007 return annotation == null ? false : annotation.contains(ann);
1011 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1013 if (this.annotation == null)
1015 this.annotation = new Vector<AlignmentAnnotation>();
1017 if (!this.annotation.contains(annotation))
1019 this.annotation.addElement(annotation);
1021 annotation.setSequenceRef(this);
1025 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1027 if (this.annotation != null)
1029 this.annotation.removeElement(annotation);
1030 if (this.annotation.size() == 0)
1032 this.annotation = null;
1038 * test if this is a valid candidate for another sequence's dataset sequence.
1041 private boolean isValidDatasetSequence()
1043 if (datasetSequence != null)
1047 for (int i = 0; i < sequence.length; i++)
1049 if (jalview.util.Comparison.isGap(sequence[i]))
1058 public SequenceI deriveSequence()
1060 Sequence seq = null;
1061 if (datasetSequence == null)
1063 if (isValidDatasetSequence())
1065 // Use this as dataset sequence
1066 seq = new Sequence(getName(), "", 1, -1);
1067 seq.setDatasetSequence(this);
1068 seq.initSeqFrom(this, getAnnotation());
1073 // Create a new, valid dataset sequence
1074 createDatasetSequence();
1077 return new Sequence(this);
1080 private boolean _isNa;
1082 private long _seqhash = 0;
1085 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1089 public boolean isProtein()
1091 if (datasetSequence != null)
1093 return datasetSequence.isProtein();
1095 if (_seqhash != sequence.hashCode())
1097 _seqhash = sequence.hashCode();
1098 _isNa = Comparison.isNucleotide(this);
1106 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1109 public SequenceI createDatasetSequence()
1111 if (datasetSequence == null)
1113 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1114 jalview.util.Comparison.GapChars, getSequenceAsString()),
1115 getStart(), getEnd());
1117 datasetSequence = dsseq;
1119 dsseq.setDescription(description);
1120 // move features and database references onto dataset sequence
1121 dsseq.sequenceFeatureStore = sequenceFeatureStore;
1122 sequenceFeatureStore = null;
1123 dsseq.dbrefs = dbrefs;
1125 // TODO: search and replace any references to this sequence with
1126 // references to the dataset sequence in Mappings on dbref
1127 dsseq.pdbIds = pdbIds;
1129 datasetSequence.updatePDBIds();
1130 if (annotation != null)
1132 // annotation is cloned rather than moved, to preserve what's currently
1134 for (AlignmentAnnotation aa : annotation)
1136 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1137 _aa.sequenceRef = datasetSequence;
1138 _aa.adjustForAlignment(); // uses annotation's own record of
1139 // sequence-column mapping
1140 datasetSequence.addAlignmentAnnotation(_aa);
1144 return datasetSequence;
1151 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1155 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1157 if (annotation != null)
1159 annotation.removeAllElements();
1161 if (annotations != null)
1163 for (int i = 0; i < annotations.length; i++)
1165 if (annotations[i] != null)
1167 addAlignmentAnnotation(annotations[i]);
1174 public AlignmentAnnotation[] getAnnotation(String label)
1176 if (annotation == null || annotation.size() == 0)
1181 Vector<AlignmentAnnotation> subset = new Vector<AlignmentAnnotation>();
1182 Enumeration<AlignmentAnnotation> e = annotation.elements();
1183 while (e.hasMoreElements())
1185 AlignmentAnnotation ann = e.nextElement();
1186 if (ann.label != null && ann.label.equals(label))
1188 subset.addElement(ann);
1191 if (subset.size() == 0)
1195 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1197 e = subset.elements();
1198 while (e.hasMoreElements())
1200 anns[i++] = e.nextElement();
1202 subset.removeAllElements();
1207 public boolean updatePDBIds()
1209 if (datasetSequence != null)
1211 // TODO: could merge DBRefs
1212 return datasetSequence.updatePDBIds();
1214 if (dbrefs == null || dbrefs.length == 0)
1218 boolean added = false;
1219 for (DBRefEntry dbr : dbrefs)
1221 if (DBRefSource.PDB.equals(dbr.getSource()))
1224 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1225 * PDB id is not already present in a 'matching' PDBEntry
1226 * Constructor parses out a chain code if appended to the accession id
1227 * (a fudge used to 'store' the chain code in the DBRef)
1229 PDBEntry pdbe = new PDBEntry(dbr);
1230 added |= addPDBId(pdbe);
1237 public void transferAnnotation(SequenceI entry, Mapping mp)
1239 if (datasetSequence != null)
1241 datasetSequence.transferAnnotation(entry, mp);
1244 if (entry.getDatasetSequence() != null)
1246 transferAnnotation(entry.getDatasetSequence(), mp);
1249 // transfer any new features from entry onto sequence
1250 if (entry.getSequenceFeatures() != null)
1253 List<SequenceFeature> sfs = entry.getSequenceFeatures();
1254 for (SequenceFeature feature : sfs)
1256 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(feature)
1257 : new SequenceFeature[] { new SequenceFeature(feature) };
1260 for (int sfi = 0; sfi < sf.length; sfi++)
1262 addSequenceFeature(sf[sfi]);
1268 // transfer PDB entries
1269 if (entry.getAllPDBEntries() != null)
1271 Enumeration<PDBEntry> e = entry.getAllPDBEntries().elements();
1272 while (e.hasMoreElements())
1274 PDBEntry pdb = e.nextElement();
1278 // transfer database references
1279 DBRefEntry[] entryRefs = entry.getDBRefs();
1280 if (entryRefs != null)
1282 for (int r = 0; r < entryRefs.length; r++)
1284 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1285 if (newref.getMap() != null && mp != null)
1287 // remap ref using our local mapping
1289 // we also assume all version string setting is done by dbSourceProxy
1291 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1292 * newref.setSource(dbSource); }
1300 * @return The index (zero-based) on this sequence in the MSA. It returns
1301 * {@code -1} if this information is not available.
1304 public int getIndex()
1310 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1311 * if this information is undefined.
1314 * position for this sequence. This value is zero-based (zero for
1315 * this first sequence)
1318 public void setIndex(int value)
1324 public void setRNA(RNA r)
1336 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1339 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1340 if (this.annotation != null)
1342 for (AlignmentAnnotation ann : annotation)
1344 if (ann.calcId != null && ann.calcId.equals(calcId)
1345 && ann.label != null && ann.label.equals(label))
1355 public String toString()
1357 return getDisplayId(false);
1361 public PDBEntry getPDBEntry(String pdbIdStr)
1363 if (getDatasetSequence() != null)
1365 return getDatasetSequence().getPDBEntry(pdbIdStr);
1371 List<PDBEntry> entries = getAllPDBEntries();
1372 for (PDBEntry entry : entries)
1374 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1383 public List<DBRefEntry> getPrimaryDBRefs()
1385 if (datasetSequence != null)
1387 return datasetSequence.getPrimaryDBRefs();
1389 if (dbrefs == null || dbrefs.length == 0)
1391 return Collections.emptyList();
1393 synchronized (dbrefs)
1395 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1396 DBRefEntry[] tmp = new DBRefEntry[1];
1397 for (DBRefEntry ref : dbrefs)
1399 if (!ref.isPrimaryCandidate())
1405 MapList mp = ref.getMap().getMap();
1406 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1408 // map only involves a subsequence, so cannot be primary
1412 // whilst it looks like it is a primary ref, we also sanity check type
1413 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1414 DBRefUtils.getCanonicalName(ref.getSource())))
1416 // PDB dbrefs imply there should be a PDBEntry associated
1417 // TODO: tighten PDB dbrefs
1418 // formally imply Jalview has actually downloaded and
1419 // parsed the pdb file. That means there should be a cached file
1420 // handle on the PDBEntry, and a real mapping between sequence and
1421 // extracted sequence from PDB file
1422 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1423 if (pdbentry != null && pdbentry.getFile() != null)
1429 // check standard protein or dna sources
1431 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1432 if (res != null && res[0] == tmp[0])
1446 public List<SequenceFeature> findFeatures(int from, int to,
1449 if (datasetSequence != null)
1451 return datasetSequence.findFeatures(from, to, types);
1453 return sequenceFeatureStore.findFeatures(from, to, types);