+ boolean searchDataset(boolean fromDna, SequenceI fromSeq, DBRefEntry xrf,
+ List<SequenceI> foundSeqs, AlignedCodonFrame mappings,
+ boolean direct, int mode)
+ {
+ boolean found = false;
+ if (dataset == null)
+ {
+ return false;
+ }
+ if (dataset.getSequences() == null)
+ {
+ System.err.println("Empty dataset sequence set - NO VECTOR");
+ return false;
+ }
+ List<SequenceI> ds = dataset.getSequences();
+ synchronized (ds)
+ {
+ for (SequenceI nxt : ds)
+ {
+ if (nxt != null)
+ {
+ if (nxt.getDatasetSequence() != null)
+ {
+ System.err.println(
+ "Implementation warning: CrossRef initialised with a dataset alignment with non-dataset sequences in it! ("
+ + nxt.getDisplayId(true) + " has ds reference "
+ + nxt.getDatasetSequence().getDisplayId(true)
+ + ")");
+ }
+ if (nxt == fromSeq || nxt == fromSeq.getDatasetSequence())
+ {
+ continue;
+ }
+ /*
+ * only look at same molecule type if 'direct', or
+ * complementary type if !direct
+ */
+ {
+ boolean isDna = !nxt.isProtein();
+ if (direct ? (isDna != fromDna) : (isDna == fromDna))
+ {
+ // skip this sequence because it is wrong molecule type
+ continue;
+ }
+ }
+
+ // look for direct or indirect references in common
+ List<DBRefEntry> poss = nxt.getDBRefs();
+ List<DBRefEntry> cands = null;
+
+ // todo: indirect specifies we select either direct references to nxt
+ // that match xrf which is indirect to sequenceI, or indirect
+ // references to nxt that match xrf which is direct to sequenceI
+ cands = DBRefUtils.searchRefs(poss, xrf, mode);
+ // else
+ // {
+ // poss = DBRefUtils.selectDbRefs(nxt.isProtein()!fromDna, poss);
+ // cands = DBRefUtils.searchRefs(poss, xrf);
+ // }
+ if (!cands.isEmpty())
+ {
+ if (foundSeqs.contains(nxt))
+ {
+ continue;
+ }
+ found = true;
+ foundSeqs.add(nxt);
+ if (mappings != null && !direct)
+ {
+ /*
+ * if the matched sequence has mapped dbrefs to
+ * protein product / cdna, add equivalent mappings to
+ * our source sequence
+ */
+ for (DBRefEntry candidate : cands)
+ {
+ Mapping mapping = candidate.getMap();
+ if (mapping != null)
+ {
+ MapList map = mapping.getMap();
+ if (mapping.getTo() != null
+ && map.getFromRatio() != map.getToRatio())
+ {
+ /*
+ * add a mapping, as from dna to peptide sequence
+ */
+ if (map.getFromRatio() == 3)
+ {
+ mappings.addMap(nxt, fromSeq, map);
+ }
+ else
+ {
+ mappings.addMap(nxt, fromSeq, map.getInverse());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return found;
+ }