[med-svn] [Git][med-team/htsjdk][upstream] New upstream version 3.0.5+dfsg

Pierre Gruet (@pgt) gitlab at salsa.debian.org
Tue Jun 20 15:52:15 BST 2023



Pierre Gruet pushed to branch upstream at Debian Med / htsjdk


Commits:
e0310ee7 by Pierre Gruet at 2023-06-13T22:25:49+02:00
New upstream version 3.0.5+dfsg
- - - - -


17 changed files:

- README.md
- build.gradle
- gradle/spotbugs-exclude.xml
- gradle/wrapper/gradle-wrapper.properties
- gradlew
- − scripts/checkScalaAndJavaFiles.sh
- src/main/java/htsjdk/samtools/Cigar.java
- src/main/java/htsjdk/samtools/cram/structure/CRAMRecordReadFeatures.java
- src/main/java/htsjdk/variant/vcf/VCFEncoder.java
- src/test/java/htsjdk/HtsjdkTest.java
- src/test/java/htsjdk/samtools/CRAMReferencelessTest.java
- src/test/java/htsjdk/samtools/CigarTest.java
- src/test/java/htsjdk/samtools/cram/structure/CRAMRecordTestHelper.java
- src/test/java/htsjdk/variant/vcf/VCFEncoderTest.java
- + src/test/resources/htsjdk/samtools/cram/testIGV1286.cram
- + src/test/resources/htsjdk/samtools/cram/testIGV1286.cram.crai
- + src/test/resources/htsjdk/samtools/cram/testIGV1286.sam


Changes:

=====================================
README.md
=====================================
@@ -9,7 +9,7 @@
 
 HTSJDK is an implementation of a unified Java library for accessing
 common file formats, such as [SAM][1] and [VCF][2], used for high-throughput
-sequencing data.  There are also an number of useful utilities for 
+sequencing data.  There are also a number of useful utilities for 
 manipulating HTS data.
 
 > **NOTE: _HTSJDK has only partial support for the latest Variant Call Format Specification.  VCFv4.3 can be read but not written and there is no support for BCFv2.2_**
@@ -78,7 +78,7 @@ Example gradle usage from the htsjdk root directory:
 ### Create an HTSJDK project in IntelliJ
 To create a project in IntelliJ IDE for htsjdk do the following:
 
-1. Select fom the menu: `File -> New -> Project from Existing Sources`
+1. Select from the menu: `File -> New -> Project from Existing Sources`
 2. In the resulting dialog, chose `Import from existing model`, select `Gradle` and `Next`
 3. Choose the `default gradle wrapper` and `Finish`.
 
@@ -116,8 +116,8 @@ Java SE Major Release | End of Java SE Oracle Public Updates / OpenJDK support |
  
 ### Meaning of the Htsjdk version number
 We encourage downstream projects to use the most recent htsjdk release in order to have access to the most up to date features and bug fixes.  It is therefore important therefore to make upgrading to newer versions as easy as possible. We make a best effort to adhere to the following principles in order to minimize disruption to projects that depend on htsjdk:
-* Avoid making breaking changes whenever possible. A breaking change is one which requires downstream projects to recompile against the new version of htsjdk or make changes to their source code.  These include both binary incompatiblities and source incompatibilites. 
-* Deprecate and provide new alternatives instead of removing exising APIs.
+* Avoid making breaking changes whenever possible. A breaking change is one which requires downstream projects to recompile against the new version of htsjdk or make changes to their source code.  These include both binary incompatibilities and source incompatibilities. 
+* Deprecate and provide new alternatives instead of removing existing APIs.
 * Document breaking changes in the release notes.
 * Provide clear instructions for upgrading to new API's when breaking changes/ deprecations occur.
 * Provide explanations for the rare cases when functionality is deprecated or removed without replacement.


