+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
package jalview.ws;
import java.util.*;
import jalview.bin.*;
import jalview.datamodel.*;
import jalview.datamodel.Alignment;
-import jalview.datamodel.Sequence;
import jalview.gui.*;
import vamsas.objects.simple.MsaResult;
// order
- class MsaWSJob extends WSThread.WSJob
+ class MsaWSJob
+ extends WSThread.WSJob
{
// hold special input for this
vamsas.objects.simple.SequenceSet seqs = new vamsas.objects.simple.
{
seqarray[n] = new vamsas.objects.simple.Sequence();
seqarray[n].setId(newname);
- seqarray[n++].setSeq( (submitGaps) ? seqs[i].getSequence()
+ seqarray[n++].setSeq( (submitGaps) ? seqs[i].getSequenceAsString()
: AlignSeq.extractGaps(
jalview.util.Comparison.GapChars, seqs[i]
- .getSequence()));
+ .getSequenceAsString()));
}
else
{
String empty = null;
if (seqs[i].getEnd() >= seqs[i].getStart())
{
- empty = (submitGaps) ? seqs[i].getSequence()
+ empty = (submitGaps) ? seqs[i].getSequenceAsString()
: AlignSeq.extractGaps(
jalview.util.Comparison.GapChars, seqs[i]
- .getSequence());
+ .getSequenceAsString());
}
emptySeqs.add(new String[]
{newname, empty});
public boolean hasResults()
{
if (subjobComplete && result != null && result.isFinished()
- && ((MsaResult) result).getMsa() != null && ((MsaResult) result).getMsa().getSeqs() != null)
+ && ( (MsaResult) result).getMsa() != null &&
+ ( (MsaResult) result).getMsa().getSeqs() != null)
{
return true;
}
SequenceI[] alseqs = null;
char alseq_gapchar = '-';
int alseq_l = 0;
- if (((MsaResult) result).getMsa() != null)
+ if ( ( (MsaResult) result).getMsa() != null)
{
- alseqs = getVamsasAlignment(((MsaResult) result).getMsa());
- alseq_gapchar = ((MsaResult) result).getMsa().getGapchar().charAt(0);
+ alseqs = getVamsasAlignment( ( (MsaResult) result).getMsa());
+ alseq_gapchar = ( (MsaResult) result).getMsa().getGapchar().charAt(0);
alseq_l = alseqs.length;
}
if (emptySeqs.size() > 0)
if (nw > sw)
{
// pad at end
- alseqs[i].setSequence(t_alseqs[i].getSequence() +
+ alseqs[i].setSequence(t_alseqs[i].getSequenceAsString() +
insbuff.substring(0, sw - nw));
}
}
}
return null;
}
+
/**
* mark subjob as cancelled and set result object appropriatly
*/
- void cancel() {
- cancelled=true;
+ void cancel()
+ {
+ cancelled = true;
subjobComplete = true;
result = null;
}
+
/**
*
* @return boolean true if job can be submitted.
*/
- boolean hasValidInput() {
- if (seqs.getSeqs()!=null)
+ boolean hasValidInput()
+ {
+ if (seqs.getSeqs() != null)
+ {
return true;
+ }
return false;
}
}
-
String alTitle; // name which will be used to form new alignment window.
Alignment dataset; // dataset to which the new alignment will be
OutputHeader = wsInfo.getProgressText();
alTitle = title;
dataset = seqset;
- SeqCigar[] msa = _msa.getSequences();
- int[] contigs = _msa.getContigs();
- int njobs = 1;
- if (contigs != null && contigs.length > 0)
+
+ SequenceI[][] conmsa = _msa.getVisibleContigs('-');
+ if (conmsa != null)
{
- int start = 0;
- njobs = 0;
- int width = _msa.getWidth();
- for (int contig = 0; contig < contigs.length; contig += 3)
- {
- if ( (contigs[contig + 1] - start) > 0)
- {
- njobs++;
- }
- width += contigs[contig + 2]; // end up with full region width (including hidden regions)
- start = contigs[contig + 1] + contigs[contig + 2];
- }
- if (start < width)
- {
- njobs++;
- }
+ int njobs = conmsa.length;
jobs = new MsaWSJob[njobs];
- start = 0;
- int j = 0;
- for (int contig = 0; contig < contigs.length; contig += 3)
+ for (int j = 0; j < njobs; j++)
{
- if (contigs[contig + 1] - start > 0)
- {
- SequenceI mseq[] = new SequenceI[msa.length];
- for (int s = 0; s < mseq.length; s++)
- {
- mseq[s] = msa[s].getSeq('-').getSubSequence(start,
- contigs[contig + 1]);
- }
- if (j != 0)
- {
- jobs[j] = new MsaWSJob(wsinfo.addJobPane(), mseq);
- }
- else
- {
- jobs[j] = new MsaWSJob(0, mseq);
- }
- wsinfo.setProgressName("region " + jobs[j].jobnum, jobs[j].jobnum);
- wsinfo.setProgressText(jobs[j].jobnum, OutputHeader);
- j++;
- }
- start = contigs[contig + 1] + contigs[contig + 2];
- }
- if (start < width)
- {
- SequenceI mseq[] = new SequenceI[msa.length];
- for (int s = 0; s < mseq.length; s++)
- {
- mseq[s] = msa[s].getSeq('-').getSubSequence(start,
- width + 1);
- }
if (j != 0)
{
- jobs[j] = new MsaWSJob(wsinfo.addJobPane(), mseq);
+ jobs[j] = new MsaWSJob(wsinfo.addJobPane(), conmsa[j]);
}
else
{
- jobs[j] = new MsaWSJob(0, mseq);
+ jobs[j] = new MsaWSJob(0, conmsa[j]);
+ }
+ if (njobs > 0)
+ {
+ wsinfo.setProgressName("region " + jobs[j].jobnum, jobs[j].jobnum);
}
- wsinfo.setProgressName("region " + jobs[j].jobnum, jobs[j].jobnum);
wsinfo.setProgressText(jobs[j].jobnum, OutputHeader);
- j++;
- }
- }
- else
- {
- SequenceI mseq[] = new SequenceI[msa.length];
- for (int s = 0; s < mseq.length; s++)
- {
- mseq[s] = msa[s].getSeq('-');
}
- jobs = new MsaWSJob[1];
- wsinfo.setProgressText(OutputHeader); // ensures default text
- jobs[0] = new MsaWSJob(0, mseq);
}
}
{
// CANCELLED_JOB
cancelledMessage = "Job cancelled.";
- ((MsaWSJob) jobs[job]).cancel();
+ ( (MsaWSJob) jobs[job]).cancel();
wsInfo.setStatus(jobs[job].jobnum,
WebserviceInfo.STATE_CANCELLED_OK);
}
cancelledMessage +=
("\nProblems cancelling the job : Exception received...\n"
+ exc + "\n");
- Cache.log.warn("Exception whilst cancelling "+jobs[job].jobId,exc);
+ Cache.log.warn("Exception whilst cancelling " + jobs[job].jobId,
+ exc);
}
wsInfo.setProgressText(jobs[job].jobnum, OutputHeader
+ cancelledMessage + "\n");
}
}
}
- void pollJob(WSJob job) throws Exception {
- ((MsaWSJob) job).result = server.getResult(((MsaWSJob) job).jobId);
+
+ void pollJob(WSJob job)
+ throws Exception
+ {
+ ( (MsaWSJob) job).result = server.getResult( ( (MsaWSJob) job).jobId);
}
+
void StartJob(WSJob job)
{
- if (!(job instanceof MsaWSJob)) {
- throw new Error("StartJob(MsaWSJob) called on a WSJobInstance "+job.getClass());
+ if (! (job instanceof MsaWSJob))
+ {
+ throw new Error("StartJob(MsaWSJob) called on a WSJobInstance " +
+ job.getClass());
}
MsaWSJob j = (MsaWSJob) job;
if (j.submitted)
j.result = new MsaResult();
j.result.setFinished(true);
j.result.setStatus("Empty Alignment Job");
- ((MsaResult) j.result).setMsa(null);
+ ( (MsaResult) j.result).setMsa(null);
}
try
{
if (jobs[j].submitted && jobs[j].subjobComplete && jobs[j].hasResults())
{
results++;
- vamsas.objects.simple.Alignment valign = ((MsaResult) jobs[j].result).getMsa();
+ vamsas.objects.simple.Alignment valign = ( (MsaResult) jobs[j].result).
+ getMsa();
if (valign != null)
{
wsInfo.appendProgressText(jobs[j].jobnum,
}
});
wsInfo.setResultsReady();
- } else
+ }
+ else
+ {
wsInfo.setFinishedNoResults();
+ }
}
void displayResults(boolean newFrame)
{
// view input or result data for each block
- // warn user if a block is input rather than aligned data ?
-
- int contigs[] = input.getContigs();
- SeqCigar[] seqs = input.getSequences();
- SequenceI[] alignment = new SequenceI[seqs.length];
- ColumnSelection columnselection = new ColumnSelection();
Vector alorders = new Vector();
- if (contigs != null && contigs.length > 0)
- {
- int start = 0;
- int nwidth = 0;
- int owidth = input.getWidth();
- int j = 0;
- for (int contig = 0; contig < contigs.length; contig += 3)
- {
- owidth += contigs[contig + 2]; // recover final column width
- if (contigs[contig + 1] - start > 0)
- {
- int width = 0; // subalignment width
- if (jobs[j].hasResults())
- {
- Object[] subalg = ((MsaWSJob) jobs[j++]).getAlignment();
- alorders.add(subalg[1]);
- SequenceI mseq[] = (SequenceI[]) subalg[0];
- width = mseq[0].getLength();
- for (int s = 0; s < mseq.length; s++)
- {
- if (alignment[s] == null)
- {
- alignment[s] = mseq[s];
- }
- else
- {
- alignment[s].setSequence(alignment[s].getSequence() +
- mseq[s].getSequence());
- if (mseq[s].getStart() <= mseq[s].getEnd())
- {
- alignment[s].setEnd(mseq[s].getEnd());
- }
- ( (AlignmentOrder) subalg[1]).updateSequence(mseq[s],
- alignment[s]);
- }
- }
- }
- else
- {
- // recover input data or place gaps
- if (true)
- {
- // recover input data
- for (int s = 0; s < seqs.length; s++)
- {
- SequenceI oseq = seqs[s].getSeq('-').getSubSequence(start,
- contigs[contig + 1]);
- if (width < oseq.getLength())
- {
- width = oseq.getLength();
- }
- if (alignment[s] == null)
- {
- alignment[s] = oseq;
- }
- else
- {
- alignment[s].setSequence(alignment[s].getSequence() +
- oseq.getSequence());
- if (oseq.getEnd() >= oseq.getStart())
- {
- alignment[s].setEnd(oseq.getEnd());
- }
- }
- }
+ SequenceI[][] results = new SequenceI[jobs.length][];
+ AlignmentOrder[] orders = new AlignmentOrder[jobs.length];
- }
- j++;
- }
- nwidth += width;
- }
- // advance to begining of visible region
- start = contigs[contig + 1] + contigs[contig + 2];
- // add hidden segment to right of next region
- for (int s = 0; s < seqs.length; s++)
- {
- SequenceI hseq = seqs[s].getSeq('-').getSubSequence(contigs[contig +
- 1], start);
- if (alignment[s] == null)
- {
- alignment[s] = hseq;
- }
- else
- {
- alignment[s].setSequence(alignment[s].getSequence() +
- hseq.getSequence());
- if (hseq.getEnd() >= hseq.getStart())
- {
- alignment[s].setEnd(hseq.getEnd());
- }
- }
- }
- // mark hidden segment as hidden in the new alignment
- columnselection.hideColumns(nwidth, nwidth + contigs[contig + 2] - 1);
- nwidth += contigs[contig + 2];
- }
- // Do final job - if it exists
- if (j < jobs.length)
- {
- int width = 0;
- if (jobs[j].hasResults())
- {
- Object[] subalg = ((MsaWSJob) jobs[j]).getAlignment();
- alorders.add(subalg[1]);
- SequenceI mseq[] = (SequenceI[]) subalg[0];
- width = mseq[0].getLength();
- for (int s = 0; s < mseq.length; s++)
- {
- if (alignment[s] == null)
- {
- alignment[s] = mseq[s];
- }
- else
- {
- alignment[s].setSequence(alignment[s].getSequence() +
- mseq[s].getSequence());
- if (mseq[s].getEnd() >= mseq[s].getStart())
- {
- alignment[s].setEnd(mseq[s].getEnd());
- }
- ( (AlignmentOrder) subalg[1]).updateSequence(mseq[s], alignment[s]);
- }
- }
- }
- else
- {
- if (start < owidth)
- {
- // recover input data or place gaps
- if (true)
- {
- // recover input data
- for (int s = 0; s < seqs.length; s++)
- {
- SequenceI oseq = seqs[s].getSeq('-').getSubSequence(start,
- owidth + 1);
- if (width < oseq.getLength())
- {
- width = oseq.getLength();
- }
- if (alignment[s] == null)
- {
- alignment[s] = oseq;
- }
- else
- {
- alignment[s].setSequence(alignment[s].getSequence() +
- oseq.getSequence());
- if (oseq.getEnd() >= oseq.getStart())
- {
- alignment[s].setEnd(oseq.getEnd());
- }
- }
- }
- nwidth += width;
- }
- else
- {
- // place gaps.
- throw new Error("Padding not yet implemented.");
- }
- }
- }
- }
- }
- else
+ for (int j = 0; j < jobs.length; j++)
{
- if (jobs[0].hasResults())
+ if (jobs[j].hasResults())
{
- Object[] alg = ((MsaWSJob) jobs[0]).getAlignment();
- alignment = (SequenceI[]) alg[0];
- alorders.add(alg[1]);
+ Object[] res = ( (MsaWSJob) jobs[j]).getAlignment();
+ alorders.add(res[1]);
+ results[j] = (SequenceI[]) res[0];
+ orders[j] = (AlignmentOrder) res[1];
+// SequenceI[] alignment = input.getUpdated
}
else
{
- alignment = SeqCigar.createAlignmentSequences(seqs, '-',
- columnselection, null);
+ results[j] = null;
}
}
+ Object[] newview = input.getUpdatedView(results, orders, '-');
+ // trash references to original result data
+ for (int j = 0; j < jobs.length; j++)
+ {
+ results[j] = null;
+ orders[j] = null;
+ }
+ SequenceI[] alignment = (SequenceI[]) newview[0];
+ ColumnSelection columnselection = (ColumnSelection) newview[1];
Alignment al = new Alignment(alignment);
if (dataset != null)
{
al.setDataset(dataset);
}
+ // JBNote- TODO: warn user if a block is input rather than aligned data ?
+
if (newFrame)
{
- AlignFrame af = new AlignFrame(al, columnselection);
+ AlignFrame af = new AlignFrame(al, columnselection,
+ AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
// >>>This is a fix for the moment, until a better solution is
// found!!<<<
af.getFeatureRenderer().transferSettings(
alignFrame.getFeatureRenderer());
+ // update orders
if (alorders.size() > 0)
{
if (alorders.size() == 1)
{
String orderName = new String(" Region " + i);
int j = i + 1;
- int r = l;
+
while (j < l)
{
if ( ( (AlignmentOrder) alorders.get(i)).equals( ( (
for (int i = 0, l = alorders.size(); i < l; i++)
{
af.addSortByOrderMenuItem(WebServiceName
- +( (String) names.get(i)) +
+ + ( (String) names.get(i)) +
" Ordering",
(AlignmentOrder) alorders.get(i));
}
}
Desktop.addInternalFrame(af, alTitle,
- AlignFrame.NEW_WINDOW_WIDTH,
- AlignFrame.NEW_WINDOW_HEIGHT);
+ AlignFrame.DEFAULT_WIDTH,
+ AlignFrame.DEFAULT_HEIGHT);
}
else
}
}
+
+ public boolean canMergeResults()
+ {
+ return false;
+ }
}