Refactor
authorMartin C. Frith
Wed Feb 27 14:29:58 2019 +0900 (6 months ago)
changeset 9731ed9db7f46ca
parent 972 ae880ec00591
child 974 2b0e54aee679
Refactor
src/lastal.cc
     1.1 --- a/src/lastal.cc	Wed Feb 27 09:56:54 2019 +0900
     1.2 +++ b/src/lastal.cc	Wed Feb 27 14:29:58 2019 +0900
     1.3 @@ -184,16 +184,7 @@
     1.4    }
     1.5  }
     1.6  
     1.7 -void makeQualityScorers(){
     1.8 -  if( args.isGreedy ) return;
     1.9 -
    1.10 -  if( args.isTranslated() )
    1.11 -    if( isUseQuality( args.inputFormat ) || isUseQuality( referenceFormat ) )
    1.12 -      return warn( args.programName,
    1.13 -		   "quality data not used for DNA-versus-protein alignment" );
    1.14 -
    1.15 -  const ScoreMatrixRow* m = fwdMatrices.scoresMasked;  // case isn't relevant
    1.16 -  const ScoreMatrixRow* mRev = revMatrices.scores;
    1.17 +void makeQualityScorers(SubstitutionMatrices &m, bool isCheck) {
    1.18    bool isMatchMismatch = (args.matrixFile.empty() && args.matchScore > 0);
    1.19    bool isPhred1 = isPhred( referenceFormat );
    1.20    int offset1 = qualityOffset( referenceFormat );
    1.21 @@ -203,75 +194,59 @@
    1.22  
    1.23    if( !isUseFastq( referenceFormat ) ){
    1.24      if( isUseFastq( args.inputFormat ) ){
    1.25 -      LOG( "calculating per-quality scores..." );
    1.26 +      if ( isCheck ) LOG( "calculating per-quality scores..." );
    1.27        if( args.maskLowercase > 0 )
    1.28 -	fwdMatrices.oneQualMasked.init(m, alph.size, fwdMatrices.stats,
    1.29 -				       isPhred2, offset2, toUnmasked, true);
    1.30 +	m.oneQualMasked.init(m.scores, alph.size, m.stats,
    1.31 +			     isPhred2, offset2, toUnmasked, true);
    1.32        if( args.maskLowercase < 3 )
    1.33 -	fwdMatrices.oneQual.init(m, alph.size, fwdMatrices.stats,
    1.34 -				 isPhred2, offset2, toUnmasked, false);
    1.35 +	m.oneQual.init(m.scores, alph.size, m.stats,
    1.36 +		       isPhred2, offset2, toUnmasked, false);
    1.37        const OneQualityScoreMatrix &q = (args.maskLowercase < 3) ?
    1.38 -	fwdMatrices.oneQual : fwdMatrices.oneQualMasked;
    1.39 +	m.oneQual : m.oneQualMasked;
    1.40        if( args.outputType > 3 )
    1.41 -        fwdMatrices.oneQualExp.init( q, args.temperature );
    1.42 -      if( args.verbosity > 0 )
    1.43 +        m.oneQualExp.init(q, args.temperature);
    1.44 +      if( isCheck && args.verbosity > 0 )
    1.45  	writeOneQualityScoreMatrix( q, alph.letters.c_str(),
    1.46  				    offset2, std::cerr );
    1.47 -      if( args.isQueryStrandMatrix && args.strand != 1 ){
    1.48 -	if( args.maskLowercase > 0 )
    1.49 -	  revMatrices.oneQualMasked.init(mRev, alph.size, revMatrices.stats,
    1.50 -					 isPhred2, offset2, toUnmasked, true);
    1.51 -	if( args.maskLowercase < 3 )
    1.52 -	  revMatrices.oneQual.init(mRev, alph.size, revMatrices.stats,
    1.53 -				   isPhred2, offset2, toUnmasked, false);
    1.54 -	const OneQualityScoreMatrix &qRev = (args.maskLowercase < 3) ?
    1.55 -	  revMatrices.oneQual : revMatrices.oneQualMasked;
    1.56 -	if( args.outputType > 3 )
    1.57 -	  revMatrices.oneQualExp.init( qRev, args.temperature );
    1.58 -      }
    1.59      }
    1.60      if( isUseQuality(args.inputFormat) ){
    1.61 -      fwdMatrices.maker.init(m, alph.size, fwdMatrices.stats.lambda(),
    1.62 -			     isMatchMismatch,
    1.63 -			     args.matchScore, -args.mismatchCost,
    1.64 -			     isPhred2, offset2, toUnmasked);
    1.65 -      if( args.isQueryStrandMatrix && args.strand != 1 )
    1.66 -	revMatrices.maker.init(mRev, alph.size, revMatrices.stats.lambda(),
    1.67 -			       isMatchMismatch,
    1.68 -			       args.matchScore, -args.mismatchCost,
    1.69 -			       isPhred2, offset2, toUnmasked);
    1.70 +      m.maker.init(m.scores, alph.size, m.stats.lambda(),
    1.71 +		   isMatchMismatch, args.matchScore, -args.mismatchCost,
    1.72 +		   isPhred2, offset2, toUnmasked);
    1.73      }
    1.74 -  }
    1.75 -  else{
    1.76 +  } else {
    1.77      if( isUseFastq( args.inputFormat ) ){
    1.78        if( args.maskLowercase > 0 )
    1.79 -	fwdMatrices.twoQualMasked.init(m, fwdMatrices.stats,
    1.80 -				       isPhred1, offset1, isPhred2, offset2,
    1.81 -				       toUnmasked, true, isMatchMismatch);
    1.82 +	m.twoQualMasked.init(m.scores, m.stats,
    1.83 +			     isPhred1, offset1, isPhred2, offset2,
    1.84 +			     toUnmasked, true, isMatchMismatch);
    1.85        if( args.maskLowercase < 3 )
    1.86 -	fwdMatrices.twoQual.init(m, fwdMatrices.stats,
    1.87 -				 isPhred1, offset1, isPhred2, offset2,
    1.88 -				 toUnmasked, false, isMatchMismatch);
    1.89 +	m.twoQual.init(m.scores, m.stats,
    1.90 +		       isPhred1, offset1, isPhred2, offset2,
    1.91 +		       toUnmasked, false, isMatchMismatch);
    1.92        if( args.outputType > 3 )
    1.93          ERR( "fastq-versus-fastq column probabilities not implemented" );
    1.94 -      if( args.isQueryStrandMatrix && args.strand != 1 ){
    1.95 -	if( args.maskLowercase > 0 )
    1.96 -	  revMatrices.twoQualMasked.init(mRev, revMatrices.stats,
    1.97 -					 isPhred1, offset1, isPhred2, offset2,
    1.98 -					 toUnmasked, true, isMatchMismatch);
    1.99 -	if( args.maskLowercase < 3 )
   1.100 -	  revMatrices.twoQual.init(mRev, revMatrices.stats,
   1.101 -				   isPhred1, offset1, isPhred2, offset2,
   1.102 -				   toUnmasked, false, isMatchMismatch);
   1.103 -      }
   1.104 -    }
   1.105 -    else{
   1.106 +    } else if (isCheck) {
   1.107        warn(args.programName,
   1.108  	   "quality data not used for non-fastq query versus fastq reference");
   1.109      }
   1.110    }
   1.111  }
   1.112  
   1.113 +void makeQualityScorers(){
   1.114 +  if( args.isGreedy ) return;
   1.115 +
   1.116 +  if( args.isTranslated() )
   1.117 +    if( isUseQuality( args.inputFormat ) || isUseQuality( referenceFormat ) )
   1.118 +      return warn( args.programName,
   1.119 +		   "quality data not used for DNA-versus-protein alignment" );
   1.120 +
   1.121 +  makeQualityScorers(fwdMatrices, true);
   1.122 +  if (args.isQueryStrandMatrix && args.strand != 1) {
   1.123 +    makeQualityScorers(revMatrices, false);
   1.124 +  }
   1.125 +}
   1.126 +
   1.127  // Calculate statistical parameters for the alignment scoring scheme
   1.128  static void calculateScoreStatistics(const std::string& matrixName,
   1.129  				     countT refLetters) {