Merge branch 'develop' into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.molecular / src / main / java / eu / etaxonomy / taxeditor / molecular / io / wizard / ExportSingleReadAlignmentWizardModel.java
1 /**
2 * Copyright (C) 2016 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.taxeditor.molecular.io.wizard;
10
11
12 import info.bioinfweb.commons.bio.SequenceUtils;
13 import info.bioinfweb.jphyloio.events.type.EventContentType;
14 import info.bioinfweb.jphyloio.factory.JPhyloIOReaderWriterFactory;
15 import info.bioinfweb.jphyloio.formatinfo.JPhyloIOFormatInfo;
16
17 import java.util.ArrayList;
18 import java.util.Collections;
19 import java.util.List;
20
21 import org.eclipse.core.databinding.observable.value.IObservableValue;
22 import org.eclipse.core.databinding.observable.value.WritableValue;
23
24
25
26 /**
27 * The data model for a wizard to export single read alignments to different file formats using <i>JPhyloIO</i>.
28 *
29 * @author Ben Stöver
30 * @date 16.11.2016
31 */
32 public class ExportSingleReadAlignmentWizardModel {
33 protected static final JPhyloIOReaderWriterFactory READER_WRITER_FACTORY = new JPhyloIOReaderWriterFactory();
34 protected static final List<JPhyloIOFormatInfo> FORMATS = createFormatInfoList();
35
36
37 private IObservableValue formatInfo = new WritableValue(0, Integer.class);
38 private IObservableValue fileName = new WritableValue(null, String.class);
39 private IObservableValue exportSingleReads = new WritableValue(true, Boolean.class);
40 private IObservableValue exportConsensusSequence = new WritableValue(true, Boolean.class);
41 private IObservableValue consensusSequenceLabel = new WritableValue("Consensus", String.class);
42 private IObservableValue elongateSequences = new WritableValue(false, Boolean.class);
43 private IObservableValue useGapToken = new WritableValue(true, Boolean.class);
44
45
46 private static List<JPhyloIOFormatInfo> createFormatInfoList() {
47 List<JPhyloIOFormatInfo> result = new ArrayList<JPhyloIOFormatInfo>();
48 for (String formatID : READER_WRITER_FACTORY.getFormatIDsSet()) {
49 JPhyloIOFormatInfo info = READER_WRITER_FACTORY.getFormatInfo(formatID);
50 if (info.isElementModeled(EventContentType.ALIGNMENT, false)) { // Check if the current format allows to write alignments.
51 result.add(info);
52 }
53 }
54 return Collections.unmodifiableList(result);
55 }
56
57
58 protected IObservableValue getFormatInfoObservable() {
59 return formatInfo;
60 }
61
62
63 /**
64 * Returns the <i>JPhyloIO</i> format info object to be used for exporting.
65 *
66 * @return the format info
67 */
68 public JPhyloIOFormatInfo getFormatInfo() {
69 return FORMATS.get((Integer)formatInfo.getValue());
70 }
71
72
73 public String getFileName() {
74 return (String)fileName.getValue();
75 }
76
77
78 protected IObservableValue getFileNameObservable() {
79 return fileName;
80 }
81
82
83 public boolean isExportSingleReads() {
84 return (Boolean)exportSingleReads.getValue();
85 }
86
87
88 protected IObservableValue getExportSingleReadsObservable() {
89 return exportSingleReads;
90 }
91
92
93 public boolean isExportConsensusSequence() {
94 return (Boolean)exportConsensusSequence.getValue();
95 }
96
97
98 protected IObservableValue getExportConsensusSequenceObservable() {
99 return exportConsensusSequence;
100 }
101
102
103 public String getConsensusSequenceLabel() {
104 return (String)consensusSequenceLabel.getValue();
105 }
106
107
108 protected IObservableValue getConsensusSequenceLabelObservable() {
109 return consensusSequenceLabel;
110 }
111
112
113 public String getElongationToken() {
114 if ((Boolean)elongateSequences.getValue()) {
115 if ((Boolean)useGapToken.getValue()) {
116 return Character.toString(SequenceUtils.GAP_CHAR);
117 }
118 else {
119 return Character.toString(SequenceUtils.MISSING_DATA_CHAR);
120 }
121 }
122 else {
123 return null;
124 }
125 }
126
127
128 protected IObservableValue getElongateSequencesObservable() {
129 return elongateSequences;
130 }
131
132
133 protected IObservableValue getUseGapTokenObservable() {
134 return useGapToken;
135 }
136 }