JAL-2738 extract utility method to MappingUtils
[jalview.git] / src / jalview / io / vcf / VCFLoader.java
index abbe139..4adc97c 100644 (file)
@@ -19,6 +19,7 @@ import jalview.ext.ensembl.EnsemblMap;
 import jalview.ext.htsjdk.VCFReader;
 import jalview.io.gff.SequenceOntologyI;
 import jalview.util.MapList;
+import jalview.util.MappingUtils;
 
 import java.io.IOException;
 import java.util.HashMap;
@@ -304,6 +305,11 @@ public class VCFLoader
     String alleles = sb.toString(); // e.g. G,A,C
 
     String type = SequenceOntologyI.SEQUENCE_VARIANT;
+
+    /*
+     * extract allele frequency as feature score, but only if
+     * a simple SNP (not for >1 co-located SNPs as each has a score)
+     */
     float score = 0f;
     if (alleleCount == 1)
     {
@@ -434,7 +440,7 @@ public class VCFLoader
           /*
            * mapping is 1:1 in length, so we trust it to have no discontinuities
            */
-          if (rangeContains(fromRange, queryRange))
+          if (MappingUtils.rangeContains(fromRange, queryRange))
           {
             /*
              * fromRange subsumes our query range
@@ -451,23 +457,6 @@ public class VCFLoader
   }
 
   /**
-   * Answers true if range's start-end positions include those of queryRange,
-   * where either range might be in reverse direction, else false
-   * 
-   * @param range
-   * @param queryRange
-   * @return
-   */
-  protected static boolean rangeContains(int[] range, int[] queryRange)
-  {
-    int min = Math.min(range[0], range[1]);
-    int max = Math.max(range[0], range[1]);
-
-    return (min <= queryRange[0] && max >= queryRange[0]
-            && min <= queryRange[1] && max >= queryRange[1]);
-  }
-
-  /**
    * Formats a ranges map lookup key
    * 
    * @param chromosome