All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.biojava.nbio.alignment.Alignments Maven / Gradle / Ivy

There is a newer version: 7.1.3
Show newest version
/*
 *                    BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 *
 * Created on June 7, 2010
 * Author: Mark Chapman
 */

package org.biojava.nbio.alignment;

import org.biojava.nbio.core.alignment.template.ProfilePair;
import org.biojava.nbio.core.alignment.template.SequencePair;
import org.biojava.nbio.core.alignment.matrices.SubstitutionMatrixHelper;
import org.biojava.nbio.core.alignment.template.Profile;
import org.biojava.nbio.core.alignment.template.SubstitutionMatrix;
import org.biojava.nbio.alignment.template.*;
import org.biojava.nbio.core.sequence.compound.AmbiguityDNACompoundSet;
import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet;
import org.biojava.nbio.core.sequence.compound.DNACompoundSet;
import org.biojava.nbio.core.sequence.template.Compound;
import org.biojava.nbio.core.sequence.template.CompoundSet;
import org.biojava.nbio.core.sequence.template.Sequence;
import org.biojava.nbio.core.util.ConcurrencyTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * Static utility to easily run alignment routines.  To exit cleanly after running any parallel method that mentions
 * use of the {@link ConcurrencyTools} utility, {@link ConcurrencyTools#shutdown()} or
 * {@link ConcurrencyTools#shutdownAndAwaitTermination()} must be called.
 *
 * @author Mark Chapman
 */
public class Alignments {

	private final static Logger logger = LoggerFactory.getLogger(Alignments.class);

	/**
	 * List of implemented sequence pair in a profile scoring routines.
	 */
	public static enum PairInProfileScorerType {
		IDENTITIES,  // similar to MUSCLE
		SIMILARITIES
	}

	/**
	 * List of implemented pairwise sequence alignment routines.
	 */
	public static enum PairwiseSequenceAlignerType {
		GLOBAL,              // Needleman-Wunsch/Gotoh
		GLOBAL_LINEAR_SPACE, // Guan-Uberbacher
		LOCAL,               // Smith-Waterman/Gotoh
		LOCAL_LINEAR_SPACE   // Smith-Waterman/Gotoh with smart traceback at each maximum
	}

	/**
	 * List of implemented pairwise sequence scoring routines.
	 */
	public static enum PairwiseSequenceScorerType {
		GLOBAL,
		GLOBAL_IDENTITIES,   // similar to CLUSTALW and CLUSTALW2
		GLOBAL_SIMILARITIES,
		LOCAL,
		LOCAL_IDENTITIES,
		LOCAL_SIMILARITIES,
		KMERS,               // similar to CLUSTAL and MUSCLE
		WU_MANBER            // similar to KALIGN
	}

	/**
	 * List of implemented profile-profile alignment routines.
	 */
	public static enum ProfileProfileAlignerType {
		GLOBAL,              // similar to MUSCLE and KALIGN
		GLOBAL_LINEAR_SPACE, // similar to CLUSTALW and CLUSTALW2
		GLOBAL_CONSENSUS,    // similar to CLUSTAL
		LOCAL,
		LOCAL_LINEAR_SPACE,
		LOCAL_CONSENSUS
	}

	/**
	 * List of implemented profile refinement routines.
	 */
	public static enum RefinerType {
		PARTITION_SINGLE,     // similar to CLUSTALW2
		PARTITION_SINGLE_ALL, // similar to CLUSTALW2
		PARTITION_TREE,       // similar to MUSCLE
		PARTITION_TREE_ALL,
		RESCORE_IDENTITIES,   // similar to MUSCLE
		RESCORE_SIMILARITIES
	}

	// prevents instantiation
	private Alignments() { }

	// public factory methods

	/**
	 * Factory method which computes a sequence alignment for all {@link Sequence} pairs in the given {@link List}.
	 * This method runs the alignments in parallel by submitting all of the alignments to the shared thread pool of the
	 * {@link ConcurrencyTools} utility.
	 *
	 * @param  each {@link Sequence} of an alignment pair is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param sequences the {@link List} of {@link Sequence}s to align
	 * @param type chosen type from list of pairwise sequence alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return list of sequence alignment pairs
	 */
	public static , C extends Compound> List> getAllPairsAlignments(
			List sequences, PairwiseSequenceAlignerType type, GapPenalty gapPenalty,
			SubstitutionMatrix subMatrix) {
		return runPairwiseAligners(getAllPairsAligners(sequences, type, gapPenalty, subMatrix));
	}

	/**
	 * Factory method which computes a multiple sequence alignment for the given {@link List} of {@link Sequence}s.
	 *
	 * @param  each {@link Sequence} of the {@link List} is of type S
	 * @param  each element of a {@link Sequence} is a {@link Compound} of type C
	 * @param sequences the {@link List} of {@link Sequence}s to align
	 * @param settings optional settings that adjust the alignment
	 * @return multiple sequence alignment {@link Profile}
	 */
	public static , C extends Compound> Profile getMultipleSequenceAlignment(
			List sequences, Object... settings) { // TODO convert other factories to this parameter style?
		CompoundSet cs = sequences.get(0).getCompoundSet();
		PairwiseSequenceScorerType ps = PairwiseSequenceScorerType.GLOBAL_IDENTITIES;
		GapPenalty gapPenalty = new SimpleGapPenalty();
		SubstitutionMatrix subMatrix = null;
		if (cs == AminoAcidCompoundSet.getAminoAcidCompoundSet()) {
			@SuppressWarnings("unchecked") // compound types must be equal since compound sets are equal
			SubstitutionMatrix temp = (SubstitutionMatrix) SubstitutionMatrixHelper.getBlosum62();
			subMatrix = temp;
		} else if (cs == DNACompoundSet.getDNACompoundSet()) {
			@SuppressWarnings("unchecked") // compound types must be equal since compound sets are equal
			SubstitutionMatrix temp = (SubstitutionMatrix) SubstitutionMatrixHelper.getNuc4_4();
			subMatrix = temp;

		} else if (cs == AmbiguityDNACompoundSet.getDNACompoundSet()) {
			@SuppressWarnings("unchecked") // compound types must be equal since compound sets are equal
			SubstitutionMatrix temp = (SubstitutionMatrix) SubstitutionMatrixHelper.getNuc4_4();
			subMatrix = temp;

		}
		ProfileProfileAlignerType pa = ProfileProfileAlignerType.GLOBAL;
		for (Object o : settings) {
			if (o instanceof PairwiseSequenceScorerType) {
				ps = (PairwiseSequenceScorerType) o;
			} else if (o instanceof GapPenalty) {
				gapPenalty = (GapPenalty) o;
			} else if (o instanceof SubstitutionMatrix) {
				if (cs != ((SubstitutionMatrix) o).getCompoundSet()) {
					throw new IllegalArgumentException(
							"Compound sets of the sequences and substitution matrix must match.");
				}
				@SuppressWarnings("unchecked") // compound types must be equal since compound sets are equal
				SubstitutionMatrix temp = (SubstitutionMatrix) o;
				subMatrix = temp;
			} else if (o instanceof ProfileProfileAlignerType) {
				pa = (ProfileProfileAlignerType) o;
			}
		}

		// stage 1: pairwise similarity calculation
		List> scorers = getAllPairsScorers(sequences, ps, gapPenalty, subMatrix);
		runPairwiseScorers(scorers);

		// stage 2: hierarchical clustering into a guide tree
		GuideTree tree = new GuideTree(sequences, scorers);
		scorers = null;

		// stage 3: progressive alignment
		Profile msa = getProgressiveAlignment(tree, pa, gapPenalty, subMatrix);

		// TODO stage 4: refinement
		return msa;
	}

	/**
	 * Factory method which computes a sequence alignment for the given {@link Sequence} pair.
	 *
	 * @param  each {@link Sequence} of the pair is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param query the first {@link Sequence}s to align
	 * @param target the second {@link Sequence}s to align
	 * @param type chosen type from list of pairwise sequence alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return sequence alignment pair
	 */
	public static , C extends Compound> SequencePair getPairwiseAlignment(
			S query, S target, PairwiseSequenceAlignerType type, GapPenalty gapPenalty,
			SubstitutionMatrix subMatrix) {
		return getPairwiseAligner(query, target, type, gapPenalty, subMatrix).getPair();
	}

	// default access (package private) factory methods

	/**
	 * Factory method which sets up a sequence alignment for all {@link Sequence} pairs in the given {@link List}.
	 *
	 * @param  each {@link Sequence} of an alignment pair is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param sequences the {@link List} of {@link Sequence}s to align
	 * @param type chosen type from list of pairwise sequence alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return list of pairwise sequence aligners
	 */
	static , C extends Compound> List> getAllPairsAligners(
			List sequences, PairwiseSequenceAlignerType type, GapPenalty gapPenalty,
			SubstitutionMatrix subMatrix) {
		List> allPairs = new ArrayList>();
		for (int i = 0; i < sequences.size(); i++) {
			for (int j = i+1; j < sequences.size(); j++) {
				allPairs.add(getPairwiseAligner(sequences.get(i), sequences.get(j), type, gapPenalty, subMatrix));
			}
		}
		return allPairs;
	}

	/**
	 * Factory method which sets up a sequence pair scorer for all {@link Sequence} pairs in the given {@link List}.
	 *
	 * @param  each {@link Sequence} of a pair is of type S
	 * @param  each element of a {@link Sequence} is a {@link Compound} of type C
	 * @param sequences the {@link List} of {@link Sequence}s to align
	 * @param type chosen type from list of pairwise sequence scoring routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return list of sequence pair scorers
	 */
	public static , C extends Compound> List> getAllPairsScorers(
			List sequences, PairwiseSequenceScorerType type, GapPenalty gapPenalty,
			SubstitutionMatrix subMatrix) {
		List> allPairs = new ArrayList>();
		for (int i = 0; i < sequences.size(); i++) {
			for (int j = i+1; j < sequences.size(); j++) {
				allPairs.add(getPairwiseScorer(sequences.get(i), sequences.get(j), type, gapPenalty, subMatrix));
			}
		}
		return allPairs;
	}

	/**
	 * Factory method which computes a sequence pair score for all {@link Sequence} pairs in the given {@link List}.
	 * This method runs the scorings in parallel by submitting all of the scorings to the shared thread pool of the
	 * {@link ConcurrencyTools} utility.
	 *
	 * @param  each {@link Sequence} of a pair is of type S
	 * @param  each element of a {@link Sequence} is a {@link Compound} of type C
	 * @param sequences the {@link List} of {@link Sequence}s to align
	 * @param type chosen type from list of pairwise sequence scoring routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return list of sequence pair scores
	 */
	public static , C extends Compound> double[] getAllPairsScores( List sequences,
			PairwiseSequenceScorerType type, GapPenalty gapPenalty, SubstitutionMatrix subMatrix) {
		return runPairwiseScorers(getAllPairsScorers(sequences, type, gapPenalty, subMatrix));
	}

	/**
	 * Factory method which retrieves calculated elements from a list of tasks on the concurrent execution queue.
	 *
	 * @param  each task calculates a value of type E
	 * @param futures list of tasks
	 * @return calculated elements
	 */
	static  List getListFromFutures(List> futures) {
		List list = new ArrayList();
		for (Future f : futures) {
			// TODO when added to ConcurrencyTools, log completions and exceptions instead of printing stack traces
			try {
				list.add(f.get());
			} catch (InterruptedException e) {
				logger.error("Interrupted Exception: ", e);
			} catch (ExecutionException e) {
				logger.error("Execution Exception: ", e);
			}
		}
		return list;
	}

	/**
	 * Factory method which constructs a pairwise sequence aligner.
	 *
	 * @param  each {@link Sequence} of an alignment pair is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param query the first {@link Sequence} to align
	 * @param target the second {@link Sequence} to align
	 * @param type chosen type from list of pairwise sequence alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return pairwise sequence aligner
	 */
	public static , C extends Compound> PairwiseSequenceAligner getPairwiseAligner(
			S query, S target, PairwiseSequenceAlignerType type, GapPenalty gapPenalty,
			SubstitutionMatrix subMatrix) {
		if (!query.getCompoundSet().equals(target.getCompoundSet())) {
			throw new IllegalArgumentException("Sequence compound sets must be the same");
		}
		switch (type) {
		default:
		case GLOBAL:
			return new NeedlemanWunsch(query, target, gapPenalty, subMatrix);
		case LOCAL:
			return new SmithWaterman(query, target, gapPenalty, subMatrix);
		case GLOBAL_LINEAR_SPACE:
		case LOCAL_LINEAR_SPACE:
			// TODO other alignment options (Myers-Miller, Thompson)
			throw new UnsupportedOperationException(Alignments.class.getSimpleName() + " does not yet support " +
					type + " alignment");
		}
	}

	/**
	 * Factory method which computes a similarity score for the given {@link Sequence} pair.
	 *
	 * @param  each {@link Sequence} of the pair is of type S
	 * @param  each element of a {@link Sequence} is a {@link Compound} of type C
	 * @param query the first {@link Sequence} to score
	 * @param target the second {@link Sequence} to score
	 * @param type chosen type from list of pairwise sequence scoring routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return sequence pair score
	 */
	static , C extends Compound> double getPairwiseScore(S query, S target,
			PairwiseSequenceScorerType type, GapPenalty gapPenalty, SubstitutionMatrix subMatrix) {
		return getPairwiseScorer(query, target, type, gapPenalty, subMatrix).getScore();
	}

	/**
	 * Factory method which constructs a pairwise sequence scorer.
	 *
	 * @param  each {@link Sequence} of a pair is of type S
	 * @param  each element of a {@link Sequence} is a {@link Compound} of type C
	 * @param query the first {@link Sequence} to score
	 * @param target the second {@link Sequence} to score
	 * @param type chosen type from list of pairwise sequence scoring routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return sequence pair scorer
	 */
	static , C extends Compound> PairwiseSequenceScorer getPairwiseScorer(
			S query, S target, PairwiseSequenceScorerType type, GapPenalty gapPenalty,
			SubstitutionMatrix subMatrix) {
		switch (type) {
		default:
		case GLOBAL:
			return getPairwiseAligner(query, target, PairwiseSequenceAlignerType.GLOBAL, gapPenalty, subMatrix);
		case GLOBAL_IDENTITIES:
			return new FractionalIdentityScorer(getPairwiseAligner(query, target,
					PairwiseSequenceAlignerType.GLOBAL, gapPenalty, subMatrix));
		case GLOBAL_SIMILARITIES:
			return new FractionalSimilarityScorer(getPairwiseAligner(query, target,
					PairwiseSequenceAlignerType.GLOBAL, gapPenalty, subMatrix));
		case LOCAL:
			return getPairwiseAligner(query, target, PairwiseSequenceAlignerType.LOCAL, gapPenalty, subMatrix);
		case LOCAL_IDENTITIES:
			return new FractionalIdentityScorer(getPairwiseAligner(query, target,
					PairwiseSequenceAlignerType.LOCAL, gapPenalty, subMatrix));
		case LOCAL_SIMILARITIES:
			return new FractionalSimilarityScorer(getPairwiseAligner(query, target,
					PairwiseSequenceAlignerType.LOCAL, gapPenalty, subMatrix));
		case KMERS:
		case WU_MANBER:
			// TODO other scoring options
			throw new UnsupportedOperationException(Alignments.class.getSimpleName() + " does not yet support " +
					type + " scoring");
		}
	}

	/**
	 * Factory method which constructs a profile-profile aligner.
	 *
	 * @param  each {@link Sequence} of an alignment profile is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param profile1 the first {@link Profile} to align
	 * @param profile2 the second {@link Profile} to align
	 * @param type chosen type from list of profile-profile alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return profile-profile aligner
	 */
	static , C extends Compound> ProfileProfileAligner getProfileProfileAligner(
			Profile profile1, Profile profile2, ProfileProfileAlignerType type, GapPenalty gapPenalty,
			SubstitutionMatrix subMatrix) {
		switch (type) {
		default:
		case GLOBAL:
			return new SimpleProfileProfileAligner(profile1, profile2, gapPenalty, subMatrix);
		case GLOBAL_LINEAR_SPACE:
		case GLOBAL_CONSENSUS:
		case LOCAL:
		case LOCAL_LINEAR_SPACE:
		case LOCAL_CONSENSUS:
			// TODO other alignment options (Myers-Miller, consensus, local)
			throw new UnsupportedOperationException(Alignments.class.getSimpleName() + " does not yet support " +
					type + " alignment");
		}
	}

	/**
	 * Factory method which constructs a profile-profile aligner.
	 *
	 * @param  each {@link Sequence} of an alignment profile is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param profile1 the first {@link Profile} to align
	 * @param profile2 the second {@link Profile} to align
	 * @param type chosen type from list of profile-profile alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return profile-profile aligner
	 */
	static , C extends Compound> ProfileProfileAligner getProfileProfileAligner(
			Future> profile1, Future> profile2, ProfileProfileAlignerType type,
			GapPenalty gapPenalty, SubstitutionMatrix subMatrix) {
		switch (type) {
		default:
		case GLOBAL:
			return new SimpleProfileProfileAligner(profile1, profile2, gapPenalty, subMatrix);
		case GLOBAL_LINEAR_SPACE:
		case GLOBAL_CONSENSUS:
		case LOCAL:
		case LOCAL_LINEAR_SPACE:
		case LOCAL_CONSENSUS:
			// TODO other alignment options (Myers-Miller, consensus, local)
			throw new UnsupportedOperationException(Alignments.class.getSimpleName() + " does not yet support " +
					type + " alignment");
		}
	}

	/**
	 * Factory method which constructs a profile-profile aligner.
	 *
	 * @param  each {@link Sequence} of an alignment profile is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param profile1 the first {@link Profile} to align
	 * @param profile2 the second {@link Profile} to align
	 * @param type chosen type from list of profile-profile alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return profile-profile aligner
	 */
	static , C extends Compound> ProfileProfileAligner getProfileProfileAligner(
			Profile profile1, Future> profile2, ProfileProfileAlignerType type,
			GapPenalty gapPenalty, SubstitutionMatrix subMatrix) {
		switch (type) {
		default:
		case GLOBAL:
			return new SimpleProfileProfileAligner(profile1, profile2, gapPenalty, subMatrix);
		case GLOBAL_LINEAR_SPACE:
		case GLOBAL_CONSENSUS:
		case LOCAL:
		case LOCAL_LINEAR_SPACE:
		case LOCAL_CONSENSUS:
			// TODO other alignment options (Myers-Miller, consensus, local)
			throw new UnsupportedOperationException(Alignments.class.getSimpleName() + " does not yet support " +
					type + " alignment");
		}
	}

	/**
	 * Factory method which constructs a profile-profile aligner.
	 *
	 * @param  each {@link Sequence} of an alignment profile is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param profile1 the first {@link Profile} to align
	 * @param profile2 the second {@link Profile} to align
	 * @param type chosen type from list of profile-profile alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return profile-profile aligner
	 */
	static , C extends Compound> ProfileProfileAligner getProfileProfileAligner(
			Future> profile1, Profile profile2, ProfileProfileAlignerType type,
			GapPenalty gapPenalty, SubstitutionMatrix subMatrix) {
		switch (type) {
		default:
		case GLOBAL:
			return new SimpleProfileProfileAligner(profile1, profile2, gapPenalty, subMatrix);
		case GLOBAL_LINEAR_SPACE:
		case GLOBAL_CONSENSUS:
		case LOCAL:
		case LOCAL_LINEAR_SPACE:
		case LOCAL_CONSENSUS:
			// TODO other alignment options (Myers-Miller, consensus, local)
			throw new UnsupportedOperationException(Alignments.class.getSimpleName() + " does not yet support " +
					type + " alignment");
		}
	}

	/**
	 * Factory method which computes a profile alignment for the given {@link Profile} pair.
	 *
	 * @param  each {@link Sequence} of the {@link Profile} pair is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param profile1 the first {@link Profile} to align
	 * @param profile2 the second {@link Profile} to align
	 * @param type chosen type from list of profile-profile alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return alignment profile
	 */
	static , C extends Compound> ProfilePair getProfileProfileAlignment(
			Profile profile1, Profile profile2, ProfileProfileAlignerType type, GapPenalty gapPenalty,
			SubstitutionMatrix subMatrix) {
		return getProfileProfileAligner(profile1, profile2, type, gapPenalty, subMatrix).getPair();
	}

	/**
	 * Factory method to run the profile-profile alignments of a progressive multiple sequence alignment concurrently.
	 * This method runs the alignments in parallel by submitting all of the alignment tasks to the shared thread pool
	 * of the {@link ConcurrencyTools} utility.
	 *
	 * @param  each {@link Sequence} of the {@link Profile} pair is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param tree guide tree to follow aligning profiles from leaves to root
	 * @param type chosen type from list of profile-profile alignment routines
	 * @param gapPenalty the gap penalties used during alignment
	 * @param subMatrix the set of substitution scores used during alignment
	 * @return multiple sequence alignment
	 */
	public static , C extends Compound> Profile getProgressiveAlignment(GuideTree tree,
			ProfileProfileAlignerType type, GapPenalty gapPenalty, SubstitutionMatrix subMatrix) {

		// find inner nodes in post-order traversal of tree (each leaf node has a single sequence profile)
		List> innerNodes = new ArrayList>();
		for (GuideTreeNode n : tree) {
			if (n.getProfile() == null) {
				innerNodes.add(n);
			}
		}

		// submit alignment tasks to the shared thread pool
		int i = 1, all = innerNodes.size();
		for (GuideTreeNode n : innerNodes) {
			Profile p1 = n.getChild1().getProfile(), p2 = n.getChild2().getProfile();
			Future> pf1 = n.getChild1().getProfileFuture(), pf2 = n.getChild2().getProfileFuture();
			ProfileProfileAligner aligner =
					(p1 != null) ? ((p2 != null) ? getProfileProfileAligner(p1, p2, type, gapPenalty, subMatrix) :
							getProfileProfileAligner(p1, pf2, type, gapPenalty, subMatrix)) :
					((p2 != null) ? getProfileProfileAligner(pf1, p2, type, gapPenalty, subMatrix) :
							getProfileProfileAligner(pf1, pf2, type, gapPenalty, subMatrix));
			n.setProfileFuture(ConcurrencyTools.submit(new CallableProfileProfileAligner(aligner), String.format(
					"Aligning pair %d of %d", i++, all)));
		}

		// retrieve the alignment results
		for (GuideTreeNode n : innerNodes) {
			// TODO when added to ConcurrencyTools, log completions and exceptions instead of printing stack traces
			try {
				n.setProfile(n.getProfileFuture().get());
			} catch (InterruptedException e) {
				logger.error("Interrupted Exception: ", e);
			} catch (ExecutionException e) {
				logger.error("Execution Exception: ", e);
			}
		}

		// the alignment profile at the root of the tree is the full multiple sequence alignment
		return tree.getRoot().getProfile();
	}

	/**
	 * Factory method to run a list of alignments concurrently.  This method runs the alignments in parallel by
	 * submitting all of the alignment tasks to the shared thread pool of the {@link ConcurrencyTools} utility.
	 *
	 * @param  each {@link Sequence} of an alignment pair is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param aligners list of alignments to run
	 * @return list of {@link SequencePair} results from running alignments
	 */
	static , C extends Compound> List>
			runPairwiseAligners(List> aligners) {
		int n = 1, all = aligners.size();
		List>> futures = new ArrayList>>();
		for (PairwiseSequenceAligner aligner : aligners) {
			futures.add(ConcurrencyTools.submit(new CallablePairwiseSequenceAligner(aligner),
					String.format("Aligning pair %d of %d", n++, all)));
		}
		return getListFromFutures(futures);
	}

	/**
	 * Factory method to run a list of scorers concurrently.  This method runs the scorers in parallel by submitting
	 * all of the scoring tasks to the shared thread pool of the {@link ConcurrencyTools} utility.
	 *
	 * @param  each {@link Sequence} of an alignment pair is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param scorers list of scorers to run
	 * @return list of score results from running scorers
	 */
	public static , C extends Compound> double[] runPairwiseScorers(
			List> scorers) {
		int n = 1, all = scorers.size();
		List> futures = new ArrayList>();
		for (PairwiseSequenceScorer scorer : scorers) {
			futures.add(ConcurrencyTools.submit(new CallablePairwiseSequenceScorer(scorer),
					String.format("Scoring pair %d of %d", n++, all)));
		}
		List results = getListFromFutures(futures);
		double[] scores = new double[results.size()];
		for (int i = 0; i < scores.length; i++) {
			scores[i] = results.get(i);
		}
		return scores;
	}

	/**
	 * Factory method to run a list of alignments concurrently.  This method runs the alignments in parallel by
	 * submitting all of the alignment tasks to the shared thread pool of the {@link ConcurrencyTools} utility.
	 *
	 * @param  each {@link Sequence} of the {@link Profile} pair is of type S
	 * @param  each element of an {@link AlignedSequence} is a {@link Compound} of type C
	 * @param aligners list of alignments to run
	 * @return list of {@link ProfilePair} results from running alignments
	 */
	static , C extends Compound> List>
			runProfileAligners(List> aligners) {
		int n = 1, all = aligners.size();
		List>> futures = new ArrayList>>();
		for (ProfileProfileAligner aligner : aligners) {
			futures.add(ConcurrencyTools.submit(new CallableProfileProfileAligner(aligner),
					String.format("Aligning pair %d of %d", n++, all)));
		}
		return getListFromFutures(futures);
	}

}