=====================================
build.gradle
=====================================
@@ -5,15 +5,13 @@ buildscript {
 }
 
 plugins {
-    id 'java'
-    id 'scala'
+    id 'java-library'
     id 'maven-publish'
     id 'signing'
     id 'jacoco'
     id 'com.palantir.git-version' version '0.11.0'
     id 'com.github.johnrengelman.shadow' version '4.0.4'
-    id 'com.github.maiflai.scalatest' version '0.23'
-    id 'com.github.spotbugs' version '1.6.9'
+    id 'com.github.spotbugs' version "5.0.13"
 }
 
 repositories {
@@ -25,29 +23,27 @@ jacocoTestReport {
     description = "Generate Jacoco coverage reports after running tests."
 
     reports {
-        xml.enabled = true // codecov depends on xml format report
-        html.enabled = true
+        xml.required = true // codecov depends on xml format report
+        html.required = true
     }
 }
 
 dependencies {
-    compile "org.apache.commons:commons-jexl:2.1.1"
-    compile "commons-logging:commons-logging:1.1.1"
-    compile "org.xerial.snappy:snappy-java:1.1.8.4"
-    compile "org.apache.commons:commons-compress:1.19"
-    compile 'org.tukaani:xz:1.8'
-    compile "gov.nih.nlm.ncbi:ngs-java:2.9.0"
-    compile ('org.sharegov:mjson:1.4.1') {
-        exclude group: "junit" 
+    implementation "commons-logging:commons-logging:1.1.1"
+    implementation "org.xerial.snappy:snappy-java:1.1.8.4"
+    implementation "org.apache.commons:commons-compress:1.22"
+    implementation 'org.tukaani:xz:1.8'
+    implementation ('org.sharegov:mjson:1.4.1') {
+        exclude group: "junit"
     }
 
-    testCompile "org.scala-lang:scala-library:2.12.8"
-    testCompile "org.scalatest:scalatest_2.12:3.0.5"
-    testRuntime 'org.pegdown:pegdown:1.6.0' // Necessary for generating HTML reports with ScalaTest
-    testCompile "org.testng:testng:6.14.3"
-    testCompile "com.google.jimfs:jimfs:1.1"
-    testCompile "com.google.guava:guava:26.0-jre"
-    testCompile "org.apache.commons:commons-lang3:3.7"
+    api "gov.nih.nlm.ncbi:ngs-java:2.9.0"
+    api "org.apache.commons:commons-jexl:2.1.1"
+
+    testImplementation "org.testng:testng:6.14.3"
+    testImplementation "com.google.jimfs:jimfs:1.1"
+    testImplementation "com.google.guava:guava:26.0-jre"
+    testImplementation "org.apache.commons:commons-lang3:3.7"
 }
 
 sourceCompatibility = 1.8
@@ -74,7 +70,7 @@ jar {
     manifest {
         attributes 'Implementation-Title': 'HTSJDK',
                 'Implementation-Vendor': 'Samtools Organization',
-                'Implementation-Version': version
+                'Implementation-Version': archiveVersion
     }
 }
 
@@ -92,50 +88,58 @@ tasks.withType(Test) { task ->
     task.maxHeapSize = "2G"
 
     task.jvmArgs '-Djava.awt.headless=true'  //this prevents awt from displaying a java icon while the tests are running
-}
 
-task findScalaAndJavaTypes(type: Exec) {
-    description = "Check that Scala files only exist in the scala test dir and that java files do not reside in the scala test dir."
-    commandLine './scripts/checkScalaAndJavaFiles.sh'
-}
+    int count = 0
+    // listen to events in the test execution lifecycle
+
+    beforeTest { descriptor ->
+        count++
+        if( count % 200 == 0) {
+            logger.lifecycle("Finished "+ Integer.toString(count++) + " tests")
+        }
+    }
+
+    testLogging {
+        testLogging {
+            events "skipped", "failed"
+            exceptionFormat = "full"
+        }
+        afterSuite { desc, result ->
+            if (!desc.parent) { // will match the outermost suite
+                println "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
+            }
+        }
+    }
 
+}
 
 task testWithDefaultReference(type: Test) {
     description = "Run tests with a default reference File"
     jvmArgs += '-Dsamjdk.reference_fasta=src/test/resources/htsjdk/samtools/cram/ce.fa'
 
-    tags {
-        include "defaultReference"
+    useTestNG {
+        includeGroups "defaultReference"
     }
 }
 
 test {
     description = "Runs the unit tests other than the SRA tests"
 
-    testLogging {
-        events "failed", "skipped"
-    }
-
-    tags {
-        exclude "slow"
-        exclude "broken"
-        exclude "defaultReference"
-        exclude "ftp"
-        exclude "http"
-        exclude "sra"
-        exclude "ena"
-
-        if (!OperatingSystem.current().isUnix()) exclude "unix"
-    }
-} dependsOn findScalaAndJavaTypes, testWithDefaultReference
+   useTestNG {
+       if (OperatingSystem.current().isUnix()) {
+           excludeGroups "slow", "broken", "defaultReference", "ftp", "http", "sra", "ena"
+       } else {
+           excludeGroups "slow", "broken", "defaultReference", "ftp", "http", "sra", "ena", "unix"
+       }
+   }
+} dependsOn testWithDefaultReference
 
 
 task testFTP(type: Test) {
     description = "Runs the tests that require connection to a remote ftp server"
-    tags {
-        include "ftp"
-        exclude "slow"
-        exclude "broken"
+    useTestNG {
+        includeGroups "ftp"
+        excludeGroups "slow", "broken"
     }
 }
 
@@ -143,18 +147,15 @@ task testExternalApis(type: Test) {
     description = "Run the SRA, ENA, and HTTP tests (tests that interact with external APIs)"
     jvmArgs += '-Dsamjdk.sra_libraries_download=true'
 
-    tags {
-        include "sra"
-        include "http"
-        include "ena"
-        exclude "slow"
-        exclude "broken"
+    useTestNG {
+        includeGroups "sra", "http", "ena"
+        excludeGroups "slow", "broken"
     }
 }
 
 if(project == rootProject) {
     wrapper {
-        gradleVersion = '5.2.1'
+        gradleVersion = '7.6'
     }
 }
 
@@ -177,7 +178,15 @@ spotbugs {
     excludeFilter = file('gradle/spotbugs-exclude.xml')
 }
 
-tasks.withType(com.github.spotbugs.SpotBugsTask) {
+
+spotbugsMain {
+    reports {
+        xml.enabled = false
+        html.enabled = true
+    }
+}
+
+spotbugsTest {
     reports {
         xml.enabled = false
         html.enabled = true


=====================================
gradle/spotbugs-exclude.xml
=====================================
@@ -59,9 +59,13 @@
     </Match>
     <Match>
         <!-- It's OK for test classes to create one-off Random objects -->
+        <!-- This is done deliberately in SAMRecordSetBuilder in order to have a deterministic psuedo random result based on the input parameters -->
         <!-- DMI: Random object created and used only once -->
         <!-- https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#dmi-random-object-created-and-used-only-once-dmi-random-used-only-once -->
-        <Class name="~.*\.*Test" />
+        <Or>
+            <Class name="~.*\.*Test" />
+            <Class name="htsjdk.samtools.SAMRecordSetBuilder" />
+        </Or>
         <Bug pattern="DMI_RANDOM_USED_ONLY_ONCE" />
     </Match>
     <Match>
@@ -71,5 +75,12 @@
         <Class name="htsjdk.samtools.util.BlockCompressedInputStreamTest" />
         <Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
     </Match>
+    <Match>
+        <!--This seems to be a false positive due to a bug in how spotbugs handles breaks with gotos -->
+        <!-- SA_FIELD_SELF_ASSIGNMENT: Self assignment of field -->
+        <!-- https://spotbugs.readthedocs.io/en/stable/bugDescriptions.html#sa-self-assignment-of-local-variable-sa-local-self-assignment -->
+        <Class name="htsjdk.tribble.readers.LongLineBufferedReader" />
+        <Bug pattern="SA_FIELD_SELF_ASSIGNMENT" />
+    </Match>
 
 </FindBugsFilter>
\ No newline at end of file


=====================================
gradle/wrapper/gradle-wrapper.properties
=====================================
@@ -1,5 +1,5 @@
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists


=====================================
gradlew
=====================================
@@ -1,78 +1,129 @@
-#!/usr/bin/env sh
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
 
 ##############################################################################
-##
-##  Gradle start up script for UN*X
-##
+#
+#   Gradle start up script for POSIX generated by Gradle.
+#
+#   Important for running:
+#
+#   (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+#       noncompliant, but you have some other compliant shell such as ksh or
+#       bash, then to run this script, type that shell name before the whole
+#       command line, like:
+#
+#           ksh Gradle
+#
+#       Busybox and similar reduced shells will NOT work, because this script
+#       requires all of these POSIX shell features:
+#         * functions;
+#         * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+#           «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+#         * compound commands having a testable exit status, especially «case»;
+#         * various built-in commands including «command», «set», and «ulimit».
+#
+#   Important for patching:
+#
+#   (2) This script targets any POSIX shell, so it avoids extensions provided
+#       by Bash, Ksh, etc; in particular arrays are avoided.
+#
+#       The "traditional" practice of packing multiple parameters into a
+#       space-separated string is a well documented source of bugs and security
+#       problems, so this is (mostly) avoided, by progressively accumulating
+#       options in "$@", and eventually passing that to Java.
+#
+#       Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+#       and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+#       see the in-line comments for details.
+#
+#       There are tweaks for specific operating systems such as AIX, CygWin,
+#       Darwin, MinGW, and NonStop.
+#
+#   (3) This script is generated from the Groovy template
+#       https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+#       within the Gradle project.
+#
+#       You can find Gradle at https://github.com/gradle/gradle/.
+#
 ##############################################################################
 
 # Attempt to set APP_HOME
+
 # Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
-    ls=`ls -ld "$PRG"`
-    link=`expr "$ls" : '.*-> \(.*\)$'`
-    if expr "$link" : '/.*' > /dev/null; then
-        PRG="$link"
-    else
-        PRG=`dirname "$PRG"`"/$link"
-    fi
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+    APP_HOME=${app_path%"${app_path##*/}"}  # leaves a trailing /; empty if no leading path
+    [ -h "$app_path" ]
+do
+    ls=$( ls -ld "$app_path" )
+    link=${ls#*' -> '}
+    case $link in             #(
+      /*)   app_path=$link ;; #(
+      *)    app_path=$APP_HOME$link ;;
+    esac
 done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
+
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
 
 APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
+APP_BASE_NAME=${0##*/}
 
 # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS='"-Xmx64m"'
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
 
 # Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
+MAX_FD=maximum
 
 warn () {
     echo "$*"
-}
+} >&2
 
 die () {
     echo
     echo "$*"
     echo
     exit 1
-}
+} >&2
 
 # OS specific support (must be 'true' or 'false').
 cygwin=false
 msys=false
 darwin=false
 nonstop=false
-case "`uname`" in
-  CYGWIN* )
-    cygwin=true
-    ;;
-  Darwin* )
-    darwin=true
-    ;;
-  MINGW* )
-    msys=true
-    ;;
-  NONSTOP* )
-    nonstop=true
-    ;;
+case "$( uname )" in                #(
+  CYGWIN* )         cygwin=true  ;; #(
+  Darwin* )         darwin=true  ;; #(
+  MSYS* | MINGW* )  msys=true    ;; #(
+  NONSTOP* )        nonstop=true ;;
 esac
 
 CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
 
