| 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 |
|
|
| |
|
| 0% |
Uncovered Elements: 52 (52) |
Complexity: 12 |
Complexity Density: 0.32 |
|
| 25 |
|
class PhmmerTask extends BaseTask<BaseJob, AlignmentI> |
| 26 |
|
{ |
| 27 |
|
private final AlignmentWebServiceClientI client; |
| 28 |
|
private final AlignmentView view; |
| 29 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 30 |
0 |
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 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 38 |
0 |
@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 |
|
{ |
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 47 |
0 |
@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 |
|
|
| |
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 5 |
Complexity Density: 0.31 |
|
| 57 |
0 |
@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 |
|
|
| |
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 87 |
0 |
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 |
|
|
| 94 |
|
|
| 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 |
|
} |