Skip to content

Commit

Permalink
Finalizing STARdiploid.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdobin committed Mar 8, 2023
1 parent 45fe3dd commit b4ea237
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
8 changes: 8 additions & 0 deletions source/ReadAlign_alignBAM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ int ReadAlign::alignBAM(Transcript const &trOut, uint nTrOut, uint iTrOut, uint
break;
};

case ATTR_ha:
{
if (mapGen.pGe.transform.type==2) {
attrN+=bamAttrArrayWrite( (int32) trOut.haploType, "ha", attrOutArray+attrN );
};
break;
};

case ATTR_ch:
if (alignType<=-10)
{//chimeric alignment
Expand Down
3 changes: 2 additions & 1 deletion source/ReadAlign_multMapSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void ReadAlign::multMapSelect() {//select multiple mappers from all transcripts
trMult[iTr]->cStart=trMult[iTr]->gStart - mapGen.chrStart[trMult[iTr]->Chr];
};


//TODO: use funPrimaryAlignMark
if (nTr==1){//unique mappers
trMult[0]->primaryFlag=true;
} else {//multimappers
Expand Down Expand Up @@ -91,4 +93,3 @@ void ReadAlign::multMapSelect() {//select multiple mappers from all transcripts

//TODO re-point trBest to the primary one. This should not make a difference in the output
};

39 changes: 39 additions & 0 deletions source/funPrimaryAlignFlag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
void funPrimaryAlignMark(Transcript **trMult, uint64 nTr, Parameters &P)
{
if (nTr==1){//unique mappers
trMult[0]->primaryFlag=true;
} else {//multimappers
int nbest=0;
if (P.outMultimapperOrder.random || P.outSAMmultNmax != (uint) -1 ) {//bring the best alignment to the top of the list. TODO sort alignments by the score?
for (uint itr=0; itr<nTr; itr++) {//move the best aligns to the top of the list
if ( trMult[itr]->maxScore == maxScore ) {
swap(trMult[itr],trMult[nbest]);
++nbest;
};
};
};

if (P.outMultimapperOrder.random) {//shuffle separately the best aligns, and the rest
for (int itr=nbest-1; itr>=1; itr--) {//Fisher-Yates-Durstenfeld-Knuth shuffle
int rand1=int (rngUniformReal0to1(rngMultOrder)*itr+0.5);
swap(trMult[itr],trMult[rand1]);
};
for (int itr=nTr-nbest-1; itr>=1; itr--) {//Fisher-Yates-Durstenfeld-Knuth shuffle
int rand1=int (rngUniformReal0to1(rngMultOrder)*itr+0.5);
swap(trMult[nbest+itr],trMult[nbest+rand1]);
};
};

if ( P.outSAMprimaryFlag=="AllBestScore" ) {
for (uint itr=0; itr<nTr; itr++)
{//mark all best score aligns as primary
if ( trMult[itr]->maxScore == maxScore ) trMult[itr]->primaryFlag=true;
};
} else if (P.outMultimapperOrder.random || P.outSAMmultNmax != (uint) -1) {
trMult[0]->primaryFlag=true;//mark as primary the first one in the random ordered list: best scoring aligns are already in front of the list
} else {//old way
trBest->primaryFlag=true;
};
};
};

0 comments on commit b4ea237

Please sign in to comment.