+
 # Determine the Java command to use to start the JVM.
 if [ -n "$JAVA_HOME" ] ; then
     if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
         # IBM's JDK on AIX uses strange locations for the executables
-        JAVACMD="$JAVA_HOME/jre/sh/java"
+        JAVACMD=$JAVA_HOME/jre/sh/java
     else
-        JAVACMD="$JAVA_HOME/bin/java"
+        JAVACMD=$JAVA_HOME/bin/java
     fi
     if [ ! -x "$JAVACMD" ] ; then
         die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
 location of your Java installation."
     fi
 else
-    JAVACMD="java"
+    JAVACMD=java
     which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
 
 Please set the JAVA_HOME variable in your environment to match the
@@ -89,84 +140,101 @@ location of your Java installation."
 fi
 
 # Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
-    MAX_FD_LIMIT=`ulimit -H -n`
-    if [ $? -eq 0 ] ; then
-        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
-            MAX_FD="$MAX_FD_LIMIT"
-        fi
-        ulimit -n $MAX_FD
-        if [ $? -ne 0 ] ; then
-            warn "Could not set maximum file descriptor limit: $MAX_FD"
-        fi
-    else
-        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
-    fi
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+    case $MAX_FD in #(
+      max*)
+        MAX_FD=$( ulimit -H -n ) ||
+            warn "Could not query maximum file descriptor limit"
+    esac
+    case $MAX_FD in  #(
+      '' | soft) :;; #(
+      *)
+        ulimit -n "$MAX_FD" ||
+            warn "Could not set maximum file descriptor limit to $MAX_FD"
+    esac
 fi
 
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
-    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
+# Collect all arguments for the java command, stacking in reverse order:
+#   * args from the command line
+#   * the main class name
+#   * -classpath
+#   * -D...appname settings
+#   * --module-path (only if needed)
+#   * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+    APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+    CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+    JAVACMD=$( cygpath --unix "$JAVACMD" )
 
