From ce93212014c116c4c516c6dc85c5032449d311eb Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 16 Sep 2020 17:39:22 +0100 Subject: [PATCH] JAL-3748 pass a list to findAlignedSequence to return mapping that relates CDS and the returned Peptide sequence to avoid searching twice --- src/jalview/analysis/AlignmentUtils.java | 5 +++-- src/jalview/datamodel/AlignedCodonFrame.java | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/jalview/analysis/AlignmentUtils.java b/src/jalview/analysis/AlignmentUtils.java index 2b88cb0..cd142ca 100644 --- a/src/jalview/analysis/AlignmentUtils.java +++ b/src/jalview/analysis/AlignmentUtils.java @@ -960,11 +960,12 @@ public class AlignmentUtils .findMappingsForSequence(cdsSeq, mappings); for (AlignedCodonFrame mapping : dnaMappings) { - SequenceI peptide = mapping.findAlignedSequence(cdsSeq, protein); + List foundMap=new ArrayList<>(); + SequenceI peptide = mapping.findAlignedSequence(cdsSeq, protein,foundMap); if (peptide != null) { final int peptideLength = peptide.getLength(); - Mapping map = mapping.getMappingBetween(cdsSeq, peptide); + Mapping map = foundMap.get(0).getMapping(); if (map != null) { MapList mapList = map.getMap(); diff --git a/src/jalview/datamodel/AlignedCodonFrame.java b/src/jalview/datamodel/AlignedCodonFrame.java index fbc8a61..d1b12d3 100644 --- a/src/jalview/datamodel/AlignedCodonFrame.java +++ b/src/jalview/datamodel/AlignedCodonFrame.java @@ -455,6 +455,20 @@ public class AlignedCodonFrame */ public SequenceI findAlignedSequence(SequenceI seq, AlignmentI al) { + return findAlignedSequence(seq, al, null); + } + /** + * Convenience method to return the first aligned sequence in the given + * alignment whose dataset has a mapping with the given (aligned or dataset) + * sequence, and optionally the mapping that relates them + * + * @param seq + * @param al + * @param map - list to add the mapping to + * @return sequence from al that maps to seq + */ + public SequenceI findAlignedSequence(SequenceI seq, AlignmentI al,List map) + { /* * Search mapped protein ('to') sequences first. */ @@ -466,6 +480,10 @@ public class AlignedCodonFrame { if (ssm.covers(sourceAligned,true)) { + if (map != null) + { + map.add(ssm); + } return sourceAligned; } } @@ -484,6 +502,10 @@ public class AlignedCodonFrame { if (ssm.covers(sourceAligned,true)) { + if (map != null) + { + map.add(ssm); + } return sourceAligned; } } -- 1.7.10.2