From 7570956d4b58f313d402cdd0507737c0628f1544 Mon Sep 17 00:00:00 2001
From: jprocter
Date: Fri, 4 Aug 2006 14:28:05 +0000
Subject: [PATCH] recover original data for tree and pca as alignment view.
---
src/jalview/analysis/NJTree.java | 12 +-
src/jalview/datamodel/Alignment.java | 8 +-
src/jalview/datamodel/AlignmentView.java | 68 ++++
src/jalview/datamodel/CigarArray.java | 61 +++-
src/jalview/datamodel/CigarBase.java | 207 ++++++++++-
src/jalview/datamodel/ColumnSelection.java | 6 +-
src/jalview/datamodel/SeqCigar.java | 531 +++++++++++++++++++++-------
src/jalview/gui/AlignFrame.java | 41 ++-
src/jalview/gui/AlignViewport.java | 41 ++-
src/jalview/gui/PCAPanel.java | 72 +++-
src/jalview/gui/TreePanel.java | 52 ++-
src/jalview/util/ShiftList.java | 74 ++++
src/jalview/ws/MsaWSClient.java | 29 +-
13 files changed, 995 insertions(+), 207 deletions(-)
create mode 100644 src/jalview/datamodel/AlignmentView.java
create mode 100644 src/jalview/util/ShiftList.java
diff --git a/src/jalview/analysis/NJTree.java b/src/jalview/analysis/NJTree.java
index 974175f..674af7f 100755
--- a/src/jalview/analysis/NJTree.java
+++ b/src/jalview/analysis/NJTree.java
@@ -42,7 +42,7 @@ public class NJTree
//SequenceData is a string representation of what the user
//sees. The display may contain hidden columns.
- CigarArray seqData=null;
+ public AlignmentView seqData=null;
int[] done;
int noseqs;
@@ -76,7 +76,7 @@ public class NJTree
* @param odata Cigar[]
* @param treefile NewickFile
*/
- public NJTree(SequenceI[] seqs, CigarArray odata, NewickFile treefile) {
+ public NJTree(SequenceI[] seqs, AlignmentView odata, NewickFile treefile) {
this(seqs, treefile);
if (odata!=null)
seqData = odata;
@@ -167,7 +167,7 @@ public class NJTree
* @param end DOCUMENT ME!
*/
public NJTree(SequenceI[] sequence,
- CigarArray seqData,
+ AlignmentView seqData,
String type,
String pwtype,
int start, int end)
@@ -184,8 +184,9 @@ public class NJTree
{
seqs[i] = new SeqCigar(sequence[i], start, end);
}
- this.seqData = new CigarArray(seqs);
- this.seqData.addOperation(CigarArray.M, end-start+1);
+ CigarArray sdata = new CigarArray(seqs);
+ sdata.addOperation(CigarArray.M, end-start+1);
+ this.seqData = new AlignmentView(sdata);
}
if (!(type.equals("NJ")))
@@ -1033,7 +1034,6 @@ public class NJTree
}
return sb.toString();
}
-
/**
* DOCUMENT ME!
*
diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java
index 588134a..d67592a 100755
--- a/src/jalview/datamodel/Alignment.java
+++ b/src/jalview/datamodel/Alignment.java
@@ -70,11 +70,7 @@ public class Alignment implements AlignmentI
* @param seqs SeqCigar[]
*/
public Alignment(SeqCigar[] alseqs) {
-
- SequenceI[] seqs = new SequenceI[alseqs.length];
- for (int i=0; iTitle:
+ *
+ * Description:
+ *
+ * Copyright: Copyright (c) 2004
+ *
+ * Company: Dundee University
+ *
+ * @author not attributable
+ * @version 1.0
+ */
+public class AlignmentView
+{
+ /**
+ * Transient object compactly representing a 'view' of an alignment - with discontinuities marked.
+ */
+ private SeqCigar[] sequences = null;
+ private int[] contigs = null;
+ public AlignmentView(CigarArray seqcigararray)
+ {
+ if (!seqcigararray.isSeqCigarArray())
+ throw new Error("Implementation Error - can only make an alignment view from a CigarArray of sequences.");
+ contigs = seqcigararray.applyDeletions();
+ sequences = seqcigararray.getSeqCigarArray();
+ }
+
+ public void setSequences(SeqCigar[] sequences)
+ {
+ this.sequences = sequences;
+ }
+
+ public void setContigs(int[] contigs)
+ {
+ this.contigs = contigs;
+ }
+
+ public SeqCigar[] getSequences()
+ {
+ return sequences;
+ }
+
+ public int[] getContigs()
+ {
+ return contigs;
+ }
+ public Object[] getAlignmentAndColumnSelection(char gapCharacter) {
+ ColumnSelection colsel = new ColumnSelection();
+
+ return new Object[] { SeqCigar.createAlignmentSequences(sequences, gapCharacter, colsel), colsel};
+ }
+ /**
+ * getSequenceStrings
+ *
+ * @param c char
+ * @return String[]
+ */
+ public String[] getSequenceStrings(char c)
+ {
+ String[] seqs=new String[sequences.length];
+ for (int n=0; n=rlength) {
+ if (sbend>rlength) {
sq.append(reference.substring(cursor, rlength));
while (sbend-- >= rlength)
{
@@ -183,7 +183,7 @@ public abstract class CigarBase
}
/**
- * inefficient add one operation to cigar string
+ * add an operation to cigar string
* @param op char
* @param range int
*/
@@ -229,22 +229,206 @@ public abstract class CigarBase
* NOTE: Insertion operations simply extend width of cigar result - affecting registration of alignment
* Deletion ops will shorten length of result - and affect registration of alignment
* Match ops will also affect length of result - affecting registration of alignment
- * (ie "10M".insert(4,I,3)->"4M3I3M")
- * (ie "10M".insert(4,D,3)->"4M3D3M")
- * (ie "5I5M".insert(4,I,3)->"8I5M")
- * (ie "5I5M".insert(4,D,3)->"4I3M")
- * if pos is beyond width - I operations are added before the operation
- * (ie "10M".insert(4,M,3)->"13M")
+ * (ie "10M".insert(4,I,3)->"4M3I3M") - (replace?)
+ * (ie "10M".insert(4,D,3)->"4M3D3M") - (shortens alignment)
+ * (ie "5I5M".insert(4,I,3)->"8I5M") - real insertion
+ * (ie "5I5M".insert(4,D,3)->"4I2D3M") - shortens aligment - I's are removed, Ms changed to Ds
+ * (ie "10M".insert(4,M,3)->"13M") - lengthens - Is changed to M, Ds changed to M.
* (ie "5I5M".insert(4,M,3)->"4I8M") - effectively shifts sequence left by 1 residue and extends it by 3
- * @param pos int
+ * ( "10D5M".insert(-1,M,3)->"3M7D5M")
+ * ( "10D5M".insert(0,M,3)->"7D8M")
+ * ( "10D5M".insert(1,M,3)->"10D8M")
+ *
+ * ( "1M10D5M".insert(0,M,3)->"1M10D8M")
+ * ( "1M10D5M".insert(1,M,3)->"
+ *
+ * if pos is beyond width - I operations are added before the operation
+ * @param pos int -1, 0-length of visible region, or greater to append new ops (with insertions in between)
* @param op char
* @param range int
- */
public void addOperationAt(int pos, char op, int range)
{
+ int cursor = -1; // mark the position for the current operation being edited.
+ int o = 0;
+ boolean last_d = false; // previous op was a deletion.
+ if (pos < -1)
+ throw new Error("pos<-1 is not supported.");
+ while (o0)
+ addInsertion(pos-cursor);
+ // then just add the new operation. Regardless of what it is.
+ addOperation(op, range);
+ } else {
+ int diff = pos - cursor;
+ int e_length = length-o; // new edit operation array length.
+ // diff<0 - can only happen before first insertion or match. - affects op and all following
+ // dif==0 - only when at first position of existing op -
+ // diff>0 - must preserve some existing operations
+ int[] e_range = new int[e_length];
+ System.arraycopy(this.range, o, e_range, 0, e_length);
+ char[] e_op = new char[e_length];
+ System.arraycopy(this.operation, o, e_op, 0, e_length);
+ length = o; // can now use add_operation to extend list.
+ int e_o=0; // current operation being edited.
+ switch (op) {
+ case M:
+ switch (e_op[e_o])
+ {
+ case M:
+ if (last_d && diff <= 0)
+ {
+ // reduce D's, if possible
+ if (range<=this.range[o-1]) {
+ this.range[o - 1] -= range;
+ } else {
+ this.range[o-1]=0;
+ }
+ if (this.range[o-1]==0)
+ o--; // lose this op.
+ }
+ e_range[e_o] += range; // just add more matched residues
+ break;
+ case I:
+ // change from insertion to match
+ if (last_d && diff<=0)
+ {
+ // reduce D's, if possible
+ if (range<=this.range[o-1]) {
+ this.range[o - 1] -= range;
+ } else {
+ this.range[o-1]=0;
+ }
+ if (this.range[o-1]==0)
+ o--; // lose this op.
+ }
+ e_range[e_o]
+ break;
+ default:
+ throw new Inp
+ }
+
+ break;
+ case I:
+ break;
+ case D:
+ }
+ break;
+ default:
+ throw new Error("Implementation Error: Unknown operation in addOperation!");
+ }
+ // finally, add remaining ops.
+ while (e_oend)
+ throw new Error("Implementation Error: deleteRange out of bounds: start must be non-negative and less than end.");
+ // find beginning
+ int cursor = 0; // mark the position for the current operation being edited.
+ int rlength=1+end-start; // number of positions to delete
+ int oldlen=length;
+ int o = 0;
+ boolean editing=false;
+ char[] oldops = operation;
+ int[] oldrange = range;
+ length=0;
+ operation = null;
+ range = null;
+ while (o0) {
+ if (oldops[o] == D) {
+ // absorbed into new deleted region.
+ addDeleted(oldrange[o++]);
+ continue;
+ }
+ int remain = oldrange[o]; // number of op characters left to edit
+ if (!editing) {
+ if ( (cursor + remain) <= start)
+ {
+ addOperation(oldops[o],oldrange[o]);
+ cursor+=oldrange[o++];
+ continue; // next operation
+ }
+ editing=true;
+ // add operations before hidden region
+ if (start-cursor>0) {
+ addOperation(oldops[o], start- cursor);
+ remain -= start - cursor;
+ }
+ }
+ // start inserting new ops
+ if (o0 && remain>0) {
+ switch (oldops[o]) {
+ case M:
+ if (rlength>remain) {
+ addDeleted(remain);
+ } else {
+ addDeleted(rlength);
+ if (remain-rlength>0)
+ this.addOperation(M,remain-rlength); // add remaining back.
+ rlength=0;
+ remain=0;
+ }
+ break;
+ case I:
+ if (remain-rlength>0) {
+ // only remove some gaps
+ addInsertion(remain-rlength);
+ rlength=0;
+ }
+ break;
+ case D:
+ throw new Error("Implementation error."); // do nothing;
+ default:
+ throw new Error("Implementation Error! Unknown operation '"+oldops[o]+"'");
+ }
+ rlength-=remain;
+ remain = oldrange[++o]; // number of op characters left to edit
+ }
+ }
+ // add remaining
+ while (o 0 && op != I)
+ if (isGap)
+ {
+ if (range > 0 && op != I)
+ {
+ cigar.addOperation(op, range);
+ range = 0;
+ }
+ op = I;
+ range++;
+ }
+ else
{
- cigar.addOperation(op, range);
- range = 0;
+ if (range > 0 && op != M)
+ {
+ cigar.addOperation(op, range);
+ range = 0;
+ }
+ op = M;
+ range++;
}
- op = I;
- range++;
}
else
{
- if (range > 0 && op != M)
+ if (!isGap)
{
- cigar.addOperation(op, range);
- range = 0;
+ if (range > 0 && op != D)
+ {
+ cigar.addOperation(op, range);
+ range = 0;
+ }
+ op = D;
+ range++;
}
- op = M;
- range++;
- }
- }
- else
- {
- if (!isGap)
- {
- if (range > 0 && op != D)
+ else
{
- cigar.addOperation(op, range);
- range = 0;
+ // do nothing - insertions are not made in flanking regions
}
- op = D;
- range++;
- }
- else
- {
- // do nothing - insertions are not recorded in flanking regions.
}
+ p++;
+ }
+ if (range > 0)
+ {
+ cigar.addOperation(op, range);
}
}
- if (range > 0)
- {
- cigar.addOperation(op, range);
- }
- }
+
/**
* create a cigar string for given sequence
* @param seq SequenceI
*/
- public SeqCigar(SequenceI seq) {
+ public SeqCigar(SequenceI seq)
+ {
super();
if (seq == null)
- throw new Error("Implementation error for new Cigar(SequenceI)");
- if (_setSeq(seq))
{
- // there is still work to do
- addSequenceOps(this, seq, 0, seq.getLength());
+ throw new Error("Implementation error for new Cigar(SequenceI)");
}
+ _setSeq(seq, false, 0, 0);
+ // there is still work to do
+ addSequenceOps(this, seq, 0, seq.getLength()-1, false);
}
- public SeqCigar(SequenceI seq, int start, int end) {
+
+ /**
+ * Create Cigar from a range of gaps and residues on a sequence object
+ * @param seq SequenceI
+ * @param start int - first column in range
+ * @param end int - last column in range
+ */
+ public SeqCigar(SequenceI seq, int start, int end)
+ {
super();
if (seq == null)
- throw new Error("Implementation error for new Cigar(SequenceI)");
- if (_setSeq(seq))
{
- // there is still work to do
- addSequenceOps(this, seq, start, end);
+ throw new Error("Implementation error for new Cigar(SequenceI)");
}
+ _setSeq(seq, false, start, end+1);
+ // there is still work to do
+ addSequenceOps(this, seq, start, end, false);
}
/**
@@ -233,6 +356,89 @@ public class SeqCigar
Object[] opsandrange = parseCigarString(cigarString);
return new SeqCigar(seq, (char[]) opsandrange[0], (int[]) opsandrange[1]);
}
+
+ /**
+ * createAlignment
+ *
+ * @param alseqs SeqCigar[]
+ * @param gapCharacter char
+ * @return SequenceI[]
+ */
+ public static SequenceI[] createAlignmentSequences(SeqCigar[] alseqs,
+ char gapCharacter, ColumnSelection colsel)
+ {
+ SequenceI[] seqs = new SequenceI[alseqs.length];
+ Vector hiddenRegions=new Vector();
+ StringBuffer[] g_seqs = new StringBuffer[alseqs.length];
+ String[] alseqs_string=new String[alseqs.length];
+ Object[] gs_regions = new Object[alseqs.length];
+ for (int i = 0; i < alseqs.length; i++)
+ {
+ alseqs_string[i]=alseqs[i].getRefSeq().
+ getSequence().substring(alseqs[i].start,alseqs[i].end);
+ gs_regions[i] = alseqs[i].getSequenceAndDeletions(alseqs_string[i], gapCharacter); // gapped sequence, {start, start col, end. endcol}, hidden regions {{start, end, col}})
+ if (gs_regions[i] == null)
+ {
+ throw new Error("Implementation error: " + i +
+ "'th sequence Cigar has no operations.");
+ }
+ g_seqs[i] = new StringBuffer( (String) ( (Object[]) gs_regions[i])[0]); // the visible gapped sequence
+ }
+ // Now account for insertions.
+ // this is complicated because we must keep track of shifted positions in each sequence
+ ShiftList shifts = new ShiftList();
+ for (int i = 0; i < alseqs.length; i++)
+ {
+ Object[] gs_region = ( (Object[]) ( (Object[]) gs_regions[i])[2]);
+ if (gs_region != null)
+
+ {
+ for (int hr = 0; hr < gs_region.length; hr++)
+ {
+ int[] region = (int[]) gs_region[hr];
+ char[] insert = new char[region[1] - region[0] + 1];
+ for (int s = 0; s < insert.length; s++)
+ {
+ insert[s] = gapCharacter;
+ }
+ int inspos = shifts.shift(region[2]); // resolve insertion position in current alignment frame of reference
+ for (int s = 0; s < alseqs.length; s++)
+ {
+ if (s != i)
+ {
+ if (g_seqs[s].length() <= inspos)
+ {
+ // prefix insertion with more gaps.
+ for (int l = inspos - g_seqs[s].length(); l > 0; l--)
+ {
+ g_seqs[s].append(gapCharacter); // to debug - use a diffferent gap character here
+ }
+ }
+ g_seqs[s].insert(inspos, insert);
+ }
+ else
+ {
+ g_seqs[s].insert(inspos,
+ alseqs_string[i].substring(region[0], region[1] + 1));
+ }
+ }
+ shifts.addShift(region[2], insert.length); // update shift in alignment frame of reference
+ colsel.hideColumns(inspos, inspos+insert.length-1);
+ }
+ }
+ }
+ for (int i = 0; i < alseqs.length; i++)
+ {
+ int[] bounds = ( (int[]) ( (Object[]) gs_regions[i])[1]);
+ SequenceI ref = alseqs[i].getRefSeq();
+ seqs[i] = new Sequence(ref.getName(), g_seqs[i].toString(),
+ ref.getStart() + alseqs[i].start+bounds[0],
+ ref.getStart() + alseqs[i].start+bounds[2]);
+ seqs[i].setDatasetSequence(ref);
+ }
+ return seqs;
+ }
+
/**
* non rigorous testing
*/
@@ -242,16 +448,25 @@ public class SeqCigar
* @param ex_cs_gapped String
* @return String
*/
- public static String testCigar_string(Sequence seq, String ex_cs_gapped) {
+ public static String testCigar_string(Sequence seq, String ex_cs_gapped)
+ {
SeqCigar c_sgapped = new SeqCigar(seq);
String cs_gapped = c_sgapped.getCigarstring();
if (!cs_gapped.equals(ex_cs_gapped))
- System.err.println("Failed getCigarstring: incorect string '"+cs_gapped+"' != "+ex_cs_gapped);
+ {
+ System.err.println("Failed getCigarstring: incorect string '" + cs_gapped +
+ "' != " + ex_cs_gapped);
+ }
return cs_gapped;
}
- public static boolean testSeqRecovery(SeqCigar gen_sgapped, SequenceI s_gapped) {
+
+ public static boolean testSeqRecovery(SeqCigar gen_sgapped,
+ SequenceI s_gapped)
+ {
+ // this is non-rigorous - start and end recovery is not tested.
SequenceI gen_sgapped_s = gen_sgapped.getSeq('-');
- if (!gen_sgapped_s.getSequence().equals(s_gapped.getSequence())) {
+ if (!gen_sgapped_s.getSequence().equals(s_gapped.getSequence()))
+ {
System.err.println("Couldn't reconstruct sequence.\n" +
gen_sgapped_s.getSequence() + "\n" +
s_gapped.getSequence());
@@ -259,41 +474,119 @@ public class SeqCigar
}
return true;
}
- public static void main(String argv[]) throws Exception {
- Sequence s=new Sequence("MySeq", "asdfktryasdtqwrtsaslldddptyipqqwaslchvhttt",39,80);
+
+ public static void main(String argv[])
+ throws Exception
+ {
+ String o_seq;
+ Sequence s = new Sequence("MySeq",
+ o_seq = "asdfktryasdtqwrtsaslldddptyipqqwaslchvhttt",
+ 39, 80);
String orig_gapped;
- Sequence s_gapped=new Sequence("MySeq", orig_gapped="----asdf------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhttt", 39,80);
- String ex_cs_gapped="4I4M6I6M3I11M4I12M4I9M";
+ Sequence s_gapped = new Sequence("MySeq",
+ orig_gapped = "----asdf------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhttt",
+ 39, 80);
+ String ex_cs_gapped = "4I4M6I6M3I11M4I12M4I9M";
s_gapped.setDatasetSequence(s);
String sub_gapped_s;
- Sequence s_subsequence_gapped=new Sequence("MySeq", sub_gapped_s="------ktryas---dtqwrtsasll----dddptyipqqwa----slchvh", 43,77);
+ Sequence s_subsequence_gapped = new Sequence("MySeq",
+ sub_gapped_s = "------ktryas---dtqwrtsasll----dddptyipqqwa----slchvh",
+ 43, 77);
s_subsequence_gapped.setDatasetSequence(s);
SeqCigar c_null = new SeqCigar(s);
String cs_null = c_null.getCigarstring();
- if (cs_null.length()>0)
- System.err.println("Failed getCigarstring: Unexpected cigar operations:"+cs_null);
+ if (!cs_null.equals("42M"))
+ {
+ System.err.println(
+ "Failed to recover ungapped sequence cigar operations:" +
+ ( (cs_null == "") ? "empty string" : cs_null));
+ }
testCigar_string(s_gapped, ex_cs_gapped);
SeqCigar gen_sgapped = SeqCigar.parseCigar(s, ex_cs_gapped);
if (!gen_sgapped.getCigarstring().equals(ex_cs_gapped))
- System.err.println("Failed parseCigar("+ex_cs_gapped+")->getCigarString()->'"+gen_sgapped.getCigarstring()+"'");
+ {
+ System.err.println("Failed parseCigar(" + ex_cs_gapped +
+ ")->getCigarString()->'" + gen_sgapped.getCigarstring() +
+ "'");
+ }
testSeqRecovery(gen_sgapped, s_gapped);
// Test dataset resolution
SeqCigar sub_gapped = new SeqCigar(s_subsequence_gapped);
if (!testSeqRecovery(sub_gapped, s_subsequence_gapped))
- System.err.println("Failed recovery for subsequence of dataset sequence");
+ {
+ System.err.println("Failed recovery for subsequence of dataset sequence");
+ }
// width functions
- if (sub_gapped.getWidth()!=sub_gapped_s.length())
+ if (sub_gapped.getWidth() != sub_gapped_s.length())
+ {
System.err.println("Failed getWidth()");
+ }
sub_gapped.getFullWidth();
if (sub_gapped.hasDeletedRegions())
+ {
System.err.println("hasDeletedRegions is incorrect.");
+ }
// Test start-end region SeqCigar
- SeqCigar sub_se_gp= new SeqCigar(s_subsequence_gapped, 8, 48);
- if (sub_se_gp.getWidth()!=40)
- System.err.println("SeqCigar(seq, start, end) not properly clipped alignsequence.");
- System.out.println("Original sequence align:\n"+sub_gapped_s+"\nReconstructed window from 8 to 48\n"+"XXXXXXXX"+sub_se_gp.getSequenceString('-')+"...."+"\nCigar String:"+sub_se_gp.getCigarstring()+"");
+ SeqCigar sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48);
+ if (sub_se_gp.getWidth() != 41)
+ {
+ System.err.println(
+ "SeqCigar(seq, start, end) not properly clipped alignsequence.");
+ }
+ System.out.println("Original sequence align:\n" + sub_gapped_s +
+ "\nReconstructed window from 8 to 48\n"
+ + "XXXXXXXX" + sub_se_gp.getSequenceString('-') + "..."
+ + "\nCigar String:" + sub_se_gp.getCigarstring() + "\n"
+ );
+ SequenceI ssgp = sub_se_gp.getSeq('-');
+ System.out.println("\t " + ssgp.getSequence());
+ for (int r = 0; r < 10; r++)
+ {
+ sub_se_gp = new SeqCigar(s_subsequence_gapped, 8, 48);
+ int sl = sub_se_gp.getWidth();
+ int st = sl - r - r;
+ for (int rs = 0; rs < 10; rs++)
+ {
+ int e = st + rs;
+ sub_se_gp.deleteRange(st, e);
+ String ssgapedseq = sub_se_gp.getSeq('-').getSequence();
+ System.out.println(st + "," + e + "\t:" + ssgapedseq);
+ }
+ }
+ {
+ SeqCigar[] set = new SeqCigar[]
+ {
+ new SeqCigar(s), new SeqCigar(s_subsequence_gapped, 8, 48),
+ new SeqCigar(s_gapped)};
+ Alignment al = new Alignment(set);
+ for (int i = 0; i < al.getHeight(); i++)
+ {
+ System.out.println("" + al.getSequenceAt(i).getName() + "\t" +
+ al.getSequenceAt(i).getStart() + "\t" +
+ al.getSequenceAt(i).getEnd() + "\t" +
+ al.getSequenceAt(i).getSequence());
+ }
+ }
+ {
+ System.out.println("Gapped.");
+ SeqCigar[] set = new SeqCigar[]
+ {
+ new SeqCigar(s), new SeqCigar(s_subsequence_gapped, 8, 48),
+ new SeqCigar(s_gapped)};
+ set[0].deleteRange(20, 25);
+ Alignment al = new Alignment(set);
+ for (int i = 0; i < al.getHeight(); i++)
+ {
+ System.out.println("" + al.getSequenceAt(i).getName() + "\t" +
+ al.getSequenceAt(i).getStart() + "\t" +
+ al.getSequenceAt(i).getEnd() + "\t" +
+ al.getSequenceAt(i).getSequence());
+ }
+ }
+// if (!ssgapedseq.equals("ryas---dtqqwa----slchvh"))
+// System.err.println("Subseqgaped\n------ktryas---dtqwrtsasll----dddptyipqqwa----slchvhryas---dtqwrtsasll--qwa----slchvh\n"+ssgapedseq+"\n"+sub_se_gp.getCigarstring());
}
}
diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java
index 2127cd5..14bf680 100755
--- a/src/jalview/gui/AlignFrame.java
+++ b/src/jalview/gui/AlignFrame.java
@@ -60,16 +60,14 @@ public class AlignFrame
Stack redoList = new Stack();
private int treeCount = 0;
-
/**
- * Creates a new AlignFrame object.
- *
- * @param al DOCUMENT ME!
+ * new alignment window with hidden columns
+ * @param al AlignmentI
+ * @param hiddenColumns ColumnSelection or null
*/
- public AlignFrame(AlignmentI al)
- {
+ public AlignFrame(AlignmentI al, ColumnSelection hiddenColumns) {
- viewport = new AlignViewport(al);
+ viewport = new AlignViewport(al, hiddenColumns);
this.setDropTarget(new java.awt.dnd.DropTarget(this, this));
@@ -141,6 +139,17 @@ public class AlignFrame
}
+
+ /**
+ * Creates a new AlignFrame object.
+ *
+ * @param al DOCUMENT ME!
+ */
+ public AlignFrame(AlignmentI al)
+ {
+ this(al, null);
+ }
+
public AlignViewport getViewport()
{
return viewport;
@@ -2289,27 +2298,28 @@ public class AlignFrame
* or just the selected set will be submitted for multiple alignment.
*
*/
- private SequenceI[] gatherSequencesForAlignment()
+ private jalview.datamodel.AlignmentView gatherSequencesForAlignment()
{
// Now, check we have enough sequences
- SequenceI[] msa = null;
+ AlignmentView msa = null;
if ( (viewport.getSelectionGroup() != null) &&
(viewport.getSelectionGroup().getSize(false) > 1))
{
// JBPNote UGLY! To prettify, make SequenceGroup and Alignment conform to some common interface!
- SequenceGroup seqs = viewport.getSelectionGroup();
+ /*SequenceGroup seqs = viewport.getSelectionGroup();
int sz;
msa = new SequenceI[sz = seqs.getSize(false)];
for (int i = 0; i < sz; i++)
{
msa[i] = (SequenceI) seqs.getSequenceAt(i);
- }
+ } */
+ msa = viewport.getAlignmentView(true);
}
else
{
- Vector seqs = viewport.getAlignment().getSequences();
+ /*Vector seqs = viewport.getAlignment().getSequences();
if (seqs.size() > 1)
{
@@ -2319,7 +2329,8 @@ public class AlignFrame
{
msa[i] = (SequenceI) seqs.elementAt(i);
}
- }
+ }*/
+ msa = viewport.getAlignmentView(false);
}
return msa;
}
@@ -2523,7 +2534,7 @@ public class AlignFrame
{
public void actionPerformed(ActionEvent e)
{
- SequenceI[] msa = gatherSequencesForAlignment();
+ AlignmentView msa = gatherSequencesForAlignment();
new jalview.ws.MsaWSClient(sh, title, msa,
false, true, viewport.getAlignment().getDataset(), af);
@@ -2540,7 +2551,7 @@ public class AlignFrame
{
public void actionPerformed(ActionEvent e)
{
- SequenceI[] msa = gatherSequencesForAlignment();
+ AlignmentView msa = gatherSequencesForAlignment();
new jalview.ws.MsaWSClient(sh, title, msa,
true, true, viewport.getAlignment().getDataset(), af);
diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java
index f8be001..fde4d90 100755
--- a/src/jalview/gui/AlignViewport.java
+++ b/src/jalview/gui/AlignViewport.java
@@ -121,6 +121,20 @@ public class AlignViewport
setAlignment(al);
init();
}
+ /**
+ * Create a new AlignViewport with hidden regions
+ * @param al AlignmentI
+ * @param hiddenColumns ColumnSelection
+ */
+ public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns) {
+ setAlignment(al);
+ if (hiddenColumns!=null) {
+ this.colSel = hiddenColumns;
+ if (hiddenColumns.getHiddenColumns() != null)
+ hasHiddenColumns = true;
+ }
+ init();
+ }
void init()
{
@@ -1188,13 +1202,13 @@ public class AlignViewport
iSize = selectionGroup.getSize(false);
seqs = selectionGroup.getSequencesInOrder(alignment);
start = selectionGroup.getStartRes();
- end = selectionGroup.getEndRes()+1;
+ end = selectionGroup.getEndRes(); // inclusive for start and end in SeqCigar constructor
}
else
{
iSize = alignment.getHeight();
seqs = alignment.getSequencesArray();
- end = alignment.getWidth();
+ end = alignment.getWidth()-1;
}
SeqCigar[] selseqs = new SeqCigar[iSize];
for(i=0; i>>This is a fix for the moment, until a better solution is found!!<<<
+ // af.getFeatureRenderer().transferSettings(alignFrame.getFeatureRenderer());
+
+ // af.addSortByOrderMenuItem(ServiceName + " Ordering",
+ // msaorder);
+
+ Desktop.addInternalFrame(af, "original Data for " + this.title,
+ AlignFrame.NEW_WINDOW_WIDTH,
+ AlignFrame.NEW_WINDOW_HEIGHT);
+ }
+ }
+ /* CutAndPasteTransfer cap = new CutAndPasteTransfer();
+ for (int i = 0; i < seqs.length; i++)
+ {
+ cap.appendText(new jalview.util.Format("%-" + 15 + "s").form(
+ seqs[i].getName()));
+ cap.appendText(" " + seqstrings[i] + "\n");
- Desktop.addInternalFrame(cap, "Original Data",
- 400, 400);
+ }
+ Desktop.addInternalFrame(cap, "Original Data",
+ 400, 400);
+ */
}
diff --git a/src/jalview/gui/TreePanel.java b/src/jalview/gui/TreePanel.java
index bde218c..d306028 100755
--- a/src/jalview/gui/TreePanel.java
+++ b/src/jalview/gui/TreePanel.java
@@ -137,7 +137,7 @@ public class TreePanel extends GTreePanel
class TreeLoader extends Thread
{
NewickFile newtree;
- jalview.datamodel.CigarArray odata=null;
+ jalview.datamodel.AlignmentView odata=null;
public TreeLoader(NewickFile newtree)
{
this.newtree = newtree;
@@ -168,7 +168,7 @@ public class TreePanel extends GTreePanel
{
int start, end;
SequenceI [] seqs;
- CigarArray seqStrings = av.getViewAsCigars(av.getSelectionGroup()!=null);
+ AlignmentView seqStrings = av.getAlignmentView(av.getSelectionGroup()!=null);
if(av.getSelectionGroup()==null)
{
start = 0;
@@ -316,16 +316,46 @@ public class TreePanel extends GTreePanel
public void originalSeqData_actionPerformed(ActionEvent e)
{
- String originalData = tree.printOriginalSequenceData(av.getGapCharacter());
- if (originalData!=null) {
- CutAndPasteTransfer cap = new CutAndPasteTransfer();
- cap.setText(originalData);
- Desktop.addInternalFrame(cap, "Original Data",
- 400, 400);
- } else {
- System.err.println("IMPLEMENTATION BUG! originalSeqData is not available.");
+ if (!tree.hasOriginalSequenceData())
+ {
+ jalview.bin.Cache.log.info("Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action.");
+ return;
}
-
+ // decide if av alignment is sufficiently different to original data to warrant a new window to be created
+ // create new alignmnt window with hidden regions (unhiding hidden regions yields unaligned seqs)
+ // or create a selection box around columns in alignment view
+ // test Alignment(SeqCigar[])
+ Object[] alAndColsel = tree.seqData.getAlignmentAndColumnSelection(av.
+ getGapCharacter());
+
+
+ if (alAndColsel != null && alAndColsel[0]!=null)
+ {
+ // AlignmentOrder origorder = new AlignmentOrder(alAndColsel[0]);
+
+ Alignment al = new Alignment((SequenceI[]) alAndColsel[0]);
+ Alignment dataset = av.getAlignment().getDataset();
+ if (dataset != null)
+ {
+ al.setDataset(dataset);
+ }
+
+ if (true)
+ {
+ // make a new frame!
+ AlignFrame af = new AlignFrame(al, (ColumnSelection) alAndColsel[1]);
+
+ //>>>This is a fix for the moment, until a better solution is found!!<<<
+ // af.getFeatureRenderer().transferSettings(alignFrame.getFeatureRenderer());
+
+ // af.addSortByOrderMenuItem(ServiceName + " Ordering",
+ // msaorder);
+
+ Desktop.addInternalFrame(af, "original Data for " + this.title,
+ AlignFrame.NEW_WINDOW_WIDTH,
+ AlignFrame.NEW_WINDOW_HEIGHT);
+ }
+ }
}
diff --git a/src/jalview/util/ShiftList.java b/src/jalview/util/ShiftList.java
new file mode 100644
index 0000000..ca768ae
--- /dev/null
+++ b/src/jalview/util/ShiftList.java
@@ -0,0 +1,74 @@
+package jalview.util;
+
+import java.util.*;
+
+/**
+ * ShiftList
+ * Simple way of mapping a linear series to a new linear range with new points introduced.
+ * Use at your own risk!
+ * Title: ShiftList
+ *
+ * Description:
+ *
+ * Copyright: Copyright (c) 2004
+ *
+ * Company: Dundee University
+ *
+ * @author not attributable
+ * @version 1.0
+ */
+public class ShiftList
+{
+ Vector shifts;
+ public ShiftList()
+ {
+ shifts = new Vector();
+ }
+
+ /**
+ * addShift
+ * @param pos start position for shift (in original reference frame)
+ * @param shift length of shift
+ */
+ public void addShift(int pos, int shift)
+ {
+ int sidx = 0;
+ int[] rshift=null;
+ while (sidx