more iterators out; some time checks
authorhansonr <hansonr@STO24954W.ad.stolaf.edu>
Tue, 29 Jan 2019 02:01:45 +0000 (20:01 -0600)
committerhansonr <hansonr@STO24954W.ad.stolaf.edu>
Tue, 29 Jan 2019 02:01:45 +0000 (20:01 -0600)
src/jalview/ext/ensembl/EnsemblRestClient.java
src/jalview/ext/ensembl/EnsemblSeqProxy.java
src/jalview/gui/Desktop.java
src/jalview/util/Platform.java

index da9d2e5..bef1db0 100644 (file)
@@ -501,17 +501,17 @@ boolean checkEnsembl()
        if (url == null)
           url = getUrl(ids);
        
-//     Platform.timeCheck("EnsembleRestClient.getJSON0 " + url, Platform.TIME_MARK);
-       
        Reader br = null;
        try {
+
+         Platform.timeCheck(null, Platform.TIME_MARK);
+               
       br = (url == null ? null : getHttpResponse(url, ids, msDelay));
 
-//      Platform.timeCheck("EnsembleRestClient.getJSON1 parsing... ", Platform.TIME_MARK);
-       
       Object ret = (br == null ? null : JSONUtils.parse(br));
 
-//      Platform.timeCheck("EnsembleRestClient.getJSON2 ...done ", Platform.TIME_MARK);
+         Platform.timeCheck("EnsembleRestClient.getJSON " + url, Platform.TIME_MARK);
+       
 
       if (ret != null && mapKey != null)
            ret = ((Map<String, Object>) ret).get(mapKey);
index a558ad2..fb01708 100644 (file)
@@ -171,14 +171,15 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
      * fetch and transfer genomic sequence features,
      * fetch protein product and add as cross-reference
      */
-    for (String accId : allIds)
+    for (int i = 0, n = allIds.size(); i < n; i++) 
     {
-      addFeaturesAndProduct(accId, alignment);
+      addFeaturesAndProduct(allIds.get(i), alignment);
     }
 
-    for (SequenceI seq : alignment.getSequences())
+    List<SequenceI> seqs = alignment.getSequences();
+    for (int i = 0, n = seqs.size(); i < n; i++)
     {
-      getCrossReferences(seq);
+      getCrossReferences(seqs.get(i));
     }
 
     return alignment;
@@ -209,12 +210,19 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       SequenceI genomicSequence = null;
       EnsemblFeatures gffFetcher = new EnsemblFeatures(getDomain());
       EnsemblFeatureType[] features = getFeaturesToFetch();      
+      
+      Platform.timeCheck("ESP.getsequencerec1", Platform.TIME_MARK);     
+
+      
       AlignmentI geneFeatures = gffFetcher.getSequenceRecords(accId,
               features);
       if (geneFeatures != null && geneFeatures.getHeight() > 0)
       {
         genomicSequence = geneFeatures.getSequenceAt(0);
       }
+      
+      Platform.timeCheck("ESP.getsequencerec2", Platform.TIME_MARK);     
+      
       if (genomicSequence != null)
       {
         /*
@@ -228,6 +236,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
            * fetch and map protein product, and add it as a cross-reference
            * of the retrieved sequence
            */
+            Platform.timeCheck("ESP.transferFeatures", Platform.TIME_MARK);      
           addProteinProduct(querySeq);
         }
       }
@@ -236,6 +245,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       System.err.println(
               "Error transferring Ensembl features: " + e.getMessage());
     }
+    Platform.timeCheck("ESP.addfeat done", Platform.TIME_MARK);          
   }
 
   /**
@@ -348,28 +358,47 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
    */
   protected void getCrossReferences(SequenceI seq)
   {
+         
+      Platform.timeCheck("ESP. getdataseq ", Platform.TIME_MARK);        
+
+         
     while (seq.getDatasetSequence() != null)
     {
       seq = seq.getDatasetSequence();
     }
+
+    Platform.timeCheck("ESP. getxref ", Platform.TIME_MARK);     
+
     EnsemblXref xrefFetcher = new EnsemblXref(getDomain(), getDbSource(),
             getEnsemblDataVersion());
     List<DBRefEntry> xrefs = xrefFetcher.getCrossReferences(seq.getName());
     
     for (int i = 0, n = xrefs.size(); i < n; i++)
     {
+//        Platform.timeCheck("ESP. getxref + " + (i) + "/" + n, Platform.TIME_MARK);     
         // BH 2019.01.25 this next method was taking 174 ms PER addition for a 266-reference example.
         //    DBRefUtils.ensurePrimaries(seq) 
         //        was at the end of seq.addDBRef, so executed after ever addition!
         //        This method was moved to     seq.getPrimaryDBRefs()
       seq.addDBRef(xrefs.get(i));
     }
+
+//    System.out.println("primaries are " + seq.getPrimaryDBRefs().toString());
     /*
      * and add a reference to itself
      */
+    
+//    Platform.timeCheck("ESP. getxref self ", Platform.TIME_MARK);      
+
     DBRefEntry self = new DBRefEntry(getDbSource(), getEnsemblDataVersion(),
     seq.getName());
+
+//    Platform.timeCheck("ESP. getxref self add ", Platform.TIME_MARK);          
+
     seq.addDBRef(self);
+    
+    Platform.timeCheck("ESP. seqprox done ", Platform.TIME_MARK);        
+
   }
 
   /**
@@ -390,6 +419,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       inProgress = false;
       throw new JalviewException("ENSEMBL Rest API not available.");
     }
+       Platform.timeCheck("EnsemblSeqProx.fetchSeq ", Platform.TIME_MARK);
+
     List<SequenceI> seqs = parseSequenceJson(ids);
     if (seqs == null)
        return alignment;
@@ -455,6 +486,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
        * for now, assumes only one sequence returned; refactor if needed
        * in future to handle a JSONArray with more than one
        */
