use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.
the class SequenceSimulator method intArray2Sequence.
/**
* Convert integer representation of sequence into a Sequence
*
* @param seq integer representation of the sequence
* @param node used to determine taxon for sequence
* @return Sequence
* @
*/
Sequence intArray2Sequence(int[] seq, Node node) {
DataType dataType = m_data.get().getDataType();
String seqString = dataType.state2string(seq);
// StringBuilder seq = new StringBuilder();
// String map = m_data.get().getMap();
// if (map != null) {
// for (int i = 0; i < m_sequenceLength; i++) {
// seq.append(map.charAt(seq[i]));
// }
// } else {
// for (int i = 0; i < m_sequenceLength-1; i++) {
// seq.append(seq[i] + ",");
// }
// seq.append(seq[m_sequenceLength-1] + "");
// }
List<Sequence> taxa = m_data.get().sequenceInput.get();
String taxon = taxa.get(node.getNr()).taxonInput.get();
return new Sequence(taxon, seqString);
}
use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.
the class MergeDataWith method process.
// initAndValidate
void process(Alignment data, int iteration) throws IOException, XMLParserException, IllegalArgumentException, IllegalAccessException {
// read template
String templateXML = BeautiDoc.load(templateFile);
templateXML = templateXML.replaceAll("\\$\\(n\\)", iteration + "");
XMLParser parser = new XMLParser();
BEASTInterface b = parser.parseBareFragment(templateXML, false);
// repalce alignment
Alignment a = getAlignment(b);
List<Sequence> sequences = a.sequenceInput.get();
sequences.clear();
sequences.addAll(data.sequenceInput.get());
// write file
String outputFile = outputFileInput.get();
outputFile = outputFile.replaceAll("\\$\\(n\\)", iteration + "");
FileWriter outfile = new FileWriter(outputFile);
Set<BEASTInterface> beastObjects = new HashSet<>();
String xml = new XMLProducer().toXML(b, beastObjects);
outfile.write(xml);
outfile.close();
}
use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.
the class SimulatedAlignment method intArray2Sequence.
/**
* Convert integer representation of sequence into a Sequence
*
* @param seq integer representation of the sequence
* @param node used to determine taxon for sequence
* @return Sequence
*/
Sequence intArray2Sequence(int[] seq, Node node) {
DataType dataType = m_data.get().getDataType();
String seqString = dataType.state2string(seq);
// StringBuilder seq = new StringBuilder();
// String map = m_data.get().getMap();
// if (map != null) {
// for (int i = 0; i < m_sequenceLength; i++) {
// seq.append(map.charAt(seq[i]));
// }
// } else {
// for (int i = 0; i < m_sequenceLength-1; i++) {
// seq.append(seq[i] + ",");
// }
// seq.append(seq[m_sequenceLength-1] + "");
// }
String taxon = m_data.get().getTaxaNames().get(node.getNr());
return new Sequence(taxon, seqString);
}
use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.
the class Utils method main.
public static void main(String[] args) {
try {
Sequence a = new Sequence("A", "A");
Sequence b = new Sequence("B", "A");
Sequence c = new Sequence("C", "A");
Sequence d = new Sequence("D", "A");
Alignment data = new Alignment();
data.initByName("sequence", a, "sequence", b, "sequence", c, "sequence", d, "dataType", "nucleotide");
TreeParser tree = new TreeParser();
tree.initByName("taxa", data, "newick", "(((A:1,B:1):1,C:2):1,D:3)", "IsLabelledNewick", true);
JukesCantor JC = new JukesCantor();
JC.initAndValidate();
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", JC);
BeagleTreeLikelihood likelihood = new BeagleTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Success");
// if we got this far, exit with status 0
System.exit(0);
}
use of beast.evolution.alignment.Sequence in project beast2 by CompEvol.
the class BEASTTestCase method getFourTaxaNoData.
public Alignment getFourTaxaNoData() throws Exception {
Sequence a = new Sequence("A", "A");
Sequence b = new Sequence("B", "A");
Sequence c = new Sequence("C", "A");
Sequence d = new Sequence("D", "A");
Alignment data = new Alignment();
data.initByName("sequence", a, "sequence", b, "sequence", c, "sequence", d, "dataType", "nucleotide");
return data;
}
Aggregations