Merge branch 'develop' into features/JAL-2110_makeSenseOfCrossRef
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 9 Jun 2016 13:53:10 +0000 (14:53 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 9 Jun 2016 13:53:10 +0000 (14:53 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/gui/StructureChooser.java
src/jalview/structure/StructureSelectionManager.java
src/jalview/structures/models/AAStructureBindingModel.java
src/jalview/util/DnaUtils.java
src/jalview/ws/sifts/SiftsClient.java

index 477d113..39e4bcd 100644 (file)
@@ -1326,10 +1326,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     else
     {
       alignmentToExport = viewport.getAlignment();
-      alignmentStartEnd = viewport.getAlignment()
-              .getVisibleStartAndEndIndex(
-                      viewport.getColumnSelection().getHiddenColumns());
     }
+    alignmentStartEnd = alignmentToExport
+            .getVisibleStartAndEndIndex(viewport.getColumnSelection()
+                    .getHiddenColumns());
     AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
             omitHidden, alignmentStartEnd, settings);
     return ed;
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> seqs = new ArrayList<SequenceI>();
+      List<SequenceI> choosenSeqs = new ArrayList<SequenceI>();
       for (SequenceI sq : alignment.getSequences())
       {
-        Vector<PDBEntry> pdbs = sq.getDatasetSequence().getAllPDBEntries();
-        if (pdbs == null)
+        Vector<PDBEntry> 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)
index 46731e9..2972c69 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+", "+");
   }
 
 
@@ -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("(");
@@ -732,17 +731,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 +858,29 @@ public class StructureChooser extends GStructureChooser implements
 
     if (SiftsSettings.isMapWithSifts())
     {
+      ArrayList<SequenceI> seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
       for (SequenceI seq : sequences)
       {
-        if (seq.getSourceDBRef() == null)
+        if (seq.getSourceDBRef() == null && seq.getDBRefs() == null)
         {
-          ssm.setProgressBar(null);
-          ssm.setProgressBar("Fetching Database refs..");
-          new DBRefFetcher(sequences).fetchDBRefs(true);
-          break;
+            seqsWithoutSourceDBRef.add(seq);
+            continue;
+          }
+      }
+      if (!seqsWithoutSourceDBRef.isEmpty())
+      {
+        int y = seqsWithoutSourceDBRef.size();
+        ssm.setProgressBar(null);
+        ssm.setProgressBar("Fetching db refs for " + y
+                + " sequence" + (y > 1 ? "s" : "")
+                + " without valid db ref required 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)
index a5d9736..4dff04d 100644 (file)
@@ -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<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,
-          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,
index 42fbfa9..dc42315 100644 (file)
@@ -598,6 +598,10 @@ public abstract class AAStructureBindingModel extends
       for (String file : files)
       {
         notLoaded = file;
+        if (file == null)
+        {
+          continue;
+        }
         try
         {
           StructureMapping[] sm = getSsm().getMapping(file);
index f6514e5..9ab4fda 100644 (file)
@@ -35,15 +35,14 @@ public class DnaUtils
 
     /*
      * try to parse m..n (or simply m)
-     * also handles <m..n or m..>n (discarding < or >)
      */
     String[] range = location.split("\\.\\.");
     if (range.length == 1 || range.length == 2)
     {
       try
       {
-        int start = parseRangeEnd(range[0]);
-        int end = range.length == 1 ? start : parseRangeEnd(range[1]);
+        int start = Integer.valueOf(range[0]);
+        int end = range.length == 1 ? start : Integer.valueOf(range[1]);
         return Collections.singletonList(new int[] { start, end });
       } catch (NumberFormatException e)
       {
@@ -65,22 +64,6 @@ public class DnaUtils
   }
 
   /**
-   * Returns the integer value of a locus, discarding any < or > prefix
-   * 
-   * @throws NumberFormatException
-   *           if value is not numeric
-   */
-  static int parseRangeEnd(String loc)
-  {
-
-    if (loc.startsWith("<") || loc.startsWith(">"))
-    {
-      loc = loc.substring(1);
-    }
-    return Integer.valueOf(loc);
-  }
-
-  /**
    * Parses a complement(locationSpec) into a list of start-end ranges
    * 
    * @param location
index e04bbb7..3c2e703 100644 (file)
@@ -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<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))
@@ -752,8 +752,9 @@ public class SiftsClient implements SiftsClientI
 
   private boolean isFoundInSiftsEntry(String accessionId)
   {
+    HashSet<String> siftsDBRefs = getAllMappingAccession();
     return accessionId != null
-            && getAllMappingAccession().contains(accessionId);
+            && siftsDBRefs.contains(accessionId.toLowerCase());
   }
 
   /**