code: public static <C extends Sequence<D>, D extends Compound> DistanceMatrix percentageIdentity(
  			MultipleSequenceAlignment<C, D> msa) {
  
  		logger.info("{}:{}", "Determing Distances", 0);
  		int n = msa.getSize();
  		String[] sequenceString = new String[n];
  		for (int i = 0; i < n; i++) {
  			sequenceString[i] = msa.getAlignedSequence(i + 1)
  					.getSequenceAsString();
  		}
  
  		DistanceMatrix distance = new BasicSymmetricalDistanceMatrix(n);
  		int totalloopcount = (n / 2) * (n + 1);
  
  		int loopcount = 0;
  		for (int i = 0; i < (n - 1); i++) {
  			logger.info("{}:{}", "Determining Distances", (loopcount * 100)
  					/ totalloopcount);
  			distance.setIdentifier(i, msa.getAlignedSequence(i + 1)
  					.getAccession().getID());
  
  			for (int j = i; j < n; j++) {
  				loopcount++;
  				if (j == i) {
  					distance.setValue(i, j, 0);
  				} else {
  					distance.setValue(i, j, 100 - Comparison.PID(
  							sequenceString[i], sequenceString[j]));
  					distance.setValue(j, i, distance.getValue(i, j));
  				}
  			}
  		}
  		logger.info("{}:{}", "Determining Distances", 100);
  
  		return distance;
  	}
docs: BioJava implementation for percentage of identity (PID). Although the
  name of the method is percentage of identity, the DistanceMatrix contains
  the fractional dissimilarity (D), computed as D = 1 - PID.
  <p>
  It is recommended to use the method
  {@link DistanceMatrixCalculator#fractionalDissimilarity(MultipleSequenceAlignment)}
  instead of this one.
  
  @param msa
  MultipleSequenceAlignment
  @return DistanceMatrix