New Upstream Release - libssw

Ready changes

Summary

Merged new upstream version: 1.2.5 (was: 1.2.4).

Diff

diff --git a/debian/changelog b/debian/changelog
index ef8079d..03700cf 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,4 +1,4 @@
-libssw (1.2.4-2) UNRELEASED; urgency=medium
+libssw (1.2.5-1) UNRELEASED; urgency=medium
 
   [ Andreas Tille ]
   * Team upload.
@@ -9,7 +9,10 @@ libssw (1.2.4-2) UNRELEASED; urgency=medium
   [ Michael R. Crusoe ]
   * Remove extra copy of SIMDe in debian/include/simde
 
- -- Andreas Tille <tille@debian.org>  Mon, 28 Nov 2022 18:04:47 +0100
+  [ Debian Janitor ]
+  * New upstream release.
+
+ -- Andreas Tille <tille@debian.org>  Sun, 09 Jul 2023 10:00:45 -0000
 
 libssw (1.2.4-1) experimental; urgency=medium
 
diff --git a/debian/patches/build_all_libs.patch b/debian/patches/build_all_libs.patch
index f35610f..f27d780 100644
--- a/debian/patches/build_all_libs.patch
+++ b/debian/patches/build_all_libs.patch
@@ -4,8 +4,10 @@ Description: build all libraries
  Not upstreamed as upstream intends their C source to be inlined with the
  code using the functions.
 Author: Sascha Steinbiss <sascha@steinbiss.name>
---- a/src/Makefile
-+++ b/src/Makefile
+Index: libssw.git/src/Makefile
+===================================================================
+--- libssw.git.orig/src/Makefile
++++ libssw.git/src/Makefile
 @@ -6,25 +6,30 @@ CXXFLAGS := $(CFLAGS)
  LOBJS = ssw.o
  LCPPOBJS = ssw_cpp.o
diff --git a/debian/patches/hardening.patch b/debian/patches/hardening.patch
index ba31a60..9b1b10a 100644
--- a/debian/patches/hardening.patch
+++ b/debian/patches/hardening.patch
@@ -1,7 +1,9 @@
 Description: add hardening
 Author: Sascha Steinbiss <sascha@steinbiss.name>
---- a/src/Makefile
-+++ b/src/Makefile
+Index: libssw.git/src/Makefile
+===================================================================
+--- libssw.git.orig/src/Makefile
++++ libssw.git/src/Makefile
 @@ -1,8 +1,8 @@
 -CC = gcc
 -CXX = g++
diff --git a/debian/patches/malloc b/debian/patches/malloc
index e998439..2a24869 100644
--- a/debian/patches/malloc
+++ b/debian/patches/malloc
@@ -1,7 +1,9 @@
 From: Michael R. Crusoe <michael.crusoe@gmail.com>
 Subject: Provide declarations for malloc & free
---- libssw.orig/src/sswjni.c
-+++ libssw/src/sswjni.c
+Index: libssw.git/src/sswjni.c
+===================================================================
+--- libssw.git.orig/src/sswjni.c
++++ libssw.git/src/sswjni.c
 @@ -1,6 +1,7 @@
  #include <jni.h>
  #include <stdio.h>
diff --git a/debian/patches/rename_tool.patch b/debian/patches/rename_tool.patch
index 5d21ccd..c027bfd 100644
--- a/debian/patches/rename_tool.patch
+++ b/debian/patches/rename_tool.patch
@@ -2,8 +2,10 @@ Description: build command line aligner
  This patch ensures that 'ssw_test' is called 'ssw-align' in Debian
  and also links against libssw.
 Author: Sascha Steinbiss <satta@debian.org>
---- a/src/Makefile
-+++ b/src/Makefile
+Index: libssw.git/src/Makefile
+===================================================================
+--- libssw.git.orig/src/Makefile
++++ libssw.git/src/Makefile
 @@ -5,7 +5,7 @@ CFLAGS += -Wall -pipe -O2
  #CXXFLAGS := $(CFLAGS)
  LOBJS = ssw.o
@@ -32,8 +34,10 @@ Author: Sascha Steinbiss <satta@debian.org>
  	$(CC) -o $@ $(filter-out %.h,$^) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -lm -lz
  endif
  
