Clover icon

Coverage Report

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

File AlignmentJob.java

 

Coverage histogram

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

Code metrics

14
33
8
1
114
91
16
0.48
4.12
8
2

Classes

Class Line # Actions
AlignmentJob 28 33 16
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package jalview.ws2.actions.alignment;
2   
3    import java.util.ArrayList;
4    import java.util.Collections;
5    import java.util.LinkedHashMap;
6    import java.util.List;
7    import java.util.Map;
8   
9    import jalview.analysis.AlignSeq;
10    import jalview.analysis.SeqsetUtils;
11    import jalview.analysis.SeqsetUtils.SequenceInfo;
12    import jalview.datamodel.AlignmentI;
13    import jalview.datamodel.Sequence;
14    import jalview.datamodel.SequenceI;
15    import jalview.util.Comparison;
16    import jalview.ws2.actions.BaseJob;
17    import jalview.ws2.api.WebServiceJobHandle;
18   
19    /**
20    * A wrapper class that extends basic job container with data specific to
21    * alignment services. It stores input and empty sequences (with uniquified
22    * names) along the original sequence information. {@link AlignmentJob} objects
23    * are created by {@link AlignmentTask} during a preparation stage.
24    *
25    * @author mmwarowny
26    *
27    */
 
28    class AlignmentJob extends BaseJob
29    {
30    private final List<SequenceI> emptySeqs;
31   
32    private final Map<String, SequenceInfo> names;
33   
34    private AlignmentI alignmentResult;
35   
 
36  0 toggle AlignmentJob(List<SequenceI> inputSeqs, List<SequenceI> emptySeqs,
37    Map<String, SequenceInfo> names)
38    {
39  0 super(Collections.unmodifiableList(inputSeqs));
40  0 this.emptySeqs = Collections.unmodifiableList(emptySeqs);
41  0 this.names = Collections.unmodifiableMap(names);
42    }
43   
 
44  0 toggle public static AlignmentJob create(SequenceI[] seqs, int minlen, boolean keepGaps)
45    {
46  0 int nseqs = 0;
47  0 for (int i = 0; i < seqs.length; i++)
48    {
49  0 if (seqs[i].getEnd() - seqs[i].getStart() >= minlen)
50  0 nseqs++;
51    }
52  0 boolean valid = nseqs > 1; // need at least two sequences
53  0 Map<String, SequenceInfo> names = new LinkedHashMap<>();
54  0 List<SequenceI> inputSeqs = new ArrayList<>();
55  0 List<SequenceI> emptySeqs = new ArrayList<>();
56  0 for (int i = 0; i < seqs.length; i++)
57    {
58  0 SequenceI seq = seqs[i];
59  0 String newName = SeqsetUtils.unique_name(i);
60  0 names.put(newName, SeqsetUtils.SeqCharacterHash(seq));
61  0 if (valid && seq.getEnd() - seq.getStart() >= minlen)
62    {
63    // make new input sequence
64  0 String seqString = seq.getSequenceAsString();
65  0 if (!keepGaps)
66  0 seqString = AlignSeq.extractGaps(Comparison.GapChars, seqString);
67  0 inputSeqs.add(new Sequence(newName, seqString));
68    }
69    else
70    {
71  0 String seqString = "";
72  0 if (seq.getEnd() >= seq.getStart()) // true if gaps only
73    {
74  0 seqString = seq.getSequenceAsString();
75  0 if (!keepGaps)
76  0 seqString = AlignSeq.extractGaps(Comparison.GapChars, seqString);
77    }
78  0 emptySeqs.add(new Sequence(newName, seqString));
79    }
80    }
81  0 return new AlignmentJob(inputSeqs, emptySeqs, names);
82    }
83   
 
84  0 toggle @Override
85    public boolean isInputValid()
86    {
87  0 return inputSeqs.size() >= 2;
88    }
89   
 
90  0 toggle List<SequenceI> getEmptySequences()
91    {
92  0 return emptySeqs;
93    }
94   
 
95  0 toggle Map<String, SequenceInfo> getNames()
96    {
97  0 return names;
98    }
99   
 
100  0 toggle boolean hasResult()
101    {
102  0 return alignmentResult != null;
103    }
104   
 
105  0 toggle AlignmentI getAlignmentResult()
106    {
107  0 return alignmentResult;
108    }
109   
 
110  0 toggle void setAlignmentResult(AlignmentI alignment)
111    {
112  0 this.alignmentResult = alignment;
113    }
114    }