-# For Cygwin, switch paths to Windows format before running java
-if $cygwin ; then
-    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
-    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
-    JAVACMD=`cygpath --unix "$JAVACMD"`
-
-    # We build the pattern for arguments to be converted via cygpath
-    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
-    SEP=""
-    for dir in $ROOTDIRSRAW ; do
-        ROOTDIRS="$ROOTDIRS$SEP$dir"
-        SEP="|"
-    done
-    OURCYGPATTERN="(^($ROOTDIRS))"
-    # Add a user-defined pattern to the cygpath arguments
-    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
-        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
-    fi
     # Now convert the arguments - kludge to limit ourselves to /bin/sh
-    i=0
-    for arg in "$@" ; do
-        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
-        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
-
-        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
-            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
-        else
-            eval `echo args$i`="\"$arg\""
+    for arg do
+        if
+            case $arg in                                #(
+              -*)   false ;;                            # don't mess with options #(
+              /?*)  t=${arg#/} t=/${t%%/*}              # looks like a POSIX filepath
+                    [ -e "$t" ] ;;                      #(
+              *)    false ;;
+            esac
+        then
+            arg=$( cygpath --path --ignore --mixed "$arg" )
         fi
-        i=$((i+1))
+        # Roll the args list around exactly as many times as the number of
+        # args, so each arg winds up back in the position where it started, but
+        # possibly modified.
+        #
+        # NB: a `for` loop captures its iteration list before it begins, so
+        # changing the positional parameters here affects neither the number of
+        # iterations, nor the values presented in `arg`.
+        shift                   # remove old arg
+        set -- "$@" "$arg"      # push replacement arg
     done
