Clover icon

Coverage Report

  1. Project Clover database Thu Dec 4 2025 14:43:25 GMT
  2. Package jalview.ws2.actions.alignment

File AlignmentJob.java

 

Coverage histogram

../../../../img/srcFileCovDistChart8.png
20% 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.781818278.2%
 

Contributing tests

This file is covered by 27 tests. .

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  26 toggle AlignmentJob(List<SequenceI> inputSeqs, List<SequenceI> emptySeqs,
37    Map<String, SequenceInfo> names)
38    {
39  26 super(Collections.unmodifiableList(inputSeqs));
40  26 this.emptySeqs = Collections.unmodifiableList(emptySeqs);
41  26 this.names = Collections.unmodifiableMap(names);
42    }
43   
 
44  26 toggle public static AlignmentJob create(SequenceI[] seqs, int minlen, boolean keepGaps)
45    {
46  26 int nseqs = 0;
47  104 for (int i = 0; i < seqs.length; i++)
48    {
49  78 if (seqs[i].getEnd() - seqs[i].getStart() >= minlen)
50  78 nseqs++;
51    }
52  26 boolean valid = nseqs > 1; // need at least two sequences
53  26 Map<String, SequenceInfo> names = new LinkedHashMap<>();
54  26 List<SequenceI> inputSeqs = new ArrayList<>();
55  26 List<SequenceI> emptySeqs = new ArrayList<>();
56  104 for (int i = 0; i < seqs.length; i++)
57    {
58  78 SequenceI seq = seqs[i];
59  78 String newName = SeqsetUtils.unique_name(i);
60  78 names.put(newName, SeqsetUtils.SeqCharacterHash(seq));
61  78 if (valid && seq.getEnd() - seq.getStart() >= minlen)
62    {
63    // make new input sequence
64  78 String seqString = seq.getSequenceAsString();
65  78 if (!keepGaps)
66  72 seqString = AlignSeq.extractGaps(Comparison.GapChars, seqString);
67  78 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  26 return new AlignmentJob(inputSeqs, emptySeqs, names);
82    }
83   
 
84  196 toggle @Override
85    public boolean isInputValid()
86    {
87  196 return inputSeqs.size() >= 2;
88    }
89   
 
90  8 toggle List<SequenceI> getEmptySequences()
91    {
92  8 return emptySeqs;
93    }
94   
 
95  8 toggle Map<String, SequenceInfo> getNames()
96    {
97  8 return names;
98    }
99   
 
100  46 toggle boolean hasResult()
101    {
102  46 return alignmentResult != null;
103    }
104   
 
105  8 toggle AlignmentI getAlignmentResult()
106    {
107  8 return alignmentResult;
108    }
109   
 
110  20 toggle void setAlignmentResult(AlignmentI alignment)
111    {
112  20 this.alignmentResult = alignment;
113    }
114    }