X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fstructure%2FStructureSelectionManager.java;h=7d936ef924cb30fd333f4ecb3505026c7843307a;hb=af1f57f65bad11f8e0329be6f539ae001630948d;hp=bb1bb94c79fcf62969672fd5db157b67c072fe63;hpb=3857a631189eb7d5a73560ecd08c8e3c7d7af2b5;p=jalview.git diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index bb1bb94..7d936ef 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -20,11 +20,12 @@ */ package jalview.structure; + import jalview.analysis.AlignSeq; import jalview.api.StructureSelectionManagerProvider; import jalview.bin.ApplicationSingletonProvider; import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI; -import jalview.bin.Cache; +import jalview.bin.Console; import jalview.commands.CommandI; import jalview.commands.EditCommand; import jalview.commands.OrderCommand; @@ -57,6 +58,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Vector; @@ -68,6 +70,7 @@ public class StructureSelectionManager implements ApplicationSingletonI { public final static String NEWLINE = System.lineSeparator(); + private List mappings = new ArrayList<>(); private boolean processSecondaryStructure = false; @@ -84,7 +87,6 @@ public class StructureSelectionManager implements ApplicationSingletonI private List commandListeners = new ArrayList<>(); private List sel_listeners = new ArrayList<>(); - /* * instances of this class scoped by some context class */ @@ -98,7 +100,7 @@ public class StructureSelectionManager implements ApplicationSingletonI */ private static StructureSelectionManager getInstance() { - return (StructureSelectionManager) ApplicationSingletonProvider + return ApplicationSingletonProvider .getInstance(StructureSelectionManager.class); } @@ -144,7 +146,52 @@ public class StructureSelectionManager implements ApplicationSingletonI } return instance; } +/** Null provider in 2.11.2 + + + private static StructureSelectionManager nullProvider = null; + public static StructureSelectionManager getStructureSelectionManager( + StructureSelectionManagerProvider context) + { + if (context == null) + { + if (nullProvider == null) + { + if (instances != null) + { + throw new Error(MessageManager.getString( + "error.implementation_error_structure_selection_manager_null"), + new NullPointerException(MessageManager + .getString("exception.ssm_context_is_null"))); + } + else + { + nullProvider = new StructureSelectionManager(); + } + return nullProvider; + } + } + if (instances == null) + { + instances = new java.util.IdentityHashMap<>(); + } + StructureSelectionManager instance = instances.get(context); + if (instance == null) + { + if (nullProvider != null) + { + instance = nullProvider; + } + else + { + instance = new StructureSelectionManager(); + } + instances.put(context, instance); + } + return instance; + } +*/ /** * @return true if will try to use external services for processing secondary @@ -434,7 +481,17 @@ public class StructureSelectionManager implements ApplicationSingletonI registerPDBFile(pdb.getId().trim(), pdbFile); } // if PDBId is unavailable then skip SIFTS mapping execution path - isMapUsingSIFTs = isMapUsingSIFTs && pdb.isPPDBIdAvailable(); + // TODO: JAL-3868 need to know if structure is actually from + // PDB (has valid PDB ID and has provenance suggesting it + // actually came from PDB) + boolean isProtein = false; + for (SequenceI s:sequenceArray) { + if (s.isProtein()) { + isProtein = true; + break; + } + } + isMapUsingSIFTs = isMapUsingSIFTs && pdb.isPPDBIdAvailable() && !pdb.getId().startsWith("AF-") && isProtein; } catch (Exception ex) { @@ -454,8 +511,8 @@ public class StructureSelectionManager implements ApplicationSingletonI } catch (SiftsException e) { isMapUsingSIFTs = false; - Cache.log.error("SIFTS mapping failed", e); - Cache.log.error("Falling back on Needleman & Wunsch alignment"); + Console.error("SIFTS mapping failed", e); + Console.error("Falling back on Needleman & Wunsch alignment"); siftsClient = null; } @@ -562,22 +619,23 @@ public class StructureSelectionManager implements ApplicationSingletonI pdb, maxChain, sqmpping, maxAlignseq, siftsClient); seqToStrucMapping.add(siftsMapping); maxChain.makeExactMapping(siftsMapping, seq); - maxChain.transferRESNUMFeatures(seq, "IEA: SIFTS");// FIXME: is this - // "IEA:SIFTS" ? + maxChain.transferRESNUMFeatures(seq, "IEA: SIFTS", + pdb.getId().toLowerCase(Locale.ROOT)); maxChain.transferResidueAnnotation(siftsMapping, null); ds.addPDBId(maxChain.sequence.getAllPDBEntries().get(0)); } catch (SiftsException e) { // fall back to NW alignment - System.err.println(e.getMessage()); + Console.error(e.getMessage()); StructureMapping nwMapping = getNWMappings(seq, pdbFile, targetChainId, maxChain, pdb, maxAlignseq); seqToStrucMapping.add(nwMapping); maxChain.makeExactMapping(maxAlignseq, seq); - maxChain.transferRESNUMFeatures(seq, "IEA:Jalview"); // FIXME: is - // this - // "IEA:Jalview" ? + maxChain.transferRESNUMFeatures(seq, "IEA:Jalview", + pdb.getId().toLowerCase(Locale.ROOT)); // FIXME: is + // this + // "IEA:Jalview" ? maxChain.transferResidueAnnotation(nwMapping, sqmpping); ds.addPDBId(maxChain.sequence.getAllPDBEntries().get(0)); } @@ -595,7 +653,8 @@ public class StructureSelectionManager implements ApplicationSingletonI siftsClient); foundSiftsMappings.add(siftsMapping); chain.makeExactMapping(siftsMapping, seq); - chain.transferRESNUMFeatures(seq, "IEA: SIFTS");// FIXME: is this + chain.transferRESNUMFeatures(seq, "IEA: SIFTS", + pdb.getId().toLowerCase(Locale.ROOT));// FIXME: is this // "IEA:SIFTS" ? chain.transferResidueAnnotation(siftsMapping, null); } catch (SiftsException e) @@ -620,8 +679,9 @@ public class StructureSelectionManager implements ApplicationSingletonI StructureMapping nwMapping = getNWMappings(seq, pdbFile, maxChainId, maxChain, pdb, maxAlignseq); seqToStrucMapping.add(nwMapping); - maxChain.transferRESNUMFeatures(seq, null); // FIXME: is this - // "IEA:Jalview" ? + maxChain.transferRESNUMFeatures(seq, null, + pdb.getId().toLowerCase(Locale.ROOT)); // FIXME: is this + // "IEA:Jalview" ? maxChain.transferResidueAnnotation(nwMapping, sqmpping); ds.addPDBId(maxChain.sequence.getAllPDBEntries().get(0)); } @@ -676,6 +736,7 @@ public class StructureSelectionManager implements ApplicationSingletonI { ds = ds.getDatasetSequence(); } + ; if (ds.getAnnotation() != null) { for (AlignmentAnnotation ala : ds.getAnnotation()) @@ -787,7 +848,8 @@ public class StructureSelectionManager implements ApplicationSingletonI maxChain.makeExactMapping(maxAlignseq, seq); jalview.datamodel.Mapping sqmpping = maxAlignseq .getMappingFromS1(false); - maxChain.transferRESNUMFeatures(seq, null); + maxChain.transferRESNUMFeatures(seq, null, + pdb.getId().toLowerCase(Locale.ROOT)); HashMap mapping = new HashMap<>(); int resNum = -10000; @@ -929,9 +991,9 @@ public class StructureSelectionManager implements ApplicationSingletonI if (s != null) { result = s; + } } } - } return result; } @@ -1275,39 +1337,43 @@ public class StructureSelectionManager implements ApplicationSingletonI { if (mappings != null) { - mappings.clear(); + mappings.clear(); } if (seqmappings != null) { - seqmappings.clear(); + seqmappings.clear(); } if (sel_listeners != null) { - sel_listeners.clear(); + sel_listeners.clear(); } if (listeners != null) { - listeners.clear(); + listeners.clear(); } if (commandListeners != null) { - commandListeners.clear(); + commandListeners.clear(); } if (view_listeners != null) { - view_listeners.clear(); + view_listeners.clear(); } if (pdbFileNameId != null) { - pdbFileNameId.clear(); + pdbFileNameId.clear(); } if (pdbIdFileName != null) { - pdbIdFileName.clear(); + pdbIdFileName.clear(); } } - public void addSelectionListener(SelectionListener selecter) + public List getListeners() { + return sel_listeners; + } + + public void addSelectionListener(SelectionListener selecter) { if (!sel_listeners.contains(selecter)) { @@ -1355,7 +1421,7 @@ public class StructureSelectionManager implements ApplicationSingletonI { slis.viewPosition(startRes, endRes, startSeq, endSeq, source); } - + ; } } } @@ -1366,12 +1432,11 @@ public class StructureSelectionManager implements ApplicationSingletonI * * @param provider */ - public static void release(StructureSelectionManagerProvider provider) { getInstance().selectionManagers.remove(provider); } - + public void registerPDBEntry(PDBEntry pdbentry) { if (pdbentry.getFile() != null