-    case $i in
-        (0) set -- ;;
-        (1) set -- "$args0" ;;
-        (2) set -- "$args0" "$args1" ;;
-        (3) set -- "$args0" "$args1" "$args2" ;;
-        (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
-        (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
-        (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
-        (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
-        (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
-        (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
-    esac
 fi
 
-# Escape application args
-save () {
-    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
-    echo " "
-}
-APP_ARGS=$(save "$@")
-
-# Collect all arguments for the java command, following the shell quoting and substitution rules
-eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
-
-# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
-if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
-  cd "$(dirname "$0")"
+# Collect all arguments for the java command;
+#   * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+#     shell script including quotes and variable substitutions, so put them in
+#     double quotes to make sure that they get re-expanded; and
+#   * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+        "-Dorg.gradle.appname=$APP_BASE_NAME" \
+        -classpath "$CLASSPATH" \
+        org.gradle.wrapper.GradleWrapperMain \
+        "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+    die "xargs is not available"
 fi
 
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+#   readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+#   set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+        printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+        xargs -n1 |
+        sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+        tr '\n' ' '
+    )" '"$@"'
+
 exec "$JAVACMD" "$@"


=====================================
scripts/checkScalaAndJavaFiles.sh deleted
=====================================
@@ -1,17 +0,0 @@
-#!/usr/bin/env bash
-
-# Check that Scala files only exist in the scala test dir and
-# that java files do not reside in the scala test dir
-
-if `find src | grep -v '^src/test/scala' | grep -q '\.scala$' ` ; then
-	echo 'Found scala file(s) outside of scala test directory';
-	find src | grep -v '^src/test/scala' | grep '\.scala$'
-	exit 1; 
-fi
-
-if `find src/test/scala | grep -q '\.java$' ` ; then
-        echo 'Found java file(s) in scala test directory';
-	find src/test/scala | grep '\.java$'        
-	exit 1;
-fi
-


=====================================
src/main/java/htsjdk/samtools/Cigar.java
=====================================
@@ -36,7 +36,7 @@ import java.util.List;
  * * deletion of 1 base
  * * match or mismatch for 25 bases
  *
- * c.f. http://samtools.sourceforge.net/SAM1.pdf for complete CIGAR specification.
+ * c.f. https://samtools.github.io/hts-specs/SAMv1.pdf for complete CIGAR specification.
  */
 public class Cigar implements Serializable, Iterable<CigarElement> {
     public static final long serialVersionUID = 1L;
@@ -292,6 +292,16 @@ public class Cigar implements Serializable, Iterable<CigarElement> {
         }
         return new Cigar(cigarElementList);
     }
+
+    /**
+     * Decode a Cigar from a SAM formatted CIGAR String, uses {@link TextCigarCodec#decode(String)}
+     * Only performs minimal validation.
+     * @param cigarString A SAM formatted CIGAR string.
+     * @return a new Cigar
+     */
+    public static Cigar fromCigarString(String cigarString){
+        return TextCigarCodec.decode(cigarString);
+    }
     
     /** shortcut to <code>getCigarElements().iterator()</code> */
     @Override


=====================================
src/main/java/htsjdk/samtools/cram/structure/CRAMRecordReadFeatures.java
=====================================
@@ -495,6 +495,9 @@ public class CRAMRecordReadFeatures {
     }
 
     private static byte getByteOrDefault(final byte[] array, final int pos, final byte outOfBoundsValue) {
+        if (array == null) {
+            return outOfBoundsValue;
+        }
         return pos >= array.length ?
                 outOfBoundsValue :
                 array[pos];


=====================================
src/main/java/htsjdk/variant/vcf/VCFEncoder.java
=====================================
@@ -219,7 +219,7 @@ public class VCFEncoder {
     }
 
     @SuppressWarnings("rawtypes")
-    String formatVCFField(final Object val) {
+    static String formatVCFField(final Object val) {
         final String result;
         if (val == null) {
             result = VCFConstants.MISSING_VALUE_v4;
@@ -327,11 +327,7 @@ public class VCFEncoder {
                         throw new IllegalStateException("GTs cannot be missing for some samples if they are available for others in the record");
                     }
 
-                    writeAllele(g.getAllele(0), alleleMap, vcfoutput);
-                    for (int i = 1; i < g.getPloidy(); i++) {
-                        vcfoutput.append(g.isPhased() ? VCFConstants.PHASED : VCFConstants.UNPHASED);
-                        writeAllele(g.getAllele(i), alleleMap, vcfoutput);
-                    }
+                    writeGtField(alleleMap, vcfoutput, g);
                     continue;
 
                 } else {
@@ -387,6 +383,21 @@ public class VCFEncoder {
         }
     }
 
+    /**
+     * write the encoded GT field for a Genotype
+     * @param alleleMap a mapping of Allele -> GT allele value (from {@link this#buildAlleleStrings(VariantContext)}
+     * @param vcfoutput the appendable to write to, to avoid inefficiency due to string copying
+     * @param g the genotoype to encode
+     * @throws IOException if appending fails with an IOException
+     */
+    public static void writeGtField(final Map<Allele, String> alleleMap, final Appendable vcfoutput, final Genotype g) throws IOException {
+        writeAllele(g.getAllele(0), alleleMap, vcfoutput);
+        for (int i = 1; i < g.getPloidy(); i++) {
+            vcfoutput.append(g.isPhased() ? VCFConstants.PHASED : VCFConstants.UNPHASED);
+            writeAllele(g.getAllele(i), alleleMap, vcfoutput);
+        }
+    }
+
     /*
      * Create the info string; assumes that no values are null
      */
@@ -416,8 +427,31 @@ public class VCFEncoder {
         }
     }
 
-    public Map<Allele, String> buildAlleleStrings(final VariantContext vc) {
-        final Map<Allele, String> alleleMap = new HashMap<Allele, String>(vc.getAlleles().size() + 1);
+    /**
+     * Easy way to generate the GT field for a Genotype.  This will be less efficient than using
+     * {@link this#writeGtField(Map, Appendable, Genotype)} because of redundant Map initializations
+     * @param vc a VariantContext which must contain g or the results are likely to be incorrect
+     * @param g a Genotype in vc
+     * @return a String containing the encoding of the GT field of g
+     */
+    public static String encodeGtField(VariantContext vc, Genotype g) {
+      final StringBuilder builder = new StringBuilder();
+        try {
+            writeGtField(VCFEncoder.buildAlleleStrings(vc), builder, g);
+        } catch (final IOException e) {
+            throw new RuntimeException("Somehow we failed to append to a StringBuilder, this shouldn't happen.", e);
+        }
+        return builder.toString();
+    }
+
+    /**
+     * return a Map containing Allele -> String(allele position) for all Alleles in VC 
+     * (as well as NO_CALL) 
+     * ex: A,T,TC -> { A:0, T:1, TC:2, NO_CALL:EMPTY_ALLELE}
+     * This may be efficient when looking up values for many genotypes per VC
+     */
+    public static Map<Allele, String> buildAlleleStrings(final VariantContext vc) {
+        final Map<Allele, String> alleleMap = new HashMap<>(vc.getAlleles().size() + 1);
         alleleMap.put(Allele.NO_CALL, VCFConstants.EMPTY_ALLELE); // convenience for lookup
 
         final List<Allele> alleles = vc.getAlleles();


=====================================
src/test/java/htsjdk/HtsjdkTest.java
=====================================
@@ -1,10 +1,8 @@
 package htsjdk;
 
-import org.scalatest.testng.TestNGSuite;
-
 /**
  * Base class for all Java tests in HTSJDK.
  */
-public class HtsjdkTest extends TestNGSuite {
+public class HtsjdkTest{
 
 }


=====================================
src/test/java/htsjdk/samtools/CRAMReferencelessTest.java
=====================================
@@ -14,7 +14,7 @@ public class CRAMReferencelessTest extends HtsjdkTest {
     private static final File TEST_DATA_DIR = new File("src/test/resources/htsjdk/samtools/cram");
 
     @Test
-    private void testReadCRAMWithEmbeddedReference() throws IOException {
+    public void testReadCRAMWithEmbeddedReference() throws IOException {
         try (final SamReader cramReader = SamReaderFactory.makeDefault()
                 .validationStringency(ValidationStringency.LENIENT)
                 .referenceSource(new ReferenceSource(new File(TEST_DATA_DIR, "human_g1k_v37.20.21.1-100.fasta")))
@@ -24,16 +24,44 @@ public class CRAMReferencelessTest extends HtsjdkTest {
                      .open(new File(TEST_DATA_DIR, "referenceEmbedded.NA12878.20.21.1-100.100-SeqsPerSlice.500-unMapped.cram"))) {
             final Iterator<SAMRecord> cramIterator = cramReader.iterator();
             final Iterator<SAMRecord> cramEmbeddedIterator = cramReaderEmbedded.iterator();
+            int count = 0;
             while (cramIterator.hasNext() && cramEmbeddedIterator.hasNext()) {
+                count++;
                 final SAMRecord cramRecord = cramIterator.next();
                 final SAMRecord cramRecordEmbedded = cramEmbeddedIterator.next();
                 Assert.assertEquals(cramRecordEmbedded, cramRecord);
             }
+            Assert.assertTrue( count >0, "Expected reads but there were none.");
         }
     }
 
+    // test for https://github.com/igvteam/igv/issues/1286
+    // cram was generated subset from an example cram using samtools and -O no_ref
     @Test
-    private void testReadCRAMNoReferenceRequired() throws IOException {
+    public void testForNPE() throws IOException {
+        try (final SamReader cramReader = SamReaderFactory.makeDefault()
+                .validationStringency(ValidationStringency.LENIENT)
+                .open(new File(TEST_DATA_DIR, "testIGV1286.sam"));
+             final SamReader cramReaderEmbedded = SamReaderFactory.makeDefault()
+                     .validationStringency(ValidationStringency.LENIENT)
+                     .open(new File(TEST_DATA_DIR, "testIGV1286.cram"))) {
+            final Iterator<SAMRecord> cramIterator = cramReader.iterator();
+            final Iterator<SAMRecord> cramEmbeddedIterator = cramReaderEmbedded.iterator();
+            int count = 0;
+            while (cramIterator.hasNext() && cramEmbeddedIterator.hasNext()) {
+                count++;
+                final SAMRecord cramRecord = cramIterator.next();
+                final SAMRecord cramRecordEmbedded = cramEmbeddedIterator.next();
+                Assert.assertEquals(cramRecordEmbedded, cramRecord);
+            }
+            Assert.assertEquals(count, 2);
+            Assert.assertFalse(cramIterator.hasNext());
+            Assert.assertFalse(cramEmbeddedIterator.hasNext());
+        }
+    }
+
+    @Test
+    public void testReadCRAMNoReferenceRequired() throws IOException {
         // test reading a cram with no reference compression (RR=false in compression header)
         try (final SamReader samReader = SamReaderFactory.makeDefault()
                              .validationStringency(ValidationStringency.LENIENT)


=====================================
src/test/java/htsjdk/samtools/CigarTest.java
=====================================
@@ -100,7 +100,12 @@ public class CigarTest extends HtsjdkTest {
         Assert.assertEquals(errors.size(), 1, String.format("Got %d error, expected exactly one error.", errors.size()));
         Assert.assertEquals(errors.get(0).getType(), type);
     }
-    
+
+    @Test(dataProvider = "positiveTestsData")
+    public void testFromCigarString(String cigarString){
+        Assert.assertEquals(Cigar.fromCigarString(cigarString), TextCigarCodec.decode(cigarString) );
+    }
+
     @Test
     public void testMakeCigarFromOperators() {
         final List<CigarOperator> cigarOperators = Arrays.asList(


=====================================
src/test/java/htsjdk/samtools/cram/structure/CRAMRecordTestHelper.java
=====================================
@@ -13,10 +13,6 @@ import java.util.stream.IntStream;
 public class CRAMRecordTestHelper {
 
     final SAMRecordSetBuilder recordSetBuilder = new SAMRecordSetBuilder();
-    final Map<String, Integer> readGroupMap = new HashMap<String, Integer>() {{
-        readGroupMap.put("chr1", 1);
-        readGroupMap.put("chr2", 2);
-    }};
 
     @BeforeTest
     public void setupRecordSetBuilder() {


=====================================
src/test/java/htsjdk/variant/vcf/VCFEncoderTest.java
=====================================
@@ -3,6 +3,7 @@ package htsjdk.variant.vcf;
 import htsjdk.HtsjdkTest;
 import htsjdk.tribble.util.ParsingUtils;
 import htsjdk.variant.variantcontext.Allele;
+import htsjdk.variant.variantcontext.Genotype;
 import htsjdk.variant.variantcontext.GenotypeBuilder;
 import htsjdk.variant.variantcontext.VariantContext;
 import htsjdk.variant.variantcontext.VariantContextBuilder;
@@ -10,6 +11,7 @@ import org.testng.Assert;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -135,6 +137,40 @@ public class VCFEncoderTest extends HtsjdkTest {
         return tests.toArray(new Object[][]{});
     }
 
+    @Test
+    public void testEncodeGT(){
+        final VariantContextBuilder vcb = new VariantContextBuilder("test",
+                "chr?", 100, 100,
+                Arrays.asList(Allele.REF_A, Allele.ALT_T, Allele.create("TC")));
+        final Genotype g1 = new GenotypeBuilder("s1", Arrays.asList(Allele.REF_A, Allele.REF_A)).make();
+        final Genotype g2 = new GenotypeBuilder("s2", Arrays.asList(Allele.ALT_T, Allele.create("TC"))).make();
+        vcb.genotypes(g1, g2);
+        final VariantContext vc = vcb.make();
+
+        Assert.assertEquals(VCFEncoder.encodeGtField(vc, g1), "0/0");
+        Assert.assertEquals(VCFEncoder.encodeGtField(vc, g2), "1/2");
+    }
+
+    @Test
+    public void testsWriteGtField() throws IOException {
+        final VariantContextBuilder vcb = new VariantContextBuilder("test",
+                "chr?", 100, 100,
+                Arrays.asList(Allele.REF_A, Allele.ALT_T, Allele.create("TC")));
+        final Genotype g1 = new GenotypeBuilder("s1", Arrays.asList(Allele.REF_A, Allele.REF_A)).make();
+        final Genotype g2 = new GenotypeBuilder("s2", Arrays.asList(Allele.ALT_T, Allele.create("TC"))).make();
+        vcb.genotypes(g1, g2);
+        final VariantContext vc = vcb.make();
+        final Map<Allele, String> alleleStringMap = VCFEncoder.buildAlleleStrings(vc);
+
+        final StringBuilder b1 = new StringBuilder();
+        VCFEncoder.writeGtField(alleleStringMap, b1, g1 );
+        Assert.assertEquals(b1.toString(), "0/0");
+
+        final StringBuilder b2 = new StringBuilder();
+        VCFEncoder.writeGtField(alleleStringMap, b2, g2);
+        Assert.assertEquals(b2.toString(), "1/2");
+    }
+
     @Test(dataProvider = "MissingFormatTestData")
     public void testMissingFormatFields(final VCFEncoder encoder, final VariantContext vc, final String expectedLastColumn, final Map<Allele, String> alleleMap, final List<String> genotypeFormatKeys) {
         final StringBuilder sb = new StringBuilder();


=====================================
src/test/resources/htsjdk/samtools/cram/testIGV1286.cram
=====================================
Binary files /dev/null and b/src/test/resources/htsjdk/samtools/cram/testIGV1286.cram differ


=====================================
src/test/resources/htsjdk/samtools/cram/testIGV1286.cram.crai
=====================================
Binary files /dev/null and b/src/test/resources/htsjdk/samtools/cram/testIGV1286.cram.crai differ


=====================================
src/test/resources/htsjdk/samtools/cram/testIGV1286.sam
=====================================
The diff for this file was not included because it is too large.


View it on GitLab: https://salsa.debian.org/med-team/htsjdk/-/commit/e0310ee7a46a2b404eb25ab8b859b4fd64758a5c

-- 
View it on GitLab: https://salsa.debian.org/med-team/htsjdk/-/commit/e0310ee7a46a2b404eb25ab8b859b4fd64758a5c
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20230620/8c84ac69/attachment-0001.htm>


More information about the debian-med-commit mailing list