1 package jalview.ws2.actions.alignment;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.LinkedHashMap;
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;
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.
28 class AlignmentJob extends BaseJob
30 private final List<SequenceI> emptySeqs;
32 private final Map<String, SequenceInfo> names;
34 private AlignmentI alignmentResult;
36 AlignmentJob(List<SequenceI> inputSeqs, List<SequenceI> emptySeqs,
37 Map<String, SequenceInfo> names)
39 super(Collections.unmodifiableList(inputSeqs));
40 this.emptySeqs = Collections.unmodifiableList(emptySeqs);
41 this.names = Collections.unmodifiableMap(names);
44 public static AlignmentJob create(SequenceI[] seqs, int minlen, boolean keepGaps)
47 for (int i = 0; i < seqs.length; i++)
49 if (seqs[i].getEnd() - seqs[i].getStart() >= minlen)
52 boolean valid = nseqs > 1; // need at least two sequences
53 Map<String, SequenceInfo> names = new LinkedHashMap<>();
54 List<SequenceI> inputSeqs = new ArrayList<>();
55 List<SequenceI> emptySeqs = new ArrayList<>();
56 for (int i = 0; i < seqs.length; i++)
58 SequenceI seq = seqs[i];
59 String newName = SeqsetUtils.unique_name(i);
60 names.put(newName, SeqsetUtils.SeqCharacterHash(seq));
61 if (valid && seq.getEnd() - seq.getStart() >= minlen)
63 // make new input sequence
64 String seqString = seq.getSequenceAsString();
66 seqString = AlignSeq.extractGaps(Comparison.GapChars, seqString);
67 inputSeqs.add(new Sequence(newName, seqString));
71 String seqString = "";
72 if (seq.getEnd() >= seq.getStart()) // true if gaps only
74 seqString = seq.getSequenceAsString();
76 seqString = AlignSeq.extractGaps(Comparison.GapChars, seqString);
78 emptySeqs.add(new Sequence(newName, seqString));
81 return new AlignmentJob(inputSeqs, emptySeqs, names);
85 public boolean isInputValid()
87 return inputSeqs.size() >= 2;
90 List<SequenceI> getEmptySequences()
95 Map<String, SequenceInfo> getNames()
102 return alignmentResult != null;
105 AlignmentI getAlignmentResult()
107 return alignmentResult;
110 void setAlignmentResult(AlignmentI alignment)
112 this.alignmentResult = alignment;