Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 16:11:35 GMT
  2. Package jalview.ws2.actions.secstructpred

File SecStructPredMsaTask.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.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.918367391.8%
SecStructPredMsaTask.SecStructPredJob 118 6 3
1.0100%
 

Contributing tests

This file is covered by 10 tests. .

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  10 toggle SecStructPredMsaTask(SecStructPredWebServiceClientI client,
44    List<ArgumentI> args, Credentials credentials,
45    AlignViewportI viewport)
46    {
47  10 super(client, args, credentials);
48  10 this.client = client;
49  10 this.alignmentView = viewport.getAlignmentView(true);
50  10 this.currentView = viewport.getAlignment();
51  10 this.gapChar = viewport.getGapCharacter();
52    }
53   
 
54  10 toggle @Override
55    protected List<SecStructPredJob> prepareJobs()
56    throws ServiceInputInvalidException
57    {
58  10 SeqCigar[] msf = alignmentView.getSequences();
59  10 SequenceI referenceSeq = msf[0].getSeq('-');
60  10 int[] delMap = alignmentView
61    .getVisibleContigMapFor(referenceSeq.gapMap());
62   
63    // TODO: assume MSA for now
64  10 SequenceI[] sequences = new SequenceI[msf.length];
65  37 for (int i = 0; i < msf.length; i++)
66  27 sequences[i] = msf[i].getSeq('-');
67  10 var sequenceInfo = SeqsetUtils.uniquify(sequences, true);
68  10 referenceSeq.setSequence(alignmentView.getASequenceString('-', 0));
69  37 for (int i = 0; i < sequences.length; i++)
70  27 sequences[i].setSequence(alignmentView.getASequenceString('-', i));
71  10 var nonEmptySeqs = SeqsetUtils.getNonEmptySequenceSet(sequences);
72  10 var job = new SecStructPredJob(Arrays.asList(nonEmptySeqs),
73    referenceSeq, delMap, sequenceInfo);
74  10 job.setStatus(JobStatus.READY);
75  10 return List.of(job);
76    }
77   
 
78  2 toggle @Override
79    protected AlignmentI collectResult(List<SecStructPredJob> jobs)
80    throws IOException
81    {
82  2 var job = jobs.get(0); // There shouldn't be more than one job
83  2 var status = job.getStatus();
84  2 Console.info(
85    String.format("sec str pred job \"%s\" finished with status %s",
86    job.getServerJob().getJobId(), status));
87  2 if (status != JobStatus.COMPLETED)
88  0 return null;
89  2 JPredFile predictionFile = client.getPredictionFile(job.getServerJob());
90  2 AlignFile alignmentFile = client.getAlignmentFile(job.getServerJob());
91   
92  2 Object[] alnAndHiddenCols = alignmentView
93    .getAlignmentAndHiddenColumns(gapChar);
94  2 Alignment aln = new Alignment((SequenceI[]) alnAndHiddenCols[0]);
95  2 aln.setDataset(currentView.getDataset());
96  2 aln.setHiddenColumns((HiddenColumns) alnAndHiddenCols[1]);
97  2 try
98    {
99  2 JnetAnnotationMaker.add_annotation(predictionFile, aln, 0, false,
100    job.getDelMap());
101    } catch (Exception e)
102    {
103  0 throw new IOException(e);
104    }
105   
106  2 for (AlignmentAnnotation alnAnnot : aln.getAlignmentAnnotation())
107    {
108  18 if (alnAnnot.sequenceRef != null)
109    {
110  18 AlignmentAnnotationUtils.replaceAnnotationOnAlignmentWith(alnAnnot,
111    alnAnnot.label, getClass().getSimpleName());
112    }
113    }
114  2 aln.setSeqrep(aln.getSequenceAt(0));
115  2 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  10 toggle SecStructPredJob(List<SequenceI> sequences, SequenceI refSeq,
127    int[] delMap, Map<String, SequenceInfo> seqNames)
128    {
129  10 super(sequences);
130  10 this.refSeq = refSeq;
131  10 this.delMap = delMap;
132  10 this.seqNames = seqNames;
133    }
134   
 
135  8 toggle @Override
136    public boolean isInputValid()
137    {
138  8 return true;
139    }
140   
 
141  2 toggle public int[] getDelMap()
142    {
143  2 return this.delMap;
144    }
145    }
146   
147    }