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.analysis;
23 import jalview.datamodel.AlignedCodonFrame;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.DBRefEntry;
27 import jalview.datamodel.Mapping;
28 import jalview.datamodel.Sequence;
29 import jalview.datamodel.SequenceFeature;
30 import jalview.datamodel.SequenceI;
31 import jalview.util.DBRefUtils;
32 import jalview.util.MapList;
33 import jalview.ws.SequenceFetcherFactory;
34 import jalview.ws.seqfetcher.ASequenceFetcher;
36 import java.util.ArrayList;
37 import java.util.Iterator;
38 import java.util.List;
41 * Functions for cross-referencing sequence databases.
49 * the dataset of the alignment for which we are searching for
50 * cross-references; in some cases we may resolve xrefs by
51 * searching in the dataset
53 private AlignmentI dataset;
56 * the sequences for which we are seeking cross-references
58 private SequenceI[] fromSeqs;
61 * matcher built from dataset
63 SequenceIdMatcher matcher;
66 * sequences found by cross-ref searches to fromSeqs
68 List<SequenceI> rseqs;
74 * the sequences for which we are seeking cross-references
76 * the containing alignment dataset (may be searched to resolve
79 public CrossRef(SequenceI[] seqs, AlignmentI ds)
82 dataset = ds.getDataset() == null ? ds : ds.getDataset();
86 * Returns a list of distinct database sources for which sequences have either
88 * <li>a (dna-to-protein or protein-to-dna) cross-reference</li>
89 * <li>an indirect cross-reference - a (dna-to-protein or protein-to-dna)
90 * reference from another sequence in the dataset which has a cross-reference
91 * to a direct DBRefEntry on the given sequence</li>
95 * - when true, cross-references *from* dna returned. When false,
96 * cross-references *from* protein are returned
99 public List<String> findXrefSourcesForSequences(boolean dna)
101 List<String> sources = new ArrayList<String>();
102 for (SequenceI seq : fromSeqs)
106 findXrefSourcesForSequence(seq, dna, sources);
113 * Returns a list of distinct database sources for which a sequence has either
115 * <li>a (dna-to-protein or protein-to-dna) cross-reference</li>
116 * <li>an indirect cross-reference - a (dna-to-protein or protein-to-dna)
117 * reference from another sequence in the dataset which has a cross-reference
118 * to a direct DBRefEntry on the given sequence</li>
122 * the sequence whose dbrefs we are searching against
124 * when true, context is DNA - so sources identifying protein
125 * products will be returned.
127 * a list of sources to add matches to
129 void findXrefSourcesForSequence(SequenceI seq, boolean fromDna,
130 List<String> sources)
133 * first find seq's xrefs (dna-to-peptide or peptide-to-dna)
135 DBRefEntry[] rfs = DBRefUtils.selectDbRefs(!fromDna, seq.getDBRefs());
136 addXrefsToSources(rfs, sources);
140 * find sequence's direct (dna-to-dna, peptide-to-peptide) xrefs
142 DBRefEntry[] lrfs = DBRefUtils.selectDbRefs(fromDna, seq.getDBRefs());
143 List<SequenceI> foundSeqs = new ArrayList<SequenceI>();
146 * find sequences in the alignment which xref one of these DBRefs
147 * i.e. is xref-ed to a common sequence identifier
149 searchDatasetXrefs(fromDna, seq, lrfs, foundSeqs, null);
152 * add those sequences' (dna-to-peptide or peptide-to-dna) dbref sources
154 for (SequenceI rs : foundSeqs)
156 DBRefEntry[] xrs = DBRefUtils
157 .selectDbRefs(!fromDna, rs.getDBRefs());
158 addXrefsToSources(xrs, sources);
164 * Helper method that adds the source identifiers of some cross-references to
165 * a (non-redundant) list of database sources
170 void addXrefsToSources(DBRefEntry[] xrefs, List<String> sources)
174 for (DBRefEntry ref : xrefs)
177 * avoid duplication e.g. ENSEMBL and Ensembl
179 String source = DBRefUtils.getCanonicalName(ref.getSource());
180 if (!sources.contains(source))
189 * Attempts to find cross-references from the sequences provided in the
190 * constructor to the given source database. Cross-references may be found
192 * <li>in dbrefs on the sequence which hold a mapping to a sequence
194 * <li>provided with a fetched sequence (e.g. ENA translation), or</li>
195 * <li>populated previously after getting cross-references</li>
197 * <li>as other sequences in the alignment which share a dbref identifier with
199 * <li>by fetching from the remote database</li>
201 * The cross-referenced sequences, and mappings to them, are added to the
205 * @return cross-referenced sequences (as dataset sequences)
207 public Alignment findXrefSequences(String source, boolean fromDna)
210 rseqs = new ArrayList<SequenceI>();
211 AlignedCodonFrame cf = new AlignedCodonFrame();
212 matcher = new SequenceIdMatcher(
213 dataset.getSequences());
215 for (SequenceI seq : fromSeqs)
218 while (dss.getDatasetSequence() != null)
220 dss = dss.getDatasetSequence();
222 boolean found = false;
223 DBRefEntry[] xrfs = DBRefUtils
224 .selectDbRefs(!fromDna, dss.getDBRefs());
225 // ENST & ENSP comes in to both Protein and nucleotide, so we need to
228 if ((xrfs == null || xrfs.length == 0) && dataset != null)
231 * found no suitable dbrefs on sequence - look for sequences in the
232 * alignment which share a dbref with this one
234 DBRefEntry[] lrfs = DBRefUtils.selectDbRefs(fromDna,
238 * find sequences (except this one!), of complementary type,
239 * which have a dbref to an accession id for this sequence,
240 * and add them to the results
242 found = searchDatasetXrefs(fromDna, dss, lrfs, rseqs, cf);
244 if (xrfs == null && !found)
247 * no dbref to source on this sequence or matched
248 * complementary sequence in the dataset
252 List<DBRefEntry> sourceRefs = DBRefUtils.searchRefsForSource(xrfs,
254 Iterator<DBRefEntry> refIterator = sourceRefs.iterator();
255 // At this point, if we are retrieving Ensembl, we still don't filter out
256 // ENST when looking for protein crossrefs.
257 while (refIterator.hasNext())
259 DBRefEntry xref = refIterator.next();
261 // we're only interested in coding cross-references, not
263 if (xref.hasMap() && xref.getMap().getMap().isTripletMap())
265 SequenceI mappedTo = xref.getMap().getTo();
266 if (mappedTo != null)
269 * dbref contains the sequence it maps to; add it to the
270 * results unless we have done so already (could happen if
271 * fetching xrefs for sequences which have xrefs in common)
272 * for example: UNIPROT {P0CE19, P0CE20} -> EMBL {J03321, X06707}
276 * problem: matcher.findIdMatch() is lenient - returns a sequence
277 * with a dbref to the search arg e.g. ENST for ENSP - wrong
278 * but findInDataset() matches ENSP when looking for Uniprot...
280 SequenceI matchInDataset = findInDataset(xref);
281 if (matchInDataset != null && xref.getMap().getTo() != null
282 && matchInDataset != xref.getMap().getTo())
285 .println("Implementation problem (reopen JAL-2154): CrossRef.findInDataset seems to have recovered a different sequence than the one explicitly mapped for xref."
289 + xref.getMap().getTo()
293 /*matcher.findIdMatch(mappedTo);*/
294 if (matchInDataset != null)
296 if (!rseqs.contains(matchInDataset))
298 rseqs.add(matchInDataset);
300 // even if rseqs contained matchInDataset - check mappings between
301 // these seqs are added
302 // need to try harder to only add unique mappings
303 if (xref.getMap().getMap().isTripletMap()
304 && dataset.getMapping(seq, matchInDataset) == null
305 && cf.getMappingBetween(seq, matchInDataset) == null)
307 // materialise a mapping for highlighting between these
311 cf.addMap(dss, matchInDataset, xref.getMap().getMap(),
312 xref.getMap().getMappedFromId());
316 cf.addMap(matchInDataset, dss, xref.getMap().getMap()
317 .getInverse(), xref.getMap().getMappedFromId());
321 refIterator.remove();
324 // TODO: need to determine if this should be a deriveSequence
325 SequenceI rsq = new Sequence(mappedTo);
327 if (xref.getMap().getMap().isTripletMap())
329 // get sense of map correct for adding to product alignment.
332 // map is from dna seq to a protein product
333 cf.addMap(dss, rsq, xref.getMap().getMap(), xref.getMap()
338 // map should be from protein seq to its coding dna
339 cf.addMap(rsq, dss, xref.getMap().getMap().getInverse(),
340 xref.getMap().getMappedFromId());
348 SequenceI matchedSeq = matcher.findIdMatch(xref.getSource() + "|"
349 + xref.getAccessionId());
350 // if there was a match, check it's at least the right type of
352 if (matchedSeq != null && matchedSeq.isProtein() == fromDna)
354 if (constructMapping(seq, matchedSeq, xref, cf, fromDna))
363 // do a bit more work - search for sequences with references matching
364 // xrefs on this sequence.
365 found = searchDataset(fromDna, dss, xref, rseqs, cf, false);
369 refIterator.remove();
374 * fetch from source database any dbrefs we haven't resolved up to here
376 if (!sourceRefs.isEmpty())
378 retrieveCrossRef(sourceRefs, seq, xrfs, fromDna, cf);
382 Alignment ral = null;
383 if (rseqs.size() > 0)
385 ral = new Alignment(rseqs.toArray(new SequenceI[rseqs.size()]));
388 dataset.addCodonFrame(cf);
394 private void retrieveCrossRef(List<DBRefEntry> sourceRefs, SequenceI seq,
395 DBRefEntry[] xrfs, boolean fromDna, AlignedCodonFrame cf)
397 ASequenceFetcher sftch = SequenceFetcherFactory.getSequenceFetcher();
398 SequenceI[] retrieved = null;
399 SequenceI dss = seq.getDatasetSequence() == null ? seq : seq
400 .getDatasetSequence();
401 // first filter in case we are retrieving crossrefs that have already been
402 // retrieved. this happens for cases where a database record doesn't yield
403 // protein products for CDS
404 removeAlreadyRetrievedSeqs(sourceRefs, fromDna);
405 if (sourceRefs.size() == 0)
407 // no more work to do! We already had all requested sequence records in
413 retrieved = sftch.getSequences(sourceRefs, !fromDna);
414 } catch (Exception e)
417 .println("Problem whilst retrieving cross references for Sequence : "
422 if (retrieved != null)
424 updateDbrefMappings(seq, xrfs, retrieved, cf, fromDna);
425 for (SequenceI retrievedSequence : retrieved)
427 // dataset gets contaminated ccwith non-ds sequences. why ??!
428 // try: Ensembl -> Nuc->Ensembl, Nuc->Uniprot-->Protein->EMBL->
429 SequenceI retrievedDss = retrievedSequence.getDatasetSequence() == null ? retrievedSequence
430 : retrievedSequence.getDatasetSequence();
431 importCrossRefSeq(cf, dss, retrievedDss);
432 rseqs.add(retrievedDss);
433 if (dataset.findIndex(retrievedDss) == -1)
435 dataset.addSequence(retrievedDss);
436 matcher.add(retrievedDss);
443 * Search dataset for sequences with a primary reference contained in
447 * - list of references to filter.
449 * - type of sequence to search for matching primary reference.
451 private void removeAlreadyRetrievedSeqs(List<DBRefEntry> sourceRefs,
454 DBRefEntry[] dbrSourceSet = sourceRefs.toArray(new DBRefEntry[0]);
455 for (SequenceI sq : dataset.getSequences())
457 boolean dupeFound = false;
458 // !fromDna means we are looking only for nucleotide sequences, not
460 if (sq.isProtein() == fromDna)
462 for (DBRefEntry dbr : sq.getPrimaryDBRefs())
464 for (DBRefEntry found : DBRefUtils.searchRefs(dbrSourceSet, dbr))
466 sourceRefs.remove(found);
473 // rebuild the search array from the filtered sourceRefs list
474 dbrSourceSet = sourceRefs.toArray(new DBRefEntry[0]);
480 * process sequence retrieved via a dbref on source sequence to resolve and
484 * @param sourceSequence
485 * @param retrievedSequence
487 private void importCrossRefSeq(AlignedCodonFrame cf,
488 SequenceI sourceSequence, SequenceI retrievedSequence)
490 DBRefEntry[] dbr = retrievedSequence.getDBRefs();
493 for (DBRefEntry dbref : dbr)
495 // find any entry where we should put in the sequence being
496 // cross-referenced into the map
497 Mapping map = dbref.getMap();
500 if (map.getTo() != null && map.getMap() != null)
502 // TODO findInDataset requires exact sequence match but
503 // 'congruent' test is only for the mapped part
504 // maybe not a problem in practice since only ENA provide a
505 // mapping and it is to the full protein translation of CDS
506 SequenceI matched = findInDataset(dbref);
507 // matcher.findIdMatch(map.getTo());
511 * already got an xref to this sequence; update this
512 * map to point to the same sequence, and add
513 * any new dbrefs to it
515 DBRefEntry[] toRefs = map.getTo().getDBRefs();
518 for (DBRefEntry ref : toRefs)
520 matched.addDBRef(ref); // add or update mapping
527 if (dataset.findIndex(map.getTo()) == -1)
529 dataset.addSequence(map.getTo());
530 matcher.add(map.getTo());
536 // compare ms with dss and replace with dss in mapping
537 // if map is congruent
538 SequenceI ms = map.getTo();
539 int sf = map.getMap().getToLowest();
540 int st = map.getMap().getToHighest();
541 SequenceI mappedrg = ms.getSubSequence(sf, st);
542 if (mappedrg.getLength() > 0
543 && ms.getSequenceAsString().equals(
544 sourceSequence.getSequenceAsString()))
546 String msg = "Mapping updated from " + ms.getName()
547 + " to retrieved crossreference "
548 + sourceSequence.getName();
549 System.out.println(msg);
550 map.setTo(sourceSequence);
553 * give the reverse reference the inverse mapping
554 * (if it doesn't have one already)
556 setReverseMapping(sourceSequence, dbref, cf);
559 * copy sequence features as well, avoiding
560 * duplication (e.g. same variation from two
563 SequenceFeature[] sfs = ms.getSequenceFeatures();
566 for (SequenceFeature feat : sfs)
569 * make a flyweight feature object which ignores Parent
570 * attribute in equality test; this avoids creating many
571 * otherwise duplicate exon features on genomic sequence
573 SequenceFeature newFeature = new SequenceFeature(
577 public boolean equals(Object o)
579 return super.equals(o, true);
582 sourceSequence.addSequenceFeature(newFeature);
586 cf.addMap(retrievedSequence, map.getTo(), map.getMap());
587 } catch (Exception e)
590 .println("Exception when consolidating Mapped sequence set...");
591 e.printStackTrace(System.err);
597 retrievedSequence.updatePDBIds();
600 * Sets the inverse sequence mapping in the corresponding dbref of the mapped
601 * to sequence (if any). This is used after fetching a cross-referenced
602 * sequence, if the fetched sequence has a mapping to the original sequence,
603 * to set the mapping in the original sequence's dbref.
606 * the sequence mapped from
610 void setReverseMapping(SequenceI mapFrom, DBRefEntry dbref,
611 AlignedCodonFrame mappings)
613 SequenceI mapTo = dbref.getMap().getTo();
618 DBRefEntry[] dbrefs = mapTo.getDBRefs();
623 for (DBRefEntry toRef : dbrefs)
625 if (toRef.hasMap() && mapFrom == toRef.getMap().getTo())
628 * found the reverse dbref; update its mapping if null
630 if (toRef.getMap().getMap() == null)
632 MapList inverse = dbref.getMap().getMap().getInverse();
633 toRef.getMap().setMap(inverse);
634 mappings.addMap(mapTo, mapFrom, inverse);
641 * Returns null or the first sequence in the dataset which is identical to
642 * xref.mapTo, and has a) a primary dbref matching xref, or if none found, the
643 * first one with an ID source|xrefacc
646 * with map and mapped-to sequence
649 SequenceI findInDataset(DBRefEntry xref)
651 if (xref == null || !xref.hasMap() || xref.getMap().getTo() == null)
655 SequenceI mapsTo = xref.getMap().getTo();
656 String name = xref.getAccessionId();
657 String name2 = xref.getSource() + "|" + name;
658 SequenceI dss = mapsTo.getDatasetSequence() == null ? mapsTo : mapsTo
659 .getDatasetSequence();
660 // first check ds if ds is directly referenced
661 if (dataset.findIndex(dss) > -1)
665 DBRefEntry template = new DBRefEntry(xref.getSource(), null,
666 xref.getAccessionId());
668 * remember the first ID match - in case we don't find a match to template
670 SequenceI firstIdMatch = null;
671 for (SequenceI seq : dataset.getSequences())
673 // first check primary refs.
674 List<DBRefEntry> match = DBRefUtils.searchRefs(seq.getPrimaryDBRefs()
675 .toArray(new DBRefEntry[0]), template);
676 if (match != null && match.size() == 1 && sameSequence(seq, dss))
681 * clumsy alternative to using SequenceIdMatcher which currently
682 * returns sequences with a dbref to the matched accession id
683 * which we don't want
685 if (firstIdMatch == null
686 && (name.equals(seq.getName()) || seq.getName().startsWith(
689 if (sameSequence(seq, dss))
699 * Answers true if seq1 and seq2 contain exactly the same characters (ignoring
700 * case), else false. This method compares the lengths, then each character in
701 * turn, in order to 'fail fast'. For case-sensitive comparison, it would be
702 * possible to use Arrays.equals(seq1.getSequence(), seq2.getSequence()).
708 // TODO move to Sequence / SequenceI
709 static boolean sameSequence(SequenceI seq1, SequenceI seq2)
715 if (seq1 == null || seq2 == null)
719 char[] c1 = seq1.getSequence();
720 char[] c2 = seq2.getSequence();
721 if (c1.length != c2.length)
725 for (int i = 0; i < c1.length; i++)
727 int diff = c1[i] - c2[i];
729 * same char or differ in case only ('a'-'A' == 32)
731 if (diff != 0 && diff != 32 && diff != -32)
740 * Updates any empty mappings in the cross-references with one to a compatible
741 * retrieved sequence if found, and adds any new mappings to the
749 void updateDbrefMappings(SequenceI mapFrom, DBRefEntry[] xrefs,
750 SequenceI[] retrieved, AlignedCodonFrame acf, boolean fromDna)
752 SequenceIdMatcher idMatcher = new SequenceIdMatcher(retrieved);
753 for (DBRefEntry xref : xrefs)
757 String targetSeqName = xref.getSource() + "|"
758 + xref.getAccessionId();
759 SequenceI[] matches = idMatcher.findAllIdMatches(targetSeqName);
764 for (SequenceI seq : matches)
766 constructMapping(mapFrom, seq, xref, acf, fromDna);
773 * Tries to make a mapping between sequences. If successful, adds the mapping
774 * to the dbref and the mappings collection and answers true, otherwise
775 * answers false. The following methods of making are mapping are tried in
778 * <li>if 'mapTo' holds a mapping to 'mapFrom', take the inverse; this is, for
779 * example, the case after fetching EMBL cross-references for a Uniprot
781 * <li>else check if the dna translates exactly to the protein (give or take
782 * start and stop codons></li>
783 * <li>else try to map based on CDS features on the dna sequence</li>
792 boolean constructMapping(SequenceI mapFrom, SequenceI mapTo,
793 DBRefEntry xref, AlignedCodonFrame mappings, boolean fromDna)
795 MapList mapping = null;
796 SequenceI dsmapFrom = mapFrom.getDatasetSequence() == null ? mapFrom
797 : mapFrom.getDatasetSequence();
798 SequenceI dsmapTo = mapTo.getDatasetSequence() == null ? mapTo
799 : mapTo.getDatasetSequence();
801 * look for a reverse mapping, if found make its inverse.
802 * Note - we do this on dataset sequences only.
804 if (dsmapTo.getDBRefs() != null)
806 for (DBRefEntry dbref : dsmapTo.getDBRefs())
808 String name = dbref.getSource() + "|" + dbref.getAccessionId();
809 if (dbref.hasMap() && dsmapFrom.getName().startsWith(name))
812 * looks like we've found a map from 'mapTo' to 'mapFrom'
813 * - invert it to make the mapping the other way
815 MapList reverse = dbref.getMap().getMap().getInverse();
816 xref.setMap(new Mapping(dsmapTo, reverse));
817 mappings.addMap(mapFrom, dsmapTo, reverse);
825 mapping = AlignmentUtils.mapCdnaToProtein(mapTo, mapFrom);
829 mapping = AlignmentUtils.mapCdnaToProtein(mapFrom, mapTo);
832 mapping = mapping.getInverse();
839 xref.setMap(new Mapping(mapTo, mapping));
842 * and add a reverse DbRef with the inverse mapping
844 if (mapFrom.getDatasetSequence() != null && false)
845 // && mapFrom.getDatasetSequence().getSourceDBRef() != null)
847 // possible need to search primary references... except, why doesn't xref
848 // == getSourceDBRef ??
849 // DBRefEntry dbref = new DBRefEntry(mapFrom.getDatasetSequence()
850 // .getSourceDBRef());
851 // dbref.setMap(new Mapping(mapFrom.getDatasetSequence(), mapping
853 // mapTo.addDBRef(dbref);
858 AlignmentUtils.computeProteinFeatures(mapFrom, mapTo, mapping);
859 mappings.addMap(mapFrom, mapTo, mapping);
863 mappings.addMap(mapTo, mapFrom, mapping.getInverse());
870 * find references to lrfs in the cross-reference set of each sequence in
871 * dataset (that is not equal to sequenceI) Identifies matching DBRefEntry
872 * based on source and accession string only - Map and Version are nulled.
875 * - true if context was searching from Dna sequences, false if
876 * context was searching from Protein sequences
880 * @return true if matches were found.
882 private boolean searchDatasetXrefs(boolean fromDna, SequenceI sequenceI,
883 DBRefEntry[] lrfs, List<SequenceI> foundSeqs, AlignedCodonFrame cf)
885 boolean found = false;
890 for (int i = 0; i < lrfs.length; i++)
892 DBRefEntry xref = new DBRefEntry(lrfs[i]);
894 xref.setVersion(null);
896 found |= searchDataset(fromDna, sequenceI, xref, foundSeqs, cf, false);
902 * Searches dataset for DBRefEntrys matching the given one (xrf) and adds the
903 * associated sequence to rseqs
906 * true if context was searching for refs *from* dna sequence, false
907 * if context was searching for refs *from* protein sequence
909 * a sequence to ignore (start point of search)
911 * a cross-reference to try to match
913 * result list to add to
915 * a set of sequence mappings to add to
917 * - indicates the type of relationship between returned sequences,
918 * xrf, and sequenceI that is required.
920 * <li>direct implies xrf is a primary reference for sequenceI AND
921 * the sequences to be located (eg a uniprot ID for a protein
922 * sequence, and a uniprot ref on a transcript sequence).</li>
923 * <li>indirect means xrf is a cross reference with respect to
924 * sequenceI or all the returned sequences (eg a genomic reference
925 * associated with a locus and one or more transcripts)</li>
927 * @return true if relationship found and sequence added.
929 boolean searchDataset(boolean fromDna, SequenceI fromSeq, DBRefEntry xrf,
930 List<SequenceI> foundSeqs, AlignedCodonFrame mappings,
933 boolean found = false;
938 if (dataset.getSequences() == null)
940 System.err.println("Empty dataset sequence set - NO VECTOR");
944 synchronized (ds = dataset.getSequences())
946 for (SequenceI nxt : ds)
950 if (nxt.getDatasetSequence() != null)
953 .println("Implementation warning: CrossRef initialised with a dataset alignment with non-dataset sequences in it! ("
954 + nxt.getDisplayId(true)
955 + " has ds reference "
956 + nxt.getDatasetSequence().getDisplayId(true)
959 if (nxt == fromSeq || nxt == fromSeq.getDatasetSequence())
964 * only look at same molecule type if 'direct', or
965 * complementary type if !direct
968 boolean isDna = !nxt.isProtein();
969 if (direct ? (isDna != fromDna) : (isDna == fromDna))
971 // skip this sequence because it is wrong molecule type
976 // look for direct or indirect references in common
977 DBRefEntry[] poss = nxt.getDBRefs();
978 List<DBRefEntry> cands = null;
980 // todo: indirect specifies we select either direct references to nxt
981 // that match xrf which is indirect to sequenceI, or indirect
982 // references to nxt that match xrf which is direct to sequenceI
983 cands = DBRefUtils.searchRefs(poss, xrf);
986 // poss = DBRefUtils.selectDbRefs(nxt.isProtein()!fromDna, poss);
987 // cands = DBRefUtils.searchRefs(poss, xrf);
989 if (!cands.isEmpty())
991 if (foundSeqs.contains(nxt))
997 if (mappings != null && !direct)
1000 * if the matched sequence has mapped dbrefs to
1001 * protein product / cdna, add equivalent mappings to
1002 * our source sequence
1004 for (DBRefEntry candidate : cands)
1006 Mapping mapping = candidate.getMap();
1007 if (mapping != null)
1009 MapList map = mapping.getMap();
1010 if (mapping.getTo() != null
1011 && map.getFromRatio() != map.getToRatio())
1014 * add a mapping, as from dna to peptide sequence
1016 if (map.getFromRatio() == 3)
1018 mappings.addMap(nxt, fromSeq, map);
1022 mappings.addMap(nxt, fromSeq, map.getInverse());