import jalview.gui.AlignFrame;
import jalview.ws.WSClient;
import jalview.ws.WSMenuEntryProviderI;
-import jalview.ws.api.JPredMutlipleAlignmentServiceI;
+import jalview.ws.api.JPredServiceI;
import jalview.ws.api.ServiceWithParameters;
public class JPredClient extends WSClient
{
- JPredMutlipleAlignmentServiceI server;
+ JPredServiceI server;
public JPredClient(ServiceWithParameters sh, String title,
AlignmentView alView, AlignFrame alFrame, boolean viewOnly)
{
- server = (JPredMutlipleAlignmentServiceI) sh.getEndpoint();
+ server = (JPredServiceI) sh.getEndpoint();
wsInfo = setWebService(sh, false);
startClient(title, alView, alFrame, viewOnly);
}
{
var msf = view.getSequences();
var seq = msf[0].getSeq('-');
- if (msf.length <= 1)
- throw new RuntimeException("You need more than one sequence.");
+ int[] delMap = null;
+ if (viewOnly)
+ delMap = view.getVisibleContigMapFor(seq.gapMap());
var aln = new SequenceI[msf.length];
for (int i = 0; i < msf.length; i++)
{
aln[i] = msf[i].getSeq('-');
}
- int[] delMap = viewOnly ?
- view.getVisibleContigMapFor(seq.gapMap()) : null;
- var sequenceInfo = SeqsetUtils.uniquify(aln, true);
+ var sequenceInfo = msf.length > 1 ? SeqsetUtils.uniquify(aln, true)
+ : SeqsetUtils.SeqCharacterHash(seq);
+ if (viewOnly)
+ {
+ String seqs[] = view.getSequenceStrings('-');
+ for (int i = 0; i < msf.length; i++)
+ aln[i].setSequence(seqs[i]);
+ seq.setSequence(seqs[0]);
+ }
var thread = new JPredThread(wsInfo, title, server, sequenceInfo, aln,
delMap, view, frame, WsURL);
wsInfo.setthisService(thread);
mi.setToolTipText(sh.getHostURL());
mi.addActionListener((event) -> {
var view = frame.gatherSeqOrMsaForSecStrPrediction();
- if (view.getSequences().length > 1)
- {
- new JPredClient(sh, frame.getTitle(), view, frame, true);
- }
- else
- {
- Cache.log.error("Single sequence not supported");
- }
+ new JPredClient(sh, frame.getTitle(), view, frame, true);
});
menu.add(mi);
};
import jalview.analysis.SeqsetUtils;
import jalview.bin.Cache;
+import jalview.commands.RemoveGapsCommand;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.ws.JobStateSummary;
import jalview.ws.WSClientI;
import jalview.ws.api.CancellableI;
-import jalview.ws.api.JPredMutlipleAlignmentServiceI;
+import jalview.ws.api.JPredServiceI;
import jalview.ws.gui.WsJob;
import jalview.ws.gui.WsJob.JobState;
-class JPredJob extends WsJob
+public class JPredThread extends AWSThread implements WSClientI
{
- Hashtable<?, ?> sequenceInfo;
- List<SequenceI> msf;
- int[] delMap;
- AlignmentI alignment = null;
- HiddenColumns hiddenCols = null;
- public JPredJob(Hashtable<?, ?> sequenceInfo, SequenceI[] msf, int[] delMap)
+ private static class JPredJob extends WsJob
{
- this.sequenceInfo = sequenceInfo;
- this.msf = List.of(msf);
- this.delMap = delMap;
- }
+ private final Hashtable<?, ?> sequenceInfo;
+ private final List<SequenceI> msf;
+ private final int[] delMap;
+ private AlignmentI alignment = null;
+ private HiddenColumns hiddenCols = null;
- @Override
- public boolean hasValidInput()
- {
- return true;
- }
+ private JPredJob(Hashtable<?, ?> sequenceInfo, SequenceI[] msf, int[] delMap)
+ {
+ this.sequenceInfo = sequenceInfo;
+ this.msf = List.of(msf);
+ this.delMap = delMap;
+ }
- @Override
- public boolean hasResults()
- {
- return (isSubjobComplete() && alignment != null);
- }
-}
+ @Override
+ public boolean hasValidInput()
+ {
+ return true;
+ }
+ @Override
+ public boolean hasResults()
+ {
+ return (isSubjobComplete() && alignment != null);
+ }
+
+ public boolean isMSA()
+ {
+ return msf.size() > 1;
+ }
+ }
-public class JPredThread extends AWSThread implements WSClientI
-{
- private JPredMutlipleAlignmentServiceI server;
+ private JPredServiceI server;
private String title;
private Hashtable<?, ?> sequenceInfo;
private SequenceI[] msf;
private int[] delMap;
public JPredThread(WebserviceInfo wsInfo, String title,
- JPredMutlipleAlignmentServiceI server, Hashtable<?, ?> sequenceInfo,
+ JPredServiceI server, Hashtable<?, ?> sequenceInfo,
SequenceI[] msf, int[] delMap, AlignmentView view, AlignFrame frame,
String wsURL)
{
try {
try
{
- var jobHandle = server.align(job.msf);
+ var jobHandle = server.predict(job.msf, job.isMSA());
if (jobHandle != null)
job.setJobHandle(jobHandle);
}
wsInfo.removeProgressBar(progbar);
}
+ static final int msaIndex = 0;
+
private void prepareJobResult(JPredJob job) throws Exception
{
HiddenColumns hiddenCols = null;
var prediction = server.getPrediction(job.getJobHandle());
var preds = prediction.getSeqsAsArray();
- if (job.delMap != null)
+ if (job.msf.size() > 1)
{
- Object[] alandcolsel = input
- .getAlignmentAndHiddenColumns(getGapChar());
- alignment = new Alignment((SequenceI[]) alandcolsel[0]);
- hiddenCols = (HiddenColumns) alandcolsel[1];
+ if (job.delMap != null)
+ {
+ Object[] alandcolsel = input
+ .getAlignmentAndHiddenColumns(getGapChar());
+ alignment = new Alignment((SequenceI[]) alandcolsel[0]);
+ hiddenCols = (HiddenColumns) alandcolsel[1];
+ }
+ else
+ {
+ alignment = server.getAlignment(job.getJobHandle());
+ var seqs = new SequenceI[alignment.getHeight()];
+ for (int i = 0; i < alignment.getHeight(); i++)
+ {
+ seqs[i] = alignment.getSequenceAt(i);
+ }
+ if (!SeqsetUtils.deuniquify(sequenceInfo, seqs))
+ {
+ throw (new Exception(MessageManager.getString(
+ "exception.couldnt_recover_sequence_properties_for_alignment")));
+ }
+ }
+ firstSeq = 0;
+ if (currentView.getDataset() != null)
+ {
+ alignment.setDataset(currentView.getDataset());
+ }
+ else
+ {
+ alignment.setDataset(null);
+ }
+ JnetAnnotationMaker.add_annotation(prediction, alignment, firstSeq, false,
+ job.delMap);
}
else
{
- alignment = server.getAlignment(job.getJobHandle());
- var seqs = new SequenceI[alignment.getHeight()];
- for (int i = 0; i < alignment.getHeight(); i++)
+ alignment = new Alignment(preds);
+ firstSeq = prediction.getQuerySeqPosition();
+ if (job.delMap != null)
{
- seqs[i] = alignment.getSequenceAt(i);
+ Object[] alanndcolsel = input.getAlignmentAndHiddenColumns(getGapChar());
+ SequenceI[] seqs = (SequenceI[]) alanndcolsel[0];
+ new RemoveGapsCommand(MessageManager.getString("label.remove_gaps"),
+ new SequenceI[] {seqs[msaIndex]}, currentView);
+ SequenceI profileSeq = alignment.getSequenceAt(firstSeq);
+ profileSeq.setSequence(seqs[msaIndex].getSequenceAsString());
}
- if (!SeqsetUtils.deuniquify(sequenceInfo, seqs))
+ if (!SeqsetUtils.SeqCharacterUnhash(
+ alignment.getSequenceAt(firstSeq), sequenceInfo))
{
- throw (new Exception(MessageManager.getString(
- "exception.couldnt_recover_sequence_properties_for_alignment")));
+ throw new Exception(MessageManager.getString(
+ "exception.couldnt_recover_sequence_props_for_jnet_query"));
}
- }
- firstSeq = 0;
- if (currentView.getDataset() != null)
- {
alignment.setDataset(currentView.getDataset());
+ JnetAnnotationMaker.add_annotation(prediction, alignment, firstSeq, true,
+ job.delMap);
+ SequenceI profileSeq = alignment.getSequenceAt(0);
+ alignToProfileSeq(alignment, profileSeq);
+ if (job.delMap != null)
+ {
+ hiddenCols = alignment.propagateInsertions(profileSeq, input);
+ }
}
- else
- {
- alignment.setDataset(null);
- }
- JnetAnnotationMaker.add_annotation(prediction, alignment, firstSeq, false,
- job.delMap);
for (var annot : alignment.getAlignmentAnnotation())
{
dssan.adjustForAlignment();
}
+ private static void alignToProfileSeq(AlignmentI al, SequenceI profileseq)
+ {
+ char gc = al.getGapCharacter();
+ int[] gapMap = profileseq.gapMap();
+ // insert gaps into profile
+ for (int lp = 0, r = 0; r < gapMap.length; r++)
+ {
+ if (gapMap[r] - lp > 1)
+ {
+ StringBuffer sb = new StringBuffer();
+ for (int s = 0, ns = gapMap[r] - lp; s < ns; s++)
+ {
+ sb.append(gc);
+ }
+ for (int s = 1, ns = al.getHeight(); s < ns; s++)
+ {
+ String sq = al.getSequenceAt(s).getSequenceAsString();
+ int diff = gapMap[r] - sq.length();
+ if (diff > 0)
+ {
+ // pad gaps
+ sq = sq + sb;
+ while ((diff = gapMap[r] - sq.length()) > 0)
+ {
+ sq = sq + ((diff >= sb.length()) ? sb.toString()
+ : sb.substring(0, diff));
+ }
+ al.getSequenceAt(s).setSequence(sq);
+ }
+ else
+ {
+ al.getSequenceAt(s).setSequence(sq.substring(0, gapMap[r])
+ + sb.toString() + sq.substring(gapMap[r]));
+ }
+ }
+ }
+ lp = gapMap[r];
+ }
+ }
+
private void displayResults(boolean newWindow)
{
if (jobs == null || jobs.length == 0)
var job = (JPredJob) jobs[0];
if (job.hasResults() && newWindow)
{
- AlignFrame frame;
job.alignment.setSeqrep(job.alignment.getSequenceAt(0));
- frame = new AlignFrame(job.alignment, job.hiddenCols,
+ AlignFrame frame = new AlignFrame(job.alignment, job.hiddenCols,
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
Desktop.addInternalFrame(frame, title, AlignFrame.DEFAULT_WIDTH,
AlignFrame.DEFAULT_HEIGHT);