@@ -27,12 +27,12 @@ void MashPlacement::MSADeviceArrays::allocateDeviceArrays(uint64_t ** h_compress
2727 // std::cerr<<"????????\n";
2828 /* Flatten data */
2929 uint64_t flatStringLength=0 ;
30- for (size_t i =0 ; i<numSequences; i++) flatStringLength+= (h_seqLengths[i]+15 )/16 ;
30+ for (size_t i =0 ; i<numSequences; i++) flatStringLength+= params. isProtein ? (h_seqLengths[i]+ 7 )/ 8 : (h_seqLengths[i]+15 )/16 ;
3131 uint64_t * h_flattenCompressSeqs = new uint64_t [flatStringLength];
3232 flatStringLength=0 ;
3333 for (size_t i =0 ; i<numSequences; i++)
3434 {
35- uint64_t flatStringLengthLocal = (h_seqLengths[i]+15 )/16 ;
35+ uint64_t flatStringLengthLocal = params. isProtein ? (h_seqLengths[i]+ 7 )/ 8 : (h_seqLengths[i]+15 )/16 ;
3636 flatStringLength+=flatStringLengthLocal;
3737 for (size_t j=0 ; j<flatStringLengthLocal;j++)
3838 {
@@ -100,9 +100,9 @@ __device__ void calculateParams(int tarRowId, int curRowId, int seqLen, uint64_t
100100}
101101
102102
103- __device__ void calculateParamsParallel (int tarRowId, int curRowId, int seqLen, uint64_t * compressedSeqs, int & useful, int & match){
103+ __device__ void calculateParamsParallel (int tarRowId, int curRowId, int seqLen, uint64_t * compressedSeqs, int & useful, int & match, bool isProtein ){
104104 int tx=threadIdx .x , bs=blockDim .x , bx=blockIdx .x ;
105- int compLen=(seqLen+15 )/16 ;
105+ int compLen=isProtein ? (seqLen+ 7 )/ 8 : (seqLen+15 )/16 ;
106106 long long px=1ll *curRowId*compLen, py=1ll *tarRowId*compLen;
107107
108108 // create a shared memory array to store results
@@ -116,10 +116,18 @@ __device__ void calculateParamsParallel(int tarRowId, int curRowId, int seqLen,
116116 }
117117 for (int i=tx; i<compLen; i+=1024 ) {
118118 long long vt=compressedSeqs[px+i], vc=compressedSeqs[py+i];
119- for (int j=0 ;j<16 &&i*16 +j<seqLen;j++){
120- int et=(vt>>(j*4 ))&15 , ec=(vc>>(j*4 ))&15 ;
121- if (et<4 ||ec<4 ) sharedUseful[tx]++;
122- if (et<4 &&et==ec) sharedMatch[tx]++;
119+ if (isProtein) {
120+ for (int j=0 ;j<8 &&i*8 +j<seqLen;j++){
121+ int et=(vt>>(j*8 ))&255 , ec=(vc>>(j*8 ))&255 ;
122+ if (et<20 ||ec<20 ) sharedUseful[tx]++;
123+ if (et<20 &&et==ec) sharedMatch[tx]++;
124+ }
125+ } else {
126+ for (int j=0 ;j<16 &&i*16 +j<seqLen;j++){
127+ int et=(vt>>(j*4 ))&15 , ec=(vc>>(j*4 ))&15 ;
128+ if (et<4 ||ec<4 ) sharedUseful[tx]++;
129+ if (et<4 &&et==ec) sharedMatch[tx]++;
130+ }
123131 }
124132 }
125133 __syncthreads ();
@@ -413,7 +421,8 @@ __global__ void MSADistConstruction(
413421 double * dist,
414422 int seqLen,
415423 int numSequences,
416- int distanceType
424+ int distanceType,
425+ bool isProtein
417426){
418427 int tx=threadIdx .x , bs=blockDim .x , bx=blockIdx .x ;
419428 int idx=tx+bs*bx;
@@ -423,12 +432,17 @@ __global__ void MSADistConstruction(
423432 // printf("bx: %d, rowId: %d\n", blockID, rowId);
424433 if (distanceType==DIST_UNCORRECTED ||distanceType==DIST_JUKESCANTOR ){
425434 int useful=0 , match=0 ;
426- calculateParamsParallel (rowId, blockID, seqLen, compressedSeqs, useful, match);
435+ calculateParamsParallel (rowId, blockID, seqLen, compressedSeqs, useful, match, isProtein );
427436 // calculateParams(rowId, idx, seqLen, compressedSeqs, useful, match);
428437 if (tx == 0 ) {
429438 double uncor=1 -double (match)/useful;
430439 if (distanceType==DIST_UNCORRECTED ) dist[blockID]=uncor;
431- else dist[blockID]=-0.75 *log (1.0 -uncor/0.75 );
440+ else {
441+ if (isProtein) dist[blockID]= 2 *(1 /sqrt (1 - uncor)) -1 ;
442+ else dist[blockID]=-0.75 *log (1.0 -uncor/0.75 );
443+ }
444+ // else dist[blockID] = -log(1-uncor-0.2*uncor*uncor); // For amino acids
445+ // else dist[blockID]= 2*(1/sqrt(1 - uncor)) -1;
432446 // printf("%d %d %d %d\n",rowId, blockID, match, useful);
433447 }
434448 }
@@ -474,7 +488,7 @@ __global__ void MSADistConstruction(
474488}
475489
476490
477- void MashPlacement::MSADeviceArrays::distConstructionOnGpu (Param& params, int rowId, double * d_mashDist) const {
491+ void MashPlacement::MSADeviceArrays::distConstructionOnGpu (Param& params, int rowId, double * d_mashDist) const {
478492 int threadNum = 1024 , blockNum = 1024 ; // dont change threadNUM, interally it is used to calculate the distance
479493 // printf("rowId: %d params.distanceType %d \n", rowId, params.distanceType);
480494 MSADistConstruction <<<blockNum, threadNum>>> (
@@ -483,7 +497,9 @@ void MashPlacement::MSADeviceArrays::distConstructionOnGpu(Param& params, int ro
483497 d_mashDist,
484498 seqLen,
485499 numSequences,
486- params.distanceType
500+ params.distanceType ,
501+ params.isProtein
487502 );
488503}
489504
505+
0 commit comments