JAL-1479 added transfer of residue annotation for SIFTS mapping, then did some minor...
[jalview.git] / src / jalview / ws / sifts / SiftsClient.java
index 10e14f4..245d38f 100644 (file)
@@ -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<Integer, String> resNumMap = new TreeMap<Integer, String>();
     List<Segment> 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<ResidueDetail> 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;