X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fanalysis%2FAlignSeq.java;h=832f5198781b804b055ee48f596c5bd6fc570b1c;hb=60403f610c291791bf7c58f9c7232206469687cd;hp=4a8955bee6bf8ee3f8d4da23bc5cffd6a50392d5;hpb=59d682209891099d46b960509907c79e3fb276fe;p=jalview.git
diff --git a/src/jalview/analysis/AlignSeq.java b/src/jalview/analysis/AlignSeq.java
index 4a8955b..832f519 100755
--- a/src/jalview/analysis/AlignSeq.java
+++ b/src/jalview/analysis/AlignSeq.java
@@ -16,7 +16,6 @@
* You should have received a copy of the GNU General Public License along with Jalview. If not, see .
*/
package jalview.analysis;
-
import java.util.*;
import java.awt.*;
@@ -267,16 +266,11 @@ public class AlignSeq
}
/**
- * DOCUMENT ME!
- *
- * @param s1
- * DOCUMENT ME!
- * @param string1
- * - string to align for sequence1
- * @param s2
- * sequence 2
- * @param string2
- * - string to align for sequence2
+ * Construct score matrix for sequences with standard DNA or PEPTIDE matrix
+ * @param s1 - sequence 1
+ * @param string1 - string to use for s1
+ * @param s2 - sequence 2
+ * @param string2 - string to use for s2
* @param type
* DNA or PEPTIDE
*/
@@ -289,6 +283,14 @@ public class AlignSeq
SeqInit(string1, string2);
}
+ /**
+ * Construct score matrix for sequences with custom substitution matrix
+ * @param s1 - sequence 1
+ * @param string1 - string to use for s1
+ * @param s2 - sequence 2
+ * @param string2 - string to use for s2
+ * @param scoreMatrix - substitution matrix to use for alignment
+ */
public void SeqInit(SequenceI s1, String string1, SequenceI s2,
String string2, ScoreMatrix scoreMatrix)
{
@@ -302,7 +304,7 @@ public class AlignSeq
* construct score matrix for string1 and string2 (after removing any existing
* gaps
*
- * @param string1
+ * @param string1
* @param string2
*/
private void SeqInit(String string1, String string2)
@@ -920,6 +922,98 @@ public class AlignSeq
}
/**
+ * Compute a globally optimal needleman and wunsch alignment between two
+ * sequences
+ *
+ * @param s1
+ * @param s2
+ * @param type
+ * AlignSeq.DNA or AlignSeq.PEP
+ */
+ public static AlignSeq doGlobalNWAlignment(SequenceI s1, SequenceI s2,
+ String type)
+ {
+ AlignSeq as = new AlignSeq(s1, s2, type);
+
+ as.calcScoreMatrix();
+ as.traceAlignment();
+ return as;
+ }
+
+ /**
+ *
+ * @return mapping from positions in S1 to corresponding positions in S2
+ */
+ public jalview.datamodel.Mapping getMappingFromS1(boolean allowmismatch)
+ {
+ ArrayList as1 = new ArrayList(), as2 = new ArrayList();
+ int pdbpos = s2.getStart() + getSeq2Start() - 2;
+ int alignpos = s1.getStart() + getSeq1Start() - 2;
+ int lp2 = pdbpos - 3, lp1 = alignpos - 3;
+ boolean lastmatch = false;
+ // and now trace the alignment onto the atom set.
+ for (int i = 0; i < astr1.length(); i++)
+ {
+ char c1 = astr1.charAt(i), c2 = astr2.charAt(i);
+ if (c1 != '-')
+ {
+ alignpos++;
+ }
+
+ if (c2 != '-')
+ {
+ pdbpos++;
+ }
+
+ if (allowmismatch || c1 == c2)
+ {
+ lastmatch = true;
+ // extend mapping interval.
+ if (lp1 + 1 != alignpos)
+ {
+ as1.add(Integer.valueOf(alignpos));
+ lp1 = alignpos;
+ }
+
+ if (lp2 + 1 != pdbpos)
+ {
+ as2.add(Integer.valueOf(pdbpos));
+ lp2 = pdbpos;
+ }
+ }
+ else
+ {
+ lastmatch = false;
+ }
+ }
+ // construct range pairs
+ int[] mapseq1 = new int[as1.size() + (lastmatch ? 1 : 0)], mapseq2 = new int[as2
+ .size() + (lastmatch ? 1 : 0)];
+ int i = 0;
+ for (Integer ip : as1)
+ {
+ mapseq1[i++] = ip;
+ }
+ ;
+ i = 0;
+ for (Integer ip : as2)
+ {
+ mapseq2[i++] = ip;
+ }
+ ;
+ if (lastmatch)
+ {
+ mapseq1[mapseq1.length - 1] = alignpos;
+ mapseq2[mapseq2.length - 1] = pdbpos;
+ }
+ MapList map = new MapList(mapseq1, mapseq2, 1, 1);
+
+ jalview.datamodel.Mapping mapping = new Mapping(map);
+ mapping.setTo(s2);
+ return mapping;
+ }
+
+ /**
* compute the PID vector used by the redundancy filter.
*
* @param originalSequences