From 4316d20b437d529be1d9ddafc0118fadd1b6a4ce Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Wed, 8 Jun 2016 16:59:23 +0100 Subject: [PATCH] JAL-1479 JAL- Fix to eradicate duplicate mapping output and further improvement for DBRef re-fetching and matching issue --- src/jalview/gui/AlignViewport.java | 34 +++++++++---- src/jalview/gui/StructureChooser.java | 33 ++----------- .../structure/StructureSelectionManager.java | 52 ++++++++++++-------- src/jalview/ws/sifts/SiftsClient.java | 19 +++---- 4 files changed, 70 insertions(+), 68 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 692cd18..b1a4fee 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -683,27 +683,42 @@ public class AlignViewport extends AlignmentViewport implements List seqvectors = new ArrayList(); for (PDBEntry pdb : pdbEntries) { - List seqs = new ArrayList(); + List choosenSeqs = new ArrayList(); for (SequenceI sq : alignment.getSequences()) { - Vector pdbs = sq.getDatasetSequence().getAllPDBEntries(); - if (pdbs == null) + Vector pdbRefEntries = sq.getDatasetSequence().getAllPDBEntries(); + if (pdbRefEntries == null) { continue; } - for (PDBEntry p1 : pdbs) + for (PDBEntry pdbRefEntry : pdbRefEntries) { - if (p1.getId().equals(pdb.getId())) + if (pdbRefEntry.getId().equals(pdb.getId())) { - if (!seqs.contains(sq)) + if (pdbRefEntry.getChainCode() != null + && pdb.getChainCode() != null) { - seqs.add(sq); - continue; + if (pdbRefEntry.getChainCode().equalsIgnoreCase( + pdb.getChainCode()) + && !choosenSeqs.contains(sq)) + { + choosenSeqs.add(sq); + continue; + } } + else + { + if (!choosenSeqs.contains(sq)) + { + choosenSeqs.add(sq); + continue; + } + } + } } } - seqvectors.add(seqs.toArray(new SequenceI[seqs.size()])); + seqvectors.add(choosenSeqs.toArray(new SequenceI[choosenSeqs.size()])); } return seqvectors.toArray(new SequenceI[seqvectors.size()][]); } @@ -1103,6 +1118,7 @@ public class AlignViewport extends AlignmentViewport implements * * @param featureSettings */ + @Override public void applyFeaturesStyle(FeatureSettingsModelI featureSettings) { if (featureSettings == null) diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 6471795..2972c69 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -407,7 +407,6 @@ public class StructureChooser extends GStructureChooser implements FTSRestRequest pdbRequest = new FTSRestRequest(); if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage")) { - System.out.println(">>>>>> Filtering with uniprot coverate"); pdbRequest.setAllowEmptySeq(false); pdbRequest.setResponseSize(1); pdbRequest.setFieldToSearchBy("("); @@ -862,45 +861,19 @@ public class StructureChooser extends GStructureChooser implements ArrayList seqsWithoutSourceDBRef = new ArrayList(); for (SequenceI seq : sequences) { - if (seq.getSourceDBRef() == null) + if (seq.getSourceDBRef() == null && seq.getDBRefs() == null) { - if (seq.getDBRefs() == null) - { seqsWithoutSourceDBRef.add(seq); continue; } - for (DBRefEntry dbRef : seq.getDBRefs()) - { - if (dbRef.getSource().equalsIgnoreCase("uniprot")) - { - seq.setSourceDBRef(dbRef); - break; - } - } - for (DBRefEntry dbRef : seq.getDBRefs()) - { - if (dbRef.getSource().equalsIgnoreCase("pdb")) - { - seq.setSourceDBRef(dbRef); - break; - } - } - if (seq.getSourceDBRef() == null) - { - seqsWithoutSourceDBRef.add(seq); - } - } } if (!seqsWithoutSourceDBRef.isEmpty()) { int y = seqsWithoutSourceDBRef.size(); ssm.setProgressBar(null); - ssm.setProgressBar(">>>>> Fetching Database refs for " + y - + " sequence" + (y > 1 ? "s" : "") - + " with no valid uniprot or pdb ref for SIFTS mapping"); - System.out.println(">>>>> Fetching Database refs for " + y + ssm.setProgressBar("Fetching db refs for " + y + " sequence" + (y > 1 ? "s" : "") - + " with no valid uniprot or pdb ref for SIFTS mapping"); + + " without valid db ref required for SIFTS mapping"); SequenceI[] seqWithoutSrcDBRef = new SequenceI[y]; int x = 0; for (SequenceI fSeq : seqsWithoutSourceDBRef) diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index a5d9736..4dff04d 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -506,17 +506,41 @@ public class StructureSelectionManager .getMappingFromS1(false); if (targetChainId != null && !targetChainId.trim().isEmpty()) { - StructureMapping mapping = getStructureMapping(seq, pdbFile, - targetChainId, pdb, maxChain, sqmpping, maxAlignseq); - seqToStrucMapping.add(mapping); + StructureMapping mapping; + try + { + mapping = getStructureMapping(seq, pdbFile, targetChainId, pdb, + maxChain, sqmpping, maxAlignseq); + seqToStrucMapping.add(mapping); + } catch (SiftsException e) + { + // e.printStackTrace(); + // fall back to NW alignment + System.err.println(e.getMessage()); + seqToStrucMapping.add(getNWMappings(seq, pdbFile, + targetChainId, + maxChain, pdb, maxAlignseq)); + } } else { - for (PDBChain chain : pdb.getChains()) + try { - StructureMapping mapping = getStructureMapping(seq, pdbFile, - chain.id, pdb, chain, sqmpping, maxAlignseq); - seqToStrucMapping.add(mapping); + ArrayList tempMapping = new ArrayList(); + for (PDBChain chain : pdb.getChains()) + { + StructureMapping mapping = getStructureMapping(seq, pdbFile, + chain.id, pdb, chain, sqmpping, maxAlignseq); + tempMapping.add(mapping); + } + seqToStrucMapping.addAll(tempMapping); + } catch (SiftsException e) + { + // e.printStackTrace(); + // fall back to NW alignment + System.err.println(e.getMessage()); + seqToStrucMapping.add(getNWMappings(seq, pdbFile, maxChainId, + maxChain, pdb, maxAlignseq)); } } } @@ -546,11 +570,8 @@ public class StructureSelectionManager private StructureMapping getStructureMapping(SequenceI seq, String pdbFile, String targetChainId, StructureFile pdb, PDBChain maxChain, jalview.datamodel.Mapping sqmpping, - AlignSeq maxAlignseq) + AlignSeq maxAlignseq) throws SiftsException { - String maxChainId = targetChainId; - try - { StructureMapping curChainMapping = siftsClient .getSiftsStructureMapping(seq, pdbFile, targetChainId); try @@ -565,15 +586,6 @@ public class StructureSelectionManager e.printStackTrace(); } return curChainMapping; - } catch (SiftsException e) - { - System.err.println(e.getMessage()); - System.err.println(">>> Now switching mapping with NW alignment..."); - setProgressBar(null); - setProgressBar(">>> Now switching mapping with NW alignment..."); - return getNWMappings(seq, pdbFile, maxChainId, maxChain, pdb, - maxAlignseq); - } } private StructureMapping getNWMappings(SequenceI seq, diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index e04bbb7..3c2e703 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -360,7 +360,8 @@ public class SiftsClient implements SiftsClientI DBRefEntry[] dbRefs = seq.getDBRefs(); if (dbRefs == null || dbRefs.length < 1) { - throw new SiftsException("Could not get source DB Ref"); + throw new SiftsException( + "Source DBRef could not be determined. DBRefs might not have been retrieved."); } for (DBRefEntryI dbRef : dbRefs) @@ -374,6 +375,7 @@ public class SiftsClient implements SiftsClientI && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef .getSource().equalsIgnoreCase(DBRefSource.PDB))) { + seq.setSourceDBRef(dbRef); return dbRef; } } @@ -413,7 +415,8 @@ public class SiftsClient implements SiftsClientI .getMapRegion(); for (MapRegion mapRegion : mapRegions) { - accessions.add(mapRegion.getDb().getDbAccessionId()); + accessions + .add(mapRegion.getDb().getDbAccessionId().toLowerCase()); } } } @@ -464,12 +467,9 @@ public class SiftsClient implements SiftsClientI jalview.util.Comparison.GapChars, seq.getSequenceAsString()); HashMap mapping = new HashMap(); DBRefEntryI sourceDBRef = seq.getSourceDBRef(); - if (sourceDBRef == null) - { - sourceDBRef = getValidSourceDBRef(seq); - // TODO ensure sequence start/end is in the same coordinate system and - // consistent with the choosen sourceDBRef - } + sourceDBRef = getValidSourceDBRef(seq); + // TODO ensure sequence start/end is in the same coordinate system and + // consistent with the choosen sourceDBRef // set sequence coordinate system - default value is UniProt if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB)) @@ -752,8 +752,9 @@ public class SiftsClient implements SiftsClientI private boolean isFoundInSiftsEntry(String accessionId) { + HashSet siftsDBRefs = getAllMappingAccession(); return accessionId != null - && getAllMappingAccession().contains(accessionId); + && siftsDBRefs.contains(accessionId.toLowerCase()); } /** -- 1.7.10.2