Clover icon

Coverage Report

  1. Project Clover database Wed Dec 3 2025 17:03:17 GMT
  2. Package jalview.ws2.actions.hmmer

File PhmmerTask.java

 

Coverage histogram

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

Code metrics

10
37
5
1
111
101
12
0.32
7.4
5
2.4

Classes

Class Line # Actions
PhmmerTask 25 37 12
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.ws2.actions.hmmer;
2   
3    import static jalview.util.Comparison.GapChars;
4   
5    import java.io.IOException;
6    import java.util.List;
7   
8    import jalview.analysis.AlignSeq;
9    import jalview.bin.Console;
10    import jalview.datamodel.AlignmentAnnotation;
11    import jalview.datamodel.AlignmentI;
12    import jalview.datamodel.AlignmentView;
13    import jalview.datamodel.Annotation;
14    import jalview.datamodel.Sequence;
15    import jalview.datamodel.SequenceI;
16    import jalview.util.Comparison;
17    import jalview.ws.params.ArgumentI;
18    import jalview.ws2.actions.BaseJob;
19    import jalview.ws2.actions.BaseTask;
20    import jalview.ws2.actions.ServiceInputInvalidException;
21    import jalview.ws2.api.Credentials;
22    import jalview.ws2.api.JobStatus;
23    import jalview.ws2.client.api.AlignmentWebServiceClientI;
24   
 
25    class PhmmerTask extends BaseTask<BaseJob, AlignmentI>
26    {
27    private final AlignmentWebServiceClientI client;
28    private final AlignmentView view;
29   
 
30  0 toggle PhmmerTask(AlignmentWebServiceClientI client, List<ArgumentI> args,
31    Credentials credentials, AlignmentView view)
32    {
33  0 super(client, args, credentials);
34  0 this.client = client;
35  0 this.view = view;
36    }
37   
 
38  0 toggle @Override
39    protected List<BaseJob> prepareJobs() throws ServiceInputInvalidException
40    {
41  0 Console.info("Preparing sequence for phmmer job");
42  0 var sequence = view.getVisibleAlignment('-').getSequenceAt(0);
43  0 var seq = new Sequence(sequence.getName(),
44    AlignSeq.extractGaps(GapChars, sequence.getSequenceAsString()));
45  0 var job = new BaseJob(List.of(seq))
46    {
 
47  0 toggle @Override
48    public boolean isInputValid()
49    {
50  0 return true;
51    }
52    };
53  0 job.setStatus(JobStatus.READY);
54  0 return List.of(job);
55    }
56   
 
57  0 toggle @Override
58    protected AlignmentI collectResult(List<BaseJob> jobs) throws IOException
59    {
60  0 var job = jobs.get(0);
61  0 var status = job.getStatus();
62  0 Console.info(String.format("phmmer finished job \"%s\" with status %s",
63    job.getServerJob().getJobId(), status));
64  0 if (status != JobStatus.COMPLETED)
65  0 return null;
66  0 var outputAlignment = client.getAlignment(job.getServerJob());
67  0 var querySeq = job.getInputSequences().get(0).deriveSequence();
68    {
69  0 AlignmentAnnotation refpos = null;
70  0 for (var annot : outputAlignment.getAlignmentAnnotation())
71    {
72  0 if (annot.sequenceRef == null && annot.label.equals("Reference Positions"))
73    {
74  0 refpos = annot;
75  0 break;
76    }
77    }
78  0 if (refpos != null)
79    {
80  0 querySeq = alignQeuryToReferencePositions(querySeq, refpos);
81    }
82    }
83  0 outputAlignment.insertSequenceAt(0, querySeq);
84  0 return outputAlignment;
85    }
86   
 
87  0 toggle private SequenceI alignQeuryToReferencePositions(SequenceI query, AlignmentAnnotation refpos)
88    {
89  0 var sequenceBuilder = new StringBuilder();
90  0 var index = 0;
91  0 for (Annotation a : refpos.annotations)
92    {
93    // TODO: we assume that the number of "x" annotations is equal to the number
94    // of residues. may need a safeguard against invalid input
95  0 if (a != null && a.displayCharacter.equals("x"))
96    {
97  0 char c;
98  0 do
99  0 c = query.getCharAt(index++);
100  0 while (Comparison.isGap(c));
101  0 sequenceBuilder.append(c);
102    }
103    else
104    {
105  0 sequenceBuilder.append(Comparison.GAP_DASH);
106    }
107    }
108  0 query.setSequence(sequenceBuilder.toString());
109  0 return query;
110    }
111    }