JAL-2738 copy to spikes/mungo
[jalview.git] / src / jalview / ext / ensembl / EnsemblSeqProxy.java
index 79d6c0a..35ceea3 100644 (file)
@@ -34,6 +34,7 @@ import jalview.datamodel.features.SequenceFeatures;
 import jalview.exceptions.JalviewException;
 import jalview.io.FastaFile;
 import jalview.io.FileParse;
+import jalview.io.gff.Gff3Helper;
 import jalview.io.gff.SequenceOntologyFactory;
 import jalview.io.gff.SequenceOntologyI;
 import jalview.util.Comparison;
@@ -59,8 +60,6 @@ import java.util.Map.Entry;
  */
 public abstract class EnsemblSeqProxy extends EnsemblRestClient
 {
-  private static final String ALLELES = "alleles";
-
   protected static final String PARENT = "Parent";
 
   protected static final String ID = "ID";
@@ -139,8 +138,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
 
     // danger: accession separator used as a regex here, a string elsewhere
     // in this case it is ok (it is just a space), but (e.g.) '\' would not be
-    List<String> allIds = Arrays.asList(query
-            .split(getAccessionSeparator()));
+    List<String> allIds = Arrays
+            .asList(query.split(getAccessionSeparator()));
     AlignmentI alignment = null;
     inProgress = true;
 
@@ -238,8 +237,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       }
     } catch (IOException e)
     {
-      System.err.println("Error transferring Ensembl features: "
-              + e.getMessage());
+      System.err.println(
+              "Error transferring Ensembl features: " + e.getMessage());
     }
   }
 
@@ -277,8 +276,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       proteinSeq.createDatasetSequence();
       querySeq.createDatasetSequence();
 
-      MapList mapList = AlignmentUtils
-              .mapCdsToProtein(querySeq, proteinSeq);
+      MapList mapList = AlignmentUtils.mapCdsToProtein(querySeq,
+              proteinSeq);
       if (mapList != null)
       {
         // clunky: ensure Uniprot xref if we have one is on mapped sequence
@@ -289,9 +288,11 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
                 getEnsemblDataVersion(), proteinSeq.getName(), map);
         querySeq.getDatasetSequence().addDBRef(dbr);
         DBRefEntry[] uprots = DBRefUtils.selectRefs(ds.getDBRefs(),
-                new String[] { DBRefSource.UNIPROT });
+                new String[]
+                { DBRefSource.UNIPROT });
         DBRefEntry[] upxrefs = DBRefUtils.selectRefs(querySeq.getDBRefs(),
-                new String[] { DBRefSource.UNIPROT });
+                new String[]
+                { DBRefSource.UNIPROT });
         if (uprots != null)
         {
           for (DBRefEntry up : uprots)
@@ -306,8 +307,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
 
               if (upx.size() > 1)
               {
-                Cache.log
-                        .warn("Implementation issue - multiple uniprot acc on product sequence.");
+                Cache.log.warn(
+                        "Implementation issue - multiple uniprot acc on product sequence.");
               }
             }
             else
@@ -332,8 +333,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
          * copy exon features to protein, compute peptide variants from dna 
          * variants and add as features on the protein sequence ta-da
          */
-        AlignmentUtils
-                .computeProteinFeatures(querySeq, proteinSeq, mapList);
+        AlignmentUtils.computeProteinFeatures(querySeq, proteinSeq,
+                mapList);
       }
     } catch (Exception e)
     {
@@ -366,8 +367,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
     /*
      * and add a reference to itself
      */
-    DBRefEntry self = new DBRefEntry(getDbSource(),
-            getEnsemblDataVersion(), seq.getName());
+    DBRefEntry self = new DBRefEntry(getDbSource(), getEnsemblDataVersion(),
+            seq.getName());
     seq.addDBRef(self);
   }
 
@@ -381,8 +382,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
    * @throws JalviewException
    * @throws IOException
    */
