X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FCrossRef.java;h=0f7a75443ccba23b2fde5c3bd4c473af41a1771d;hb=9fe87bd08ab29b6fe53364f387d7a2e3a8d39994;hp=2f6076a1676314017a7661af4a766cd7d962b6eb;hpb=9c6f9bb69f694cb37db088c8fca6582169efcb05;p=jalview.git diff --git a/src/jalview/analysis/CrossRef.java b/src/jalview/analysis/CrossRef.java index 2f6076a..0f7a754 100644 --- a/src/jalview/analysis/CrossRef.java +++ b/src/jalview/analysis/CrossRef.java @@ -30,6 +30,7 @@ import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.util.DBRefUtils; +import jalview.util.MapList; import jalview.ws.SequenceFetcher; import jalview.ws.seqfetcher.ASequenceFetcher; @@ -232,8 +233,9 @@ public class CrossRef * are found e.g. alternative protein products for a protein's gene * @return products (as dataset sequences) */ - public static Alignment findXrefSequences(SequenceI[] seqs, boolean dna, - String source, AlignmentI al, List addedPeers) + public static Alignment findXrefSequences(SequenceI[] seqs, + final boolean dna, final String source, AlignmentI al, + List addedPeers) { AlignmentI dataset = al.getDataset() == null ? al : al.getDataset(); List rseqs = new ArrayList(); @@ -294,7 +296,9 @@ public class CrossRef // xrefs on this sequence. if (dataset != null) { - found |= searchDataset(dss, xref, dataset, rseqs, cf); // ,false,!dna); + found |= searchDataset(dss, xref, dataset, rseqs, cf, false, + !dna); + // ,false,!dna); if (found) { xrfs[r] = null; // we've recovered seqs for this one. @@ -355,6 +359,11 @@ public class CrossRef if (retrieved != null) { + updateDbrefMappings(dna, seq, xrfs, retrieved, cf); + + SequenceIdMatcher matcher = new SequenceIdMatcher( + dataset.getSequences()); + matcher.addAll(addedPeers); List copiedFeatures = new ArrayList(); CrossRef me = new CrossRef(); for (int rs = 0; rs < retrieved.length; rs++) @@ -372,8 +381,25 @@ public class CrossRef { if (map.getTo() != null && map.getMap() != null) { - // should search the local dataset to find any existing - // candidates for To ! + SequenceI matched = matcher + .findIdMatch(map.getTo()); + if (matched != null) + { + /* + * already got an xref to this sequence; update this + * map to point to the same sequence, and add + * any new dbrefs to it + */ + for (DBRefEntry ref : map.getTo().getDBRefs()) + { + matched.addDBRef(ref); + } + map.setTo(matched); + } + else + { + matcher.add(map.getTo()); + } try { // compare ms with dss and replace with dss in mapping @@ -427,7 +453,10 @@ public class CrossRef } else { - addedPeers.add(map.getTo()); + if (!addedPeers.contains(map.getTo())) + { + addedPeers.add(map.getTo()); + } cf.addMap(retrieved[rs].getDatasetSequence(), map.getTo(), map.getMap()); } @@ -463,6 +492,69 @@ public class CrossRef } /** + * Updates any empty mappings in the cross-references with one to a compatible + * retrieved sequence if found, and adds any new mappings to the + * AlignedCodonFrame + * + * @param dna + * @param mapFrom + * @param xrefs + * @param retrieved + * @param acf + */ + static void updateDbrefMappings(boolean dna, SequenceI mapFrom, + DBRefEntry[] xrefs, SequenceI[] retrieved, AlignedCodonFrame acf) + { + SequenceIdMatcher matcher = new SequenceIdMatcher(retrieved); + for (DBRefEntry xref : xrefs) + { + if (!xref.hasMap()) + { + String targetSeqName = xref.getSource() + "|" + + xref.getAccessionId(); + SequenceI[] matches = matcher.findAllIdMatches(targetSeqName); + if (matches == null) + { + return; + } + for (SequenceI seq : matches) + { + MapList mapping = null; + if (dna) + { + mapping = AlignmentUtils.mapCdnaToProtein(seq, mapFrom); + } + else + { + mapping = AlignmentUtils.mapCdnaToProtein(mapFrom, seq); + if (mapping != null) + { + mapping = mapping.getInverse(); + } + } + if (mapping != null) + { + xref.setMap(new Mapping(seq, mapping)); + if (dna) + { + AlignmentUtils.computeProteinFeatures(mapFrom, seq, mapping); + } + if (dna) + { + acf.addMap(mapFrom, seq, mapping); + } + else + { + acf.addMap(seq, mapFrom, mapping.getInverse()); + } + continue; + } + } + } + } + } + + /** * find references to lrfs in the cross-reference set of each sequence in * dataset (that is not equal to sequenceI) Identifies matching DBRefEntry * based on source and accession string only - Map and Version are nulled.