JAL-1919, JAL-1960 fix to disable refetching dbrefs when viewing structures
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 6 Jun 2016 13:49:31 +0000 (14:49 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Mon, 6 Jun 2016 13:49:31 +0000 (14:49 +0100)
src/jalview/gui/StructureChooser.java

index 46731e9..6471795 100644 (file)
@@ -331,8 +331,8 @@ public class StructureChooser extends GStructureChooser implements
   }
 
   /**
-   * Remove the following special characters from input string +, -, &, |, !, (,
-   * ), {, }, [, ], ^, ", ~, *, ?, :, \
+   * Remove the following special characters from input string +, -, &, !, (, ),
+   * {, }, [, ], ^, ", ~, *, ?, :, \
    * 
    * @param seqName
    * @return
@@ -341,7 +341,7 @@ public class StructureChooser extends GStructureChooser implements
   {
     Objects.requireNonNull(seqName);
     return seqName.replaceAll("\\[\\d*\\]", "")
-            .replaceAll("[^\\dA-Za-z|]", "").replaceAll("\\s+", "+");
+            .replaceAll("[^\\dA-Za-z|_]", "").replaceAll("\\s+", "+");
   }
 
 
@@ -732,17 +732,17 @@ public class StructureChooser extends GStructureChooser implements
     {
           int pdbIdColIndex = tbl_summary.getColumn("PDB Id")
                   .getModelIndex();
-      int refSeqColIndex = tbl_summary.getColumn("Ref Sequence")
+          int refSeqColIndex = tbl_summary.getColumn("Ref Sequence")
               .getModelIndex();
-      int[] selectedRows = tbl_summary.getSelectedRows();
+          int[] selectedRows = tbl_summary.getSelectedRows();
       PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
       int count = 0;
       ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
       for (int row : selectedRows)
       {
-        String pdbIdStr = tbl_summary.getValueAt(row, pdbIdColIndex)
+            String pdbIdStr = tbl_summary.getValueAt(row, pdbIdColIndex)
                 .toString();
-        SequenceI selectedSeq = (SequenceI) tbl_summary.getValueAt(row,
+            SequenceI selectedSeq = (SequenceI) tbl_summary.getValueAt(row,
                 refSeqColIndex);
         selectedSeqsToView.add(selectedSeq);
             PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
@@ -859,15 +859,55 @@ public class StructureChooser extends GStructureChooser implements
 
     if (SiftsSettings.isMapWithSifts())
     {
+      ArrayList<SequenceI> seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
       for (SequenceI seq : sequences)
       {
         if (seq.getSourceDBRef() == null)
         {
-          ssm.setProgressBar(null);
-          ssm.setProgressBar("Fetching Database refs..");
-          new DBRefFetcher(sequences).fetchDBRefs(true);
-          break;
+          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
+                + " sequence" + (y > 1 ? "s" : "")
+                + " with no valid uniprot or pdb ref for SIFTS mapping");
+        SequenceI[] seqWithoutSrcDBRef = new SequenceI[y];
+        int x = 0;
+        for (SequenceI fSeq : seqsWithoutSourceDBRef)
+        {
+          seqWithoutSrcDBRef[x++] = fSeq;
         }
+        new DBRefFetcher(seqWithoutSrcDBRef).fetchDBRefs(true);
       }
     }
     if (pdbEntriesToView.length > 1)