-  protected AlignmentI fetchSequences(List<String> ids, AlignmentI alignment)
-          throws JalviewException, IOException
+  protected AlignmentI fetchSequences(List<String> ids,
+          AlignmentI alignment) throws JalviewException, IOException
   {
     if (!isEnsemblAvailable())
     {
@@ -398,15 +399,15 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
     FastaFile fr = new FastaFile(fp);
     if (fr.hasWarningMessage())
     {
-      System.out.println(String.format(
-              "Warning when retrieving %d ids %s\n%s", ids.size(),
-              ids.toString(), fr.getWarningMessage()));
+      System.out.println(
+              String.format("Warning when retrieving %d ids %s\n%s",
+                      ids.size(), ids.toString(), fr.getWarningMessage()));
     }
     else if (fr.getSeqs().size() != ids.size())
     {
       System.out.println(String.format(
-              "Only retrieved %d sequences for %d query strings", fr
-                      .getSeqs().size(), ids.size()));
+              "Only retrieved %d sequences for %d query strings",
+              fr.getSeqs().size(), ids.size()));
     }
 
     if (fr.getSeqs().size() == 1 && fr.getSeqs().get(0).getLength() == 0)
@@ -589,8 +590,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
         if (directionSet && strand != direction)
         {
           // abort - mix of forward and backward
-          System.err.println("Error: forward and backward strand for "
-                  + accId);
+          System.err.println(
+                  "Error: forward and backward strand for " + accId);
           return null;
         }
         direction = strand;
@@ -634,8 +635,9 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
     Collections.sort(regions, direction == 1 ? IntRangeComparator.ASCENDING
             : IntRangeComparator.DESCENDING);
 
-    List<int[]> to = Arrays.asList(new int[] { start,
-        start + mappedLength - 1 });
+    List<int[]> to = Arrays
+            .asList(new int[]
+            { start, start + mappedLength - 1 });
 
     return new MapList(regions, to, 1, 1);
   }
@@ -698,9 +700,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
        * for sequence_variant on reverse strand, have to convert the allele
        * values to their complements
        */
-      if (!forwardStrand
-              && SequenceOntologyFactory.getInstance().isA(sf.getType(),
-                      SequenceOntologyI.SEQUENCE_VARIANT))
+      if (!forwardStrand && SequenceOntologyFactory.getInstance()
+              .isA(sf.getType(), SequenceOntologyI.SEQUENCE_VARIANT))
       {
         reverseComplementAlleles(copy);
       }
@@ -715,7 +716,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
    */
   static void reverseComplementAlleles(SequenceFeature sf)
   {
-    final String alleles = (String) sf.getValue(ALLELES);
+    final String alleles = (String) sf.getValue(Gff3Helper.ALLELES);
     if (alleles == null)
     {
       return;
@@ -726,7 +727,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       reverseComplementAllele(complement, allele);
     }
     String comp = complement.toString();
-    sf.setValue(ALLELES, comp);
+    sf.setValue(Gff3Helper.ALLELES, comp);
     sf.setDescription(comp);
 
     /*
@@ -736,7 +737,8 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
     String atts = sf.getAttributes();
     if (atts != null)
     {
-      atts = atts.replace(ALLELES + "=" + alleles, ALLELES + "=" + comp);
+      atts = atts.replace(Gff3Helper.ALLELES + "=" + alleles,
+              Gff3Helper.ALLELES + "=" + comp);
       sf.setAttributes(atts);
     }
   }
@@ -790,8 +792,7 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
       return false;
     }
 
-    long start = System.currentTimeMillis();
-    // SequenceFeature[] sfs = sourceSequence.getSequenceFeatures();
+//    long start = System.currentTimeMillis();
     List<SequenceFeature> sfs = sourceSequence.getFeatures()
             .getPositionalFeatures();
     MapList mapping = getGenomicRangesFromFeatures(sourceSequence,
@@ -803,10 +804,10 @@ public abstract class EnsemblSeqProxy extends EnsemblRestClient
 
     boolean result = transferFeatures(sfs, targetSequence, mapping,
             accessionId);
-    System.out.println("transferFeatures (" + (sfs.size()) + " --> "
-            + targetSequence.getFeatures().getFeatureCount(true) + ") to "
-            + targetSequence.getName() + " took "
-            + (System.currentTimeMillis() - start) + "ms");
+//    System.out.println("transferFeatures (" + (sfs.size()) + " --> "
+//            + targetSequence.getFeatures().getFeatureCount(true) + ") to "
+//            + targetSequence.getName() + " took "
+//            + (System.currentTimeMillis() - start) + "ms");
     return result;
   }