JAL-1479 JAL- Fix to eradicate duplicate mapping output and further improvement for...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 8 Jun 2016 15:59:23 +0000 (16:59 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 8 Jun 2016 15:59:23 +0000 (16:59 +0100)
src/jalview/gui/AlignViewport.java
src/jalview/gui/StructureChooser.java
src/jalview/structure/StructureSelectionManager.java
src/jalview/ws/sifts/SiftsClient.java

index 692cd18..b1a4fee 100644 (file)
@@ -683,27 +683,42 @@ public class AlignViewport extends AlignmentViewport implements
     List<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
     for (PDBEntry pdb : pdbEntries)
     {
     List<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
     for (PDBEntry pdb : pdbEntries)
     {
-      List<SequenceI> seqs = new ArrayList<SequenceI>();
+      List<SequenceI> choosenSeqs = new ArrayList<SequenceI>();
       for (SequenceI sq : alignment.getSequences())
       {
       for (SequenceI sq : alignment.getSequences())
       {
-        Vector<PDBEntry> pdbs = sq.getDatasetSequence().getAllPDBEntries();
-        if (pdbs == null)
+        Vector<PDBEntry> pdbRefEntries = sq.getDatasetSequence().getAllPDBEntries();
+        if (pdbRefEntries == null)
         {
           continue;
         }
         {
           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()][]);
   }
     }
     return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
   }
@@ -1103,6 +1118,7 @@ public class AlignViewport extends AlignmentViewport implements
    * 
    * @param featureSettings
    */
    * 
    * @param featureSettings
    */
+  @Override
   public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
   {
     if (featureSettings == null)
   public void applyFeaturesStyle(FeatureSettingsModelI featureSettings)
   {
     if (featureSettings == null)
index 6471795..2972c69 100644 (file)
@@ -407,7 +407,6 @@ public class StructureChooser extends GStructureChooser implements
           FTSRestRequest pdbRequest = new FTSRestRequest();
           if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage"))
           {
           FTSRestRequest pdbRequest = new FTSRestRequest();
           if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage"))
           {
-            System.out.println(">>>>>> Filtering with uniprot coverate");
             pdbRequest.setAllowEmptySeq(false);
             pdbRequest.setResponseSize(1);
             pdbRequest.setFieldToSearchBy("(");
             pdbRequest.setAllowEmptySeq(false);
             pdbRequest.setResponseSize(1);
             pdbRequest.setFieldToSearchBy("(");
@@ -862,45 +861,19 @@ public class StructureChooser extends GStructureChooser implements
       ArrayList<SequenceI> seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
       for (SequenceI seq : sequences)
       {
       ArrayList<SequenceI> seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
       for (SequenceI seq : sequences)
       {
-        if (seq.getSourceDBRef() == null)
+        if (seq.getSourceDBRef() == null && seq.getDBRefs() == null)
         {
         {
-          if (seq.getDBRefs() == null)
-          {
             seqsWithoutSourceDBRef.add(seq);
             continue;
           }
             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);
       }
       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" : "")
                 + " 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)
         SequenceI[] seqWithoutSrcDBRef = new SequenceI[y];
         int x = 0;
         for (SequenceI fSeq : seqsWithoutSourceDBRef)
index a5d9736..4dff04d 100644 (file)
@@ -506,17 +506,41 @@ public class StructureSelectionManager
                 .getMappingFromS1(false);
         if (targetChainId != null && !targetChainId.trim().isEmpty())
         {
                 .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
         {
         }
         else
         {
-          for (PDBChain chain : pdb.getChains())
+          try
           {
           {
-            StructureMapping mapping = getStructureMapping(seq, pdbFile,
-                    chain.id, pdb, chain, sqmpping, maxAlignseq);
-            seqToStrucMapping.add(mapping);
+            ArrayList<StructureMapping> tempMapping = new ArrayList<StructureMapping>();
+            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,
   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
       StructureMapping curChainMapping = siftsClient
               .getSiftsStructureMapping(seq, pdbFile, targetChainId);
       try
@@ -565,15 +586,6 @@ public class StructureSelectionManager
         e.printStackTrace();
       }
       return curChainMapping;
         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,
   }
 
   private StructureMapping getNWMappings(SequenceI seq,
index e04bbb7..3c2e703 100644 (file)
@@ -360,7 +360,8 @@ public class SiftsClient implements SiftsClientI
       DBRefEntry[] dbRefs = seq.getDBRefs();
       if (dbRefs == null || dbRefs.length < 1)
       {
       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)
       }
 
       for (DBRefEntryI dbRef : dbRefs)
@@ -374,6 +375,7 @@ public class SiftsClient implements SiftsClientI
                 && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef
                         .getSource().equalsIgnoreCase(DBRefSource.PDB)))
         {
                 && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef
                         .getSource().equalsIgnoreCase(DBRefSource.PDB)))
         {
+          seq.setSourceDBRef(dbRef);
           return dbRef;
         }
       }
           return dbRef;
         }
       }
@@ -413,7 +415,8 @@ public class SiftsClient implements SiftsClientI
                 .getMapRegion();
         for (MapRegion mapRegion : mapRegions)
         {
                 .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<Integer, int[]> mapping = new HashMap<Integer, int[]>();
     DBRefEntryI sourceDBRef = seq.getSourceDBRef();
             jalview.util.Comparison.GapChars, seq.getSequenceAsString());
     HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
     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))
 
     // 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)
   {
 
   private boolean isFoundInSiftsEntry(String accessionId)
   {
+    HashSet<String> siftsDBRefs = getAllMappingAccession();
     return accessionId != null
     return accessionId != null
-            && getAllMappingAccession().contains(accessionId);
+            && siftsDBRefs.contains(accessionId.toLowerCase());
   }
 
   /**
   }
 
   /**