public double compare ( IsotopePattern isoto1 , IsotopePattern isoto2 ) { IsotopePattern iso1 = IsotopePatternManipulator . sortAndNormalizedByIntensity ( isoto1 ) ; IsotopePattern iso2 = IsotopePatternManipulator . sortAndNormalizedByIntensity ( isoto2 ) ; /* charge to add */ if ( isoto1 . getCharge ( ) == 1 ) chargeToAdd = massE ; else if ( isoto1 . getCharge ( ) == - 1 ) chargeToAdd = - massE ; else chargeToAdd = 0 ; for ( IsotopeContainer isoC : iso1 . getIsotopes ( ) ) { double mass = isoC . getMass ( ) ; isoC . setMass ( mass + chargeToAdd ) ; } double diffMass , diffAbun , factor , totalFactor = 0d ; double score = 0d , tempScore ; // Maximum number of isotopes to be compared according predicted isotope // pattern. It is assumed that this will have always more isotopeContainers int length = iso1 . getNumberOfIsotopes ( ) ; for ( int i = 0 ; i < length ; i ++ ) { IsotopeContainer isoContainer = iso1 . getIsotopes ( ) . get ( i ) ; factor = isoContainer . getIntensity ( ) ; totalFactor += factor ; // Search for the closest isotope in the second pattern (detected) to the // current isotope (predicted pattern) int closestDp = getClosestDataDiff ( isoContainer , iso2 ) ; if ( closestDp == - 1 ) continue ; diffMass = isoContainer . getMass ( ) - iso2 . getIsotopes ( ) . get ( closestDp ) . getMass ( ) ; diffMass = Math . abs ( diffMass ) ; diffAbun = 1.0d - ( isoContainer . getIntensity ( ) / iso2 . getIsotopes ( ) . get ( closestDp ) . getIntensity ( ) ) ; diffAbun = Math . abs ( diffAbun ) ; tempScore = 1 - ( diffMass + diffAbun ) ; if ( tempScore < 0 ) tempScore = 0 ; score += ( tempScore * factor ) ; } return score / totalFactor ; }
Compare the IMolecularFormula with a isotope abundance pattern .