+       
+       Platform.timeCheck("ENS seqproxy", Platform.TIME_MARK);
       Map<String, Object> val = (Map<String, Object>) getJSON(null, ids, -1, MODE_MAP, null);
       if (val == null)
          return null;
@@ -480,6 +513,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       System.err.println("Error processing JSON response: " + e.toString());
       // ignore
     }
+       Platform.timeCheck("ENS seqproxy2", Platform.TIME_MARK);
     return result;
   }
 
@@ -659,7 +693,9 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
    */
   protected abstract List<SequenceFeature> getIdentifyingFeatures(
           SequenceI seq, String accId);
-
+  
+  int bhtest = 0;
+  
   /**
    * Transfers the sequence feature to the target sequence, locating its start
    * and end range based on the mapping. Features which do not overlap the
@@ -681,6 +717,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
 
     if (mappedRange != null)
     {
+//      Platform.timeCheck(null, Platform.TIME_SET);
       String group = sf.getFeatureGroup();
       if (".".equals(group))
       {
@@ -688,8 +725,11 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       }
       int newBegin = Math.min(mappedRange[0], mappedRange[1]);
       int newEnd = Math.max(mappedRange[0], mappedRange[1]);
-      SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd,
-              group, sf.getScore());
+//      Platform.timeCheck(null, Platform.TIME_MARK);
+      bhtest++;
+      // 280 ms/1000 here:
+      SequenceFeature copy = new SequenceFeature(sf, newBegin, newEnd, group, sf.getScore());
+      // 0.175 ms here:
       targetSequence.addSequenceFeature(copy);
 
       /*
@@ -794,10 +834,14 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
     MapList mapping = getGenomicRangesFromFeatures(sourceSequence,
             accessionId, targetSequence.getStart());
     if (mapping == null)
-    {
+    { 
       return false;
     }
 
+
+    Platform.timeCheck("ESP. xfer " + sfs.size(), Platform.TIME_MARK);   
+
+
     boolean result = transferFeatures(sfs, targetSequence, mapping,
             accessionId);
 //    System.out.println("transferFeatures (" + (sfs.size()) + " --> "
@@ -831,14 +875,23 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
     SequenceFeatures.sortFeatures(sfs, forwardStrand);
 
     boolean transferred = false;
-    for (SequenceFeature sf : sfs)
+    
+    for (int i = 0, n = sfs.size(); i < n; i++)
     {
+
+       if ((i%1000) == 0) {
+//         Platform.timeCheck("Feature " + bhtest, Platform.TIME_GET);
+       Platform.timeCheck("ESP. xferFeature + " + (i) + "/" + n, Platform.TIME_MARK);    
+       }
+
+      SequenceFeature sf = sfs.get(i);
       if (retainFeature(sf, parentId))
       {
         transferFeature(sf, targetSequence, mapping, forwardStrand);
         transferred = true;
       }
     }
+
     return transferred;
   }
 
index a50a2e6..30c37de 100644 (file)
@@ -2801,6 +2801,8 @@ public class Desktop extends jalview.jbgui.GDesktop
   @Override
   public void setProgressBar(String message, long id)
   {
+           Platform.timeCheck("Desktop " + message, Platform.TIME_MARK);     
+
     if (progressBars == null)
     {
       progressBars = new Hashtable<>();
index 286ded1..0b9185c 100644 (file)
@@ -201,21 +201,37 @@ public class Platform
   
   public final static int TIME_RESET = 0;
   public final static int TIME_MARK  = 1;
+  public static final int TIME_SET   = 2;
+  public static final int TIME_GET   = 3;
   
-  public static long time, mark;
+  public static long time, mark, set, duration;
   
   public static void timeCheck(String msg, int mode) {
+         long t = System.currentTimeMillis();
          switch (mode) {
          case TIME_RESET:
-                 time = mark = System.currentTimeMillis();
-                 System.err.println("Platform: timer reset\t\t\t" + msg);
+                 time = mark = t;
+                 if (msg != null)
+                         System.err.println("Platform: timer reset\t\t\t" + msg);
                  break;
          case TIME_MARK:
-                 long t = System.currentTimeMillis();
-                 if (time == 0)
-                         time = mark = t;
-                 System.err.println("Platform: timer mark\t" + ((t - time)/1000f) + "\t" + ((t - mark)/1000f) + "\t" + msg);
-                 mark = t;
+                 if (set > 0) {
+                         duration += (t - set);
+                 } else {
+                         if (time == 0)
+                                 time = mark = t;
+                         if (msg != null)
+                                 System.err.println("Platform: timer mark\t" + ((t - time)/1000f) + "\t" + ((t - mark)/1000f) + "\t" + msg);
+                         mark = t;
+                 }
+                 break;
+         case TIME_SET:
+                 set = t;
+                 break;
+         case TIME_GET:
+                 if (msg != null)
+                         System.err.println("Platform: timer dur\t" + ((t - time)/1000f) + "\t" + ((duration)/1000f) + "\t" + msg);
+                 set = 0;
                  break;
          }
   }