+ private void importMatrixData(List<MatrixType> xmlmatrices)
+ {
+ for (MatrixType xmlmat:xmlmatrices)
+ {
+ if (!PAEContactMatrix.PAEMATRIX.equals(xmlmat.getType()))
+ {
+ Console.error("Ignoring matrix '"+xmlmat.getId()+"' of type '"+xmlmat.getType());
+ continue;
+ }
+
+ if (!xmlmat.getRows().equals(xmlmat.getCols()))
+ {
+ Console.error("Can't handle non square matrices");
+ continue;
+ }
+
+ float[][] elements = ContactMatrix
+ .fromFloatStringToContacts(xmlmat.getElements(),
+ xmlmat.getCols().intValue(),
+ xmlmat.getRows().intValue());
+
+ List<BitSet> newgroups = new ArrayList<BitSet>();
+ if (xmlmat.getGroups().size() > 0)
+ {
+ for (String sgroup : xmlmat.getGroups())
+ {
+ newgroups.add(deStringifyBitset(sgroup));
+ }
+ }
+ String nwk = xmlmat.getNewick().size() > 0
+ ? xmlmat.getNewick().get(0)
+ : null;
+ if (xmlmat.getNewick().size() > 1)
+ {
+ Console.log.info(
+ "Ignoring additional clusterings for contact matrix");
+ }
+ String treeMethod = xmlmat.getTreeMethod();
+ double thresh = xmlmat.getCutHeight() != null
+ ? xmlmat.getCutHeight()
+ : 0;
+ GroupSet grpset = new GroupSet();
+ grpset.restoreGroups(newgroups, treeMethod, nwk, thresh);
+
+ FloatContactMatrix newcm = new FloatContactMatrix(elements, grpset);
+ contactMatrixRefs.put(xmlmat.getId(), newcm);
+ Console.trace("Restored base contact matrix "+xmlmat.getId());
+ }
+ }
+
+ private void restoreMatrixFor(SequenceI sequenceRef,
+ AlignmentAnnotation jaa, MapOnAMatrixType xmlmatmapping)
+ {
+ MatrixType xmlmat;
+
+ // locate matrix data in project XML and import
+ ContactMatrixI cm = contactMatrixRefs.get(xmlmatmapping.getMatrix());
+ if (cm == null)
+ {
+ Console.error("Cannot restore mapping to matrix "
+ + xmlmatmapping.getMatrix() + " - not found in project.");
+ }
+
+ // restore mapping data to matrix data
+ jalview.util.MapList mapping = null;
+ if (xmlmatmapping.getMapping() != null)
+ {
+ MapListType m = xmlmatmapping.getMapping();
+ // Mapping m = dr.getMapping();
+ int fr[] = new int[m.getMapListFrom().size() * 2];
+ Iterator<MapListFrom> from = m.getMapListFrom().iterator();// enumerateMapListFrom();
+ for (int _i = 0; from.hasNext(); _i += 2)
+ {
+ MapListFrom mf = from.next();
+ fr[_i] = mf.getStart();
+ fr[_i + 1] = mf.getEnd();
+ }
+ int fto[] = new int[m.getMapListTo().size() * 2];
+ Iterator<MapListTo> to = m.getMapListTo().iterator();// enumerateMapListTo();
+ for (int _i = 0; to.hasNext(); _i += 2)
+ {
+ MapListTo mf = to.next();
+ fto[_i] = mf.getStart();
+ fto[_i + 1] = mf.getEnd();
+ }
+
+ mapping = new jalview.util.MapList(fr, fto,
+ m.getMapFromUnit().intValue(), m.getMapToUnit().intValue());
+ }
+ PAEContactMatrix newpae = new PAEContactMatrix(jaa.sequenceRef, mapping,
+ cm);
+
+ jaa.sequenceRef.addContactListFor(jaa, newpae);
+
+ return;
+ }
+