Clover icon

Coverage Report

  1. Project Clover database Tue Mar 10 2026 14:58:44 GMT
  2. Package jalview.ws2.actions.secstructpred

File SecStructPredMsaTask.java

 

Coverage histogram

../../../../img/srcFileCovDistChart0.png
0% of files have more coverage

Code metrics

8
44
6
2
147
127
11
0.25
7.33
3
1.83

Classes

Class Line # Actions
SecStructPredMsaTask 32 38 8
0.00%
SecStructPredMsaTask.SecStructPredJob 118 6 3
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.ws2.actions.secstructpred;
2   
3    import java.io.IOException;
4    import java.util.ArrayList;
5    import java.util.Arrays;
6    import java.util.List;
7    import java.util.Map;
8   
9    import jalview.analysis.AlignmentAnnotationUtils;
10    import jalview.analysis.SeqsetUtils;
11    import jalview.analysis.SeqsetUtils.SequenceInfo;
12    import jalview.api.AlignViewportI;
13    import jalview.bin.Console;
14    import jalview.datamodel.Alignment;
15    import jalview.datamodel.AlignmentAnnotation;
16    import jalview.datamodel.AlignmentI;
17    import jalview.datamodel.AlignmentView;
18    import jalview.datamodel.HiddenColumns;
19    import jalview.datamodel.SeqCigar;
20    import jalview.datamodel.SequenceI;
21    import jalview.io.AlignFile;
22    import jalview.io.JPredFile;
23    import jalview.io.JnetAnnotationMaker;
24    import jalview.ws.params.ArgumentI;
25    import jalview.ws2.actions.BaseJob;
26    import jalview.ws2.actions.BaseTask;
27    import jalview.ws2.actions.ServiceInputInvalidException;
28    import jalview.ws2.api.Credentials;
29    import jalview.ws2.api.JobStatus;
30    import jalview.ws2.client.api.SecStructPredWebServiceClientI;
31   
 
32    public class SecStructPredMsaTask
33    extends BaseTask<SecStructPredMsaTask.SecStructPredJob, AlignmentI>
34    {
35    private final SecStructPredWebServiceClientI client;
36   
37    private final AlignmentView alignmentView;
38   
39    private final AlignmentI currentView;
40   
41    private final char gapChar;
42   
 
43  0 toggle SecStructPredMsaTask(SecStructPredWebServiceClientI client,
44    List<ArgumentI> args, Credentials credentials,
45    AlignViewportI viewport)
46    {
47  0 super(client, args, credentials);
48  0 this.client = client;
49  0 this.alignmentView = viewport.getAlignmentView(true);
50  0 this.currentView = viewport.getAlignment();
51  0 this.gapChar = viewport.getGapCharacter();
52    }
53   
 
54  0 toggle @Override
55    protected List<SecStructPredJob> prepareJobs()
56    throws ServiceInputInvalidException
57    {
58  0 SeqCigar[] msf = alignmentView.getSequences();
59  0 SequenceI referenceSeq = msf[0].getSeq('-');
60  0 int[] delMap = alignmentView
61    .getVisibleContigMapFor(referenceSeq.gapMap());
62   
63    // TODO: assume MSA for now
64  0 SequenceI[] sequences = new SequenceI[msf.length];
65  0 for (int i = 0; i < msf.length; i++)
66  0 sequences[i] = msf[i].getSeq('-');
67  0 var sequenceInfo = SeqsetUtils.uniquify(sequences, true);
68  0 referenceSeq.setSequence(alignmentView.getASequenceString('-', 0));
69  0 for (int i = 0; i < sequences.length; i++)
70  0 sequences[i].setSequence(alignmentView.getASequenceString('-', i));
71  0 var nonEmptySeqs = SeqsetUtils.getNonEmptySequenceSet(sequences);
72  0 var job = new SecStructPredJob(Arrays.asList(nonEmptySeqs),
73    referenceSeq, delMap, sequenceInfo);
74  0 job.setStatus(JobStatus.READY);
75  0 return List.of(job);
76    }
77   
 
78  0 toggle @Override
79    protected AlignmentI collectResult(List<SecStructPredJob> jobs)
80    throws IOException
81    {
82  0 var job = jobs.get(0); // There shouldn't be more than one job
83  0 var status = job.getStatus();
84  0 Console.info(
85    String.format("sec str pred job \"%s\" finished with status %s",
86    job.getServerJob().getJobId(), status));
87  0 if (status != JobStatus.COMPLETED)
88  0 return null;
89  0 JPredFile predictionFile = client.getPredictionFile(job.getServerJob());
90  0 AlignFile alignmentFile = client.getAlignmentFile(job.getServerJob());
91   
92  0 Object[] alnAndHiddenCols = alignmentView
93    .getAlignmentAndHiddenColumns(gapChar);
94  0 Alignment aln = new Alignment((SequenceI[]) alnAndHiddenCols[0]);
95  0 aln.setDataset(currentView.getDataset());
96  0 aln.setHiddenColumns((HiddenColumns) alnAndHiddenCols[1]);
97  0 try
98    {
99  0 JnetAnnotationMaker.add_annotation(predictionFile, aln, 0, false,
100    job.getDelMap());
101    } catch (Exception e)
102    {
103  0 throw new IOException(e);
104    }
105   
106  0 for (AlignmentAnnotation alnAnnot : aln.getAlignmentAnnotation())
107    {
108  0 if (alnAnnot.sequenceRef != null)
109    {
110  0 AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(alnAnnot,
111    alnAnnot.label, getClass().getSimpleName());
112    }
113    }
114  0 aln.setSeqrep(aln.getSequenceAt(0));
115  0 return aln;
116    }
117   
 
118    public static class SecStructPredJob extends BaseJob
119    {
120    private final int[] delMap;
121   
122    private final SequenceI refSeq;
123   
124    final Map<String, SequenceInfo> seqNames;
125   
 
126  0 toggle SecStructPredJob(List<SequenceI> sequences, SequenceI refSeq,
127    int[] delMap, Map<String, SequenceInfo> seqNames)
128    {
129  0 super(sequences);
130  0 this.refSeq = refSeq;
131  0 this.delMap = delMap;
132  0 this.seqNames = seqNames;
133    }
134   
 
135  0 toggle @Override
136    public boolean isInputValid()
137    {
138  0 return true;
139    }
140   
 
141  0 toggle public int[] getDelMap()
142    {
143  0 return this.delMap;
144    }
145    }
146   
147    }