From 8449c7161636af09d658905fe3affbc84fd10150 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Fri, 13 Nov 2015 15:22:22 +0000 Subject: [PATCH] JAL-1479 added transfer of residue annotation for SIFTS mapping, then did some minor house-keeping --- .../structure/StructureSelectionManager.java | 64 +++++++++++------- src/jalview/ws/sifts/SiftsClient.java | 69 +++++++++++++++++--- test/jalview/ws/sifts/SiftsClientTest.java | 4 +- 3 files changed, 103 insertions(+), 34 deletions(-) diff --git a/src/jalview/structure/StructureSelectionManager.java b/src/jalview/structure/StructureSelectionManager.java index 3d5a975..1541a6a 100644 --- a/src/jalview/structure/StructureSelectionManager.java +++ b/src/jalview/structure/StructureSelectionManager.java @@ -328,7 +328,7 @@ public class StructureSelectionManager * * @param sequenceArray * - one or more sequences to be mapped to pdbFile - * @param targetChains + * @param targetChainIds * - optional chain specification for mapping each sequence to pdb * (may be nill, individual elements may be nill) * @param pdbFile @@ -338,7 +338,8 @@ public class StructureSelectionManager * @return null or the structure data parsed as a pdb file */ synchronized public PDBfile setMapping(boolean forStructureView, - SequenceI[] sequenceArray, String[] targetChains, String pdbFile, + SequenceI[] sequenceArray, String[] targetChainIds, + String pdbFile, String protocol) { /* @@ -379,54 +380,60 @@ public class StructureSelectionManager { pdb = new PDBfile(addTempFacAnnot, parseSecStr, secStructServices, pdbFile, protocol); - if (isMapUsingSIFTs) - { - siftsClient = new SiftsClient(pdb); - } + if (pdb.id != null && pdb.id.trim().length() > 0 && AppletFormatAdapter.FILE.equals(protocol)) { registerPDBFile(pdb.id.trim(), pdbFile); } - } catch (SiftsException e) - { - e.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); return null; } - String targetChain; + try + { + if (isMapUsingSIFTs) + { + siftsClient = new SiftsClient(pdb); + } + } catch (SiftsException e) + { + isMapUsingSIFTs = false; + e.printStackTrace(); + } + + String targetChainId; for (int s = 0; s < sequenceArray.length; s++) { boolean infChain = true; final SequenceI seq = sequenceArray[s]; - if (targetChains != null && targetChains[s] != null) + if (targetChainIds != null && targetChainIds[s] != null) { infChain = false; - targetChain = targetChains[s]; + targetChainId = targetChainIds[s]; } else if (seq.getName().indexOf("|") > -1) { - targetChain = seq.getName().substring( + targetChainId = seq.getName().substring( seq.getName().lastIndexOf("|") + 1); - if (targetChain.length() > 1) + if (targetChainId.length() > 1) { - if (targetChain.trim().length() == 0) + if (targetChainId.trim().length() == 0) { - targetChain = " "; + targetChainId = " "; } else { // not a valid chain identifier - targetChain = ""; + targetChainId = ""; } } } else { - targetChain = ""; + targetChainId = ""; } /* @@ -440,7 +447,7 @@ public class StructureSelectionManager boolean first = true; for (PDBChain chain : pdb.chains) { - if (targetChain.length() > 0 && !targetChain.equals(chain.id) + if (targetChainId.length() > 0 && !targetChainId.equals(chain.id) && !infChain) { continue; // don't try to map chains don't match. @@ -456,7 +463,7 @@ public class StructureSelectionManager // as.traceAlignment(); if (first || as.maxscore > max - || (as.maxscore == max && chain.id.equals(targetChain))) + || (as.maxscore == max && chain.id.equals(targetChainId))) { first = false; maxChain = chain; @@ -480,26 +487,35 @@ public class StructureSelectionManager { try { + jalview.datamodel.Mapping sqmpping = maxAlignseq + .getMappingFromS1(false); seqToStrucMapping = new ArrayList(); - if (targetChain != null && !targetChain.trim().isEmpty()) + if (targetChainId != null && !targetChainId.trim().isEmpty()) { - maxChainId = targetChain; StructureMapping curChainMapping = siftsClient - .getSiftsStructureMapping(seq, pdbFile, targetChain); + .getSiftsStructureMapping(seq, pdbFile, targetChainId); seqToStrucMapping.add(curChainMapping); + maxChainId = targetChainId; + PDBChain chain = pdb.findChain(targetChainId); + if (chain != null) + { + chain.transferResidueAnnotation(curChainMapping, sqmpping); + } } else { for (PDBChain chain : pdb.chains) { - maxChainId = chain.id; StructureMapping curChainMapping = siftsClient .getSiftsStructureMapping(seq, pdbFile, chain.id); seqToStrucMapping.add(curChainMapping); + maxChainId = chain.id; + chain.transferResidueAnnotation(curChainMapping, sqmpping); } } } catch (SiftsException e) { + e.printStackTrace(); System.err .println(">>>>>>> SIFTs mapping could not be obtained... Now mapping with NW alignment"); seqToStrucMapping = getNWMappings(seq, pdbFile, maxChainId, diff --git a/src/jalview/ws/sifts/SiftsClient.java b/src/jalview/ws/sifts/SiftsClient.java index 10e14f4..245d38f 100644 --- a/src/jalview/ws/sifts/SiftsClient.java +++ b/src/jalview/ws/sifts/SiftsClient.java @@ -35,6 +35,7 @@ import jalview.xml.binding.sifts.Entry.Entity.Segment; import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion; import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue; import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb; +import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail; import jalview.xml.binding.sifts.Entry.ListDB.Db; import java.io.File; @@ -119,7 +120,24 @@ public class SiftsClient implements SiftsClientI return name; } }; - + + public enum ResidueDetailType + { + NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE( + "codeSecondaryStructure"), ANNOTATION("Annotation"); + private String code; + + private ResidueDetailType(String code) + { + this.code = code; + } + + public String getCode() + { + return code; + } + }; + /** * Fetch SIFTs file for the given PDB Id and construct an instance of * SiftsClient @@ -175,20 +193,24 @@ public class SiftsClient implements SiftsClientI } catch (JAXBException e) { e.printStackTrace(); + throw new SiftsException(e.getMessage()); } catch (FileNotFoundException e) { e.printStackTrace(); + throw new SiftsException(e.getMessage()); } catch (XMLStreamException e) { e.printStackTrace(); + throw new SiftsException(e.getMessage()); } catch (FactoryConfigurationError e) { e.printStackTrace(); + throw new SiftsException(e.getMessage()); } catch (IOException e) { e.printStackTrace(); + throw new SiftsException(e.getMessage()); } - throw new SiftsException("Error parsing siftFile"); } /** @@ -196,8 +218,9 @@ public class SiftsClient implements SiftsClientI * * @param pdbId * @return SIFTs XML file + * @throws SiftsException */ - public static File getSiftsFile(String pdbId) + public static File getSiftsFile(String pdbId) throws SiftsException { File siftsFile = new File(SIFTS_DOWNLOAD_DIR + pdbId.toLowerCase() + ".xml.gz"); @@ -218,8 +241,9 @@ public class SiftsClient implements SiftsClientI * * @param pdbId * @return downloaded SIFTs XML file + * @throws SiftsException */ - public static File downloadSiftsFile(String pdbId) + public static File downloadSiftsFile(String pdbId) throws SiftsException { String siftFile = pdbId + ".xml.gz"; String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile; @@ -248,7 +272,7 @@ public class SiftsClient implements SiftsClientI System.out.println(">>> File downloaded : " + downloadedSiftsFile); } catch (IOException ex) { - ex.printStackTrace(); + throw new SiftsException(ex.getMessage()); } return new File(downloadedSiftsFile); } @@ -401,7 +425,6 @@ public class SiftsClient implements SiftsClientI java.io.PrintStream os) throws SiftsException { - System.out.println("Generating mappings for : " + entityId); Entity entity = null; entity = getEntityById(entityId); @@ -439,7 +462,6 @@ public class SiftsClient implements SiftsClientI residuePos[PDB_RES_POS] = UNASSIGNED; residuePos[PDB_ATOM_POS] = UNASSIGNED; } - TreeMap resNumMap = new TreeMap(); List segments = entity.getSegment(); for (Segment segment : segments) @@ -492,7 +514,8 @@ public class SiftsClient implements SiftsClientI } try { - mapping[currSeqIndex][PDB_RES_POS] = Integer.valueOf(resNum); + mapping[currSeqIndex][PDB_RES_POS] = Integer + .valueOf(resNum); } catch (ArrayIndexOutOfBoundsException e) { // do nothing.. @@ -573,6 +596,36 @@ public class SiftsClient implements SiftsClientI return mapping; } + private boolean isResidueObserved(Residue residue) + { + String annotation = getResidueAnnotaiton(residue, + ResidueDetailType.ANNOTATION); + if (annotation == null) + { + return true; + } + if (!annotation.equalsIgnoreCase("Not_Found") + && annotation.equalsIgnoreCase("Not_Observed")) + { + return false; + } + return true; + } + + private String getResidueAnnotaiton(Residue residue, + ResidueDetailType type) + { + List resDetails = residue.getResidueDetail(); + for (ResidueDetail resDetail : resDetails) + { + if (resDetail.getProperty().equalsIgnoreCase(type.getCode())) + { + return resDetail.getContent(); + } + } + return "Not_Found"; + } + private boolean hasAccessionId(String accession) { boolean isStrictMatch = true; diff --git a/test/jalview/ws/sifts/SiftsClientTest.java b/test/jalview/ws/sifts/SiftsClientTest.java index 4c94f66..4a57a88 100644 --- a/test/jalview/ws/sifts/SiftsClientTest.java +++ b/test/jalview/ws/sifts/SiftsClientTest.java @@ -107,7 +107,7 @@ public class SiftsClientTest } @Test(groups = { "Functional" }) - public void getSIFTsFileTest() + public void getSIFTsFileTest() throws SiftsException { Assert.assertTrue(SiftsClient.deleteSiftsFileByPDBId(testPDBId)); SiftsClient.getSiftsFile(testPDBId); @@ -121,7 +121,7 @@ public class SiftsClientTest } @Test(groups = { "Functional" }) - public void downloadSiftsFileTest() + public void downloadSiftsFileTest() throws SiftsException { // Assert that file isn't yet downloaded - if already downloaded, assert it // is deleted -- 1.7.10.2