---- a/src/main.c
-+++ b/src/main.c
+Index: libssw.git/src/main.c
+===================================================================
+--- libssw.git.orig/src/main.c
++++ libssw.git/src/main.c
 @@ -257,7 +257,7 @@ int main (int argc, char * const argv[])
  
  	if (optind + 2 > argc) {
diff --git a/debian/patches/simde.patch b/debian/patches/simde.patch
index a0a9b7c..7567731 100644
--- a/debian/patches/simde.patch
+++ b/debian/patches/simde.patch
@@ -1,8 +1,10 @@
 Author: Michael R. Crusoe <michael.crusoe@gmail.com>
 Description: use the simde header library for greater compatibility
 Forwarded: https://github.com/mengyao/Complete-Striped-Smith-Waterman-Library/pull/69
---- a/src/ssw.c
-+++ b/src/ssw.c
+Index: libssw.git/src/ssw.c
+===================================================================
+--- libssw.git.orig/src/ssw.c
++++ libssw.git/src/ssw.c
 @@ -76,7 +76,8 @@
  #ifdef __ARM_NEON // (M1)
  #include "sse2neon.h"
@@ -13,8 +15,10 @@ Forwarded: https://github.com/mengyao/Complete-Striped-Smith-Waterman-Library/pu
  #endif
  
  
---- a/src/ssw.h
-+++ b/src/ssw.h
+Index: libssw.git/src/ssw.h
+===================================================================
+--- libssw.git.orig/src/ssw.h
++++ libssw.git/src/ssw.h
 @@ -17,8 +17,6 @@
  
  #ifdef __ARM_NEON // (M1)
@@ -24,8 +28,10 @@ Forwarded: https://github.com/mengyao/Complete-Striped-Smith-Waterman-Library/pu
  #endif
  
  
---- a/src/main.c
-+++ b/src/main.c
+Index: libssw.git/src/main.c
+===================================================================
+--- libssw.git.orig/src/main.c
++++ libssw.git/src/main.c
 @@ -17,8 +17,6 @@
  
  #ifdef __ARM_NEON // (M1)
diff --git a/src/example.cpp b/src/example.cpp
index 7f97205..1816f61 100644
--- a/src/example.cpp
+++ b/src/example.cpp
@@ -5,7 +5,7 @@
 // 1) g++ -Wall ssw_cpp.cpp ssw.c example.cpp
 // 2) ./a.out
 // Created by Wan-Ping Lee on 09/04/12.
-// Last revision by Mengyao Zhao on 2017-06-05
+// Last revision by Mengyao Zhao on 2023-Apr-21
 // ==========================
 
 #include <iostream>
@@ -24,8 +24,6 @@ int main() {
   const string query = "CTGAGCCGGTAAATC";
   int32_t maskLen = strlen(query.c_str())/2;
   maskLen = maskLen < 15 ? 15 : maskLen;
-  //const string ref   = "CCGTTTATCGCA";
-  //const string query = "CCTTTTATCGCA";
 
   // Declares a default Aligner
   StripedSmithWaterman::Aligner aligner;
diff --git a/src/main.c b/src/main.c
index e2d81cf..bc5a6e3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,14 +42,14 @@ KSEQ_INIT(gzFile, gzread)
 static void reverse_comple(const char* seq, char* rc) {
 	int32_t end = strlen(seq), start = 0;
 	static const int8_t rc_table[128] = {
-		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
-		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
-		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
-		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
-		4, 84, 4, 71, 4,  4,  4, 67, 4, 4, 4, 4,  4, 4, 4, 4,
-		4, 4,  4, 4,  65, 65, 4, 4,  4, 4, 4, 4,  4, 4, 4, 4,
-		4, 84, 4, 71, 4,  4,  4, 67, 4, 4, 4, 4,  4, 4, 4, 4,
-		4, 4,  4, 4,  65, 65, 4, 4,  4, 4, 4, 4,  4, 4, 4, 4
+		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4,  4,
+		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4,  4,
+		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4,  4,
+		4, 4,  4, 4,  4,  4,  4, 4,  4, 4, 4, 4,  4, 4, 4,  4,
+		4, 84, 4, 71, 4,  4,  4, 67, 4, 4, 4, 4,  4, 4, 78, 4,
+		4, 4,  4, 4,  65, 65, 4, 4,  4, 4, 4, 4,  4, 4, 4,  4,
+		4, 84, 4, 71, 4,  4,  4, 67, 4, 4, 4, 4,  4, 4, 78,  4,
+		4, 4,  4, 4,  65, 65, 4, 4,  4, 4, 4, 4,  4, 4, 4,  4
 	};
 	rc[end] = '\0';
 	-- end;
diff --git a/src/ssw.c b/src/ssw.c
index 99be158..e8599c6 100644
--- a/src/ssw.c
+++ b/src/ssw.c
@@ -56,7 +56,7 @@
  *
  *  Created by Mengyao Zhao on 6/22/10.
  *  Copyright 2010 Boston College. All rights reserved.
- *	Version 1.2.4
+ *	Version 1.2.5
  *	Last revision by Mengyao Zhao on 2022-Apr-17.
  *
  *  The lazy-F loop implementation was derived from SWPS3, which is
@@ -208,8 +208,8 @@ static alignment_end* sw_sse2_byte (const int8_t* ref,
 	 						 uint8_t bias,  /* Shift 0 point to a positive value. */
 							 int32_t maskLen) {
 
-// Put the largest number of the 16 numbers in vm into m.
-#define max16(m, vm) (vm) = _mm_max_epu8((vm), _mm_srli_si128((vm), 8)); \
+    // Put the largest number of the 16 numbers in vm into m.
+    #define max16(m, vm) (vm) = _mm_max_epu8((vm), _mm_srli_si128((vm), 8)); \
 					  (vm) = _mm_max_epu8((vm), _mm_srli_si128((vm), 4)); \
 					  (vm) = _mm_max_epu8((vm), _mm_srli_si128((vm), 2)); \
 					  (vm) = _mm_max_epu8((vm), _mm_srli_si128((vm), 1)); \
@@ -304,16 +304,17 @@ static alignment_end* sw_sse2_byte (const int8_t* ref,
 			for (j = 0; LIKELY(j < segLen); ++j) {
 				vH = _mm_load_si128(pvHStore + j);
 				vH = _mm_max_epu8(vH, vF);
-				vMaxColumn = _mm_max_epu8(vMaxColumn, vH);	// newly added line
+	    		vMaxColumn = _mm_max_epu8(vMaxColumn, vH);	// newly added line
 				_mm_store_si128(pvHStore + j, vH);
 				vH = _mm_subs_epu8(vH, vGapO);
 				vF = _mm_subs_epu8(vF, vGapE);
-				if (UNLIKELY(! _mm_movemask_epi8(_mm_cmpgt_epi8(vF, vH)))) goto end;
+                vTemp = _mm_subs_epu8(vF, vH);
+                vTemp = _mm_cmpeq_epi8 (vTemp, vZero);
+                if (UNLIKELY(_mm_movemask_epi8(vTemp) == 0xffff)) goto end;
 			}
 		}
 
 end:		
-
 		vMaxScore = _mm_max_epu8(vMaxScore, vMaxColumn);
 		vTemp = _mm_cmpeq_epi8(vMaxMark, vMaxScore);
 		cmp = _mm_movemask_epi8(vTemp);
diff --git a/src/ssw.h b/src/ssw.h
index f4ec7e7..eff0169 100644
--- a/src/ssw.h
+++ b/src/ssw.h
@@ -4,7 +4,7 @@
  *  Created by Mengyao Zhao on 6/22/10.
  *  Copyright 2010 Boston College. All rights reserved.
  *	Version 1.2.3
- *	Last revision by Mengyao Zhao on 2022-Apr-15.
+ *	Last revision by Mengyao Zhao on 2022-May-24.
  *
  */
 
@@ -46,7 +46,7 @@ typedef struct _profile s_profile;
     @field	read_begin1	0-based best alignment beginning position on read; read_begin1 = -1 when the best alignment beginning
 						position is not available
     @field	read_end1	0-based best alignment ending position on read
-    @field	read_end2	0-based sub-optimal alignment ending position on read
+    @field	ref_end2	0-based sub-optimal alignment ending position on reference
     @field	cigar	best alignment cigar; stored the same as that in BAM format, high 28 bits: length, low 4 bits: M/I/D (0/1/2);
 					cigar = 0 when the best alignment path is not available
     @field	cigarLen	length of the cigar string; cigarLen = 0 when the best alignment path is not available
diff --git a/src/ssw_cpp.cpp b/src/ssw_cpp.cpp
index d5e3a7e..fe7dc99 100644
--- a/src/ssw_cpp.cpp
+++ b/src/ssw_cpp.cpp
@@ -1,6 +1,6 @@
 // ssw_cpp.cpp
 // Created by Wan-Ping Lee
-// Last revision by Mengyao Zhao on 2017-05-30
+// Last revision by Mengyao Zhao on 2023-Apr-21
 
 #include "ssw_cpp.h"
 #include "ssw.h"
@@ -290,25 +290,18 @@ int Aligner::SetReferenceSequence(const char* seq, const int& length) {
 
   int len = 0;
   if (translation_matrix_) {
-    // calculate the valid length
-    //int calculated_ref_length = static_cast<int>(strlen(seq));
-    //int valid_length = (calculated_ref_length > length)
-    //                   ? length : calculated_ref_length;
-    int valid_length = length;
     // delete the current buffer
     CleanReferenceSequence();
     // allocate a new buffer
-    translated_reference_ = new int8_t[valid_length];
+    translated_reference_ = new int8_t[length];
 
-    len = TranslateBase(seq, valid_length, translated_reference_);
+    len = TranslateBase(seq, length, translated_reference_);
   } else {
     // nothing
   }
 
   reference_length_ = len;
   return len;
-
-
 }
 
 int Aligner::TranslateBase(const char* bases, const int& length,
@@ -326,7 +319,7 @@ int Aligner::TranslateBase(const char* bases, const int& length,
 }
 
 
-bool Aligner::Align(const char* query, const Filter& filter,
+uint16_t Aligner::Align(const char* query, const Filter& filter,
                     Alignment* alignment, const int32_t maskLen) const
 {
   if (!translation_matrix_) return false;
@@ -351,18 +344,18 @@ bool Aligner::Align(const char* query, const Filter& filter,
   alignment->Clear();
   ConvertAlignment(*s_al, query_len, alignment);
   alignment->mismatches = CalculateNumberMismatch(&*alignment, translated_reference_, translated_query, query_len);
-
+  uint16_t align_flag = s_al->flag;
 
   // Free memory
   delete [] translated_query;
   align_destroy(s_al);
   init_destroy(profile);
 
-  return true;
+  return align_flag;
 }
 
 
-bool Aligner::Align(const char* query, const char* ref, const int& ref_len,
+uint16_t Aligner::Align(const char* query, const char* ref, const int& ref_len,
                     const Filter& filter, Alignment* alignment, const int32_t maskLen) const
 {
   if (!translation_matrix_) return false;
@@ -392,6 +385,7 @@ bool Aligner::Align(const char* query, const char* ref, const int& ref_len,
   alignment->Clear();
   ConvertAlignment(*s_al, query_len, alignment);
   alignment->mismatches = CalculateNumberMismatch(&*alignment, translated_ref, translated_query, query_len);
+  uint16_t align_flag = s_al->flag;
 
   // Free memory
   delete [] translated_query;
@@ -399,7 +393,7 @@ bool Aligner::Align(const char* query, const char* ref, const int& ref_len,
   align_destroy(s_al);
   init_destroy(profile);
 
-  return true;
+  return align_flag;
 }
 
 void Aligner::Clear(void) {
diff --git a/src/ssw_cpp.h b/src/ssw_cpp.h
index 4901352..c312fc1 100644
--- a/src/ssw_cpp.h
+++ b/src/ssw_cpp.h
@@ -1,6 +1,6 @@
 // ssw_cpp.h
 // Created by Wan-Ping Lee
-// Last revision by Mengyao Zhao on 2017-05-30
+// Last revision by Mengyao Zhao on 2023-Apr-21
 
 #ifndef COMPLETE_STRIPED_SMITH_WATERMAN_CPP_H_
 #define COMPLETE_STRIPED_SMITH_WATERMAN_CPP_H_
@@ -109,7 +109,7 @@ class Aligner {
   //                    and replaced.
   // @param    seq    The reference bases;
   //                  [NOTICE] It is not necessary null terminated.
-  // @param    length The length of bases will be be built.
+  // @param    length The length of bases will be built.
   // @return   The length of the built bases.
   // =========
   int SetReferenceSequence(const char* seq, const int& length);
@@ -134,9 +134,9 @@ class Aligner {
   // @param    maskLen   The distance between the optimal and suboptimal alignment ending position will >= maskLen. We suggest to 
   //                     use readLen/2, if you don't have special concerns. Note: maskLen has to be >= 15, otherwise this function 
   //                     will NOT return the suboptimal alignment information.
-  // @return   True: succeed; false: fail.
+  // @return   If the alignment path is accurate (or has missing part). 0: accurate; 1: banded_sw is totally failed; 2: banded_sw returned path has missing part
   // =========
-  bool Align(const char* query, const Filter& filter, Alignment* alignment, const int32_t maskLen) const;
+  uint16_t Align(const char* query, const Filter& filter, Alignment* alignment, const int32_t maskLen) const;
 
   // =========
   // @function Align the query againt the reference.
@@ -151,9 +151,9 @@ class Aligner {
   // @param    maskLen   The distance between the optimal and suboptimal alignment ending position will >= maskLen. We suggest to 
   //                     use readLen/2, if you don't have special concerns. Note: maskLen has to be >= 15, otherwise this function 
   //                     will NOT return the suboptimal alignment information.
-  // @return   True: succeed; false: fail.
+  // @return   If the alignment path is accurate (or has missing part). 0: accurate; 1: banded_sw is totally failed; 2: banded_sw returned path has missing part
   // =========
-  bool Align(const char* query, const char* ref, const int& ref_len,
+  uint16_t Align(const char* query, const char* ref, const int& ref_len,
              const Filter& filter, Alignment* alignment, const int32_t maskLen) const;
 
   // @function Clear up all containers and thus the aligner is disabled.

More details

Full run details

Historical runs