static void NudgeWholeSequence(AlignedMacromolecule macromolecule, int nudgeAmount) // Moves the entire sequences given by the sequenceIndices by the nudgeAmount. { //int[] seqAlignedPos = alignedMacromolecules[index].Item2; int[] seqAlignedPos = macromolecule.AlignedPositions; for (int i = 0; i < seqAlignedPos.Length; i++) { seqAlignedPos[i] += nudgeAmount; } }
//internal void RemoveAlignedMacromolecule(Tuple<Macromolecule, int[]> alignedMacromoleculeToRemove, bool doAdjustments = true) internal void RemoveAlignedMacromolecule(AlignedMacromolecule alignedMacromoleculeToRemove, bool doAdjustments = true) // Provides an interface to remove an aligned macromolecule from the list. { alignedMacromolecules.Remove(alignedMacromoleculeToRemove); if (doAdjustments) { NormalizeAlignedPositions(); CalculateAlignmentLength(); NotifyPropertyChanged("AlignedMacromolecules"); RecalculateMaximumLength(); } }
public AlignedMacromolecule Copy() { //Produces a copy of the alignment information only, and sets sequemceWeight to 0 AlignedMacromolecule copy = new AlignedMacromolecule(this, (int[])alignedPositions.Clone()); foreach (int newGap in newGaps) { copy.newGaps.Add(newGap); } sequenceWeight = 0; return(copy); }
//internal void AddAlignedMacromolecule(Tuple<Macromolecule, int[]> newAlignedMacromolecule, bool doAdjustments = true) internal void AddAlignedMacromolecule(AlignedMacromolecule newAlignedMacromolecule, bool doAdjustments = true) // Provides an interface to add an aligned macromolecule to the list. // Adjust the name if it is not unique, adjust the alignmentLength, and add it to the list. { //Macromolecule newMacromolecule = newAlignedMacromolecule.Item1; Macromolecule newMacromolecule = newAlignedMacromolecule; // Rename the macromolecule if another with the same name is already loaded. // Appends a "1" if already exists; then if this new name matches another, add "2", etc. // Could lead to some weirdness if the loaded sequences were "seq1" "seq4" "seq4", which would // become "seq1", "seq4", "seq4 1", but this is tolerable. int nameInteger = 1; for (int i = 0; i < alignedMacromolecules.Count; i++) { //Macromolecule testMacromolecule = alignedMacromolecules[i].Item1; Macromolecule testMacromolecule = alignedMacromolecules[i]; if (newMacromolecule.Name == testMacromolecule.Name) // same name { newMacromolecule.Name += " " + nameInteger.ToString(); nameInteger++; } } alignedMacromolecules.Add(newAlignedMacromolecule); if (doAdjustments) { // Make into another sub so the Add routines can be synced? NormalizeAlignedPositions(); CalculateAlignmentLength(); NotifyPropertyChanged("AlignedMacromolecules"); //isNucleicAcid = newAlignedMacromolecule.Item1.IsNucleicAcid; isNucleicAcid = newAlignedMacromolecule.IsNucleicAcid; NotifyPropertyChanged("IsNucleicAcid"); RecalculateMaximumLength(); } }
internal static void Align(ref Alignment alignmentObject, ref BackgroundWorker myBackgroundWorker) // Runs complete Clustal multiple sequence alignment on all loaded molecules { // Currently not set up to save files during alignment. // Also not set to use the "stats" option if (alignmentObject.IsNucleicAcid) { // Load alignment parameters for nucleic acids } else { // Load alignment parameters for protein } // Step 1: Do pairwise alignments and generate the distance matrix myBackgroundWorker.ReportProgress(0, "Starting pairwise alignments..."); int numSequences = alignmentObject.NumberMacromolecules; double[,] distanceMatrix = new double[numSequences, numSequences]; // This will select between fast and full pairwise alignment. Just implementing fast alignment to start. PairwiseAlignment.IPairwiseAlignmentAlgorithm pairwiseAlignmentAlgorithm; if (true) { // This sub basically calculates the score of the best alignment between each pair of sequences pairwiseAlignmentAlgorithm = new PairwiseAlignment.FastPairwiseAlignment(); } else { throw new NotImplementedException("Full Pairwise Alignment is not yet implemented"); // pairwiseAlignmentAlgorithm = new PairwiseAlignment.FullPairwiseAlignment(); } pairwiseAlignmentAlgorithm.PairwiseAlign(ref alignmentObject, ref distanceMatrix); // Step 2: Generate a phylogenetic tree of the sequences from the distance matrix myBackgroundWorker.ReportProgress(0, "Generating phylogenetic tree..."); AlignedMacromolecule[] macromolecules = new AlignedMacromolecule[alignmentObject.NumberMacromolecules]; ReadOnlyCollection <AlignedMacromolecule> alignedMacromolecules = alignmentObject.AlignedMacromolecules; for (int i = 0; i < alignmentObject.NumberMacromolecules; i++) { macromolecules[i] = alignedMacromolecules[i]; } Tree.GuideTree <AlignedMacromolecule> tree = Tree.GuideTree <AlignedMacromolecule> .GetWeightsAndSteps(ref distanceMatrix, macromolecules); // Transfer the weights from the tree to the macromolecules and fetch the similarities and steps foreach (Tree.GuideTree <AlignedMacromolecule> .TreeLeaf leaf in tree.LeavesList) { AlignedMacromolecule macromolecule = (AlignedMacromolecule)leaf.Data; macromolecule.SequenceWeight = leaf.weight; } ReadOnlyCollection <Tuple <ReadOnlyCollection <AlignedMacromolecule>, ReadOnlyCollection <AlignedMacromolecule>, double> > alignmentSteps = tree.Steps; // Step 3: Multiple sequence alignment myBackgroundWorker.ReportProgress(0, "Starting multiple sequence alignment..."); SubstitutionMatrix.SubstitutionMatrixSeries subMatrixType; if (alignmentObject.IsNucleicAcid) // Replaced by more advanced logic later { subMatrixType = new SubstitutionMatrix.NucleotideIdentity(); } else { subMatrixType = new SubstitutionMatrix.BLOSUM(); } MultipleAlignment.MultipleAlignment.AlignSequences(ref alignmentObject, subMatrixType, ref tree.similarityMatrix, tree.LeavesList, alignmentSteps); }