Search in sources :

Example 11 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class BeautiAlignmentBuffer method getStates.

public void getStates(int sequenceIndex, int fromSite, int toSite, byte[] states) {
    Sequence sequence = alignment.getSequence(sequenceIndex);
    int j = 0;
    for (int i = fromSite; i <= toSite; i++) {
        states[j] = (byte) sequence.getState(i);
        j++;
    }
}
Also used : Sequence(dr.evolution.sequence.Sequence)

Example 12 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class SequenceParser method parseXMLObject.

/**
     * @return a sequence object based on the XML element it was passed.
     */
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Sequence sequence = new Sequence();
    Taxon taxon = (Taxon) xo.getChild(Taxon.class);
    DataType dataType = null;
    if (xo.hasAttribute(DataType.DATA_TYPE)) {
        String dataTypeStr = xo.getStringAttribute(DataType.DATA_TYPE);
        if (dataTypeStr.equals(Nucleotides.DESCRIPTION)) {
            dataType = Nucleotides.INSTANCE;
        } else if (dataTypeStr.equals(AminoAcids.DESCRIPTION)) {
            dataType = AminoAcids.INSTANCE;
        } else if (dataTypeStr.equals(Codons.DESCRIPTION)) {
            dataType = Codons.UNIVERSAL;
        } else if (dataTypeStr.equals(TwoStates.DESCRIPTION)) {
            dataType = TwoStates.INSTANCE;
        }
    }
    StringBuffer seqBuf = new StringBuffer();
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object child = xo.getChild(i);
        if (child instanceof String) {
            StringTokenizer st = new StringTokenizer((String) child);
            while (st.hasMoreTokens()) {
                seqBuf.append(st.nextToken());
            }
        }
    }
    // We really need to filter the input string to check for illegal characters.
    // Perhaps sequence.setSequenceString could throw an exception if any characters
    // don't fit the dataType.
    String sequenceString = seqBuf.toString();
    if (sequenceString.length() == 0) {
        throw new XMLParseException("Sequence data missing from sequence element!");
    }
    if (dataType != null) {
        sequence.setDataType(dataType);
    }
    sequence.setSequenceString(sequenceString);
    sequence.setTaxon(taxon);
    return sequence;
}
Also used : StringTokenizer(java.util.StringTokenizer) Taxon(dr.evolution.util.Taxon) Sequence(dr.evolution.sequence.Sequence)

Example 13 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class BeagleSequenceSimulator method compileAlignment.

// END: SimulatePartitionCallable class
private SimpleAlignment compileAlignment() {
    SimpleAlignment simpleAlignment = new SimpleAlignment();
    simpleAlignment.setReportCountStatistics(false);
    simpleAlignment.setDataType(dataType);
    LinkedHashMap<Taxon, int[]> alignmentMap = new LinkedHashMap<Taxon, int[]>();
    // compile the alignment
    for (Partition partition : partitions) {
        Map<Taxon, int[]> sequenceMap = partition.getTaxonSequencesMap();
        Iterator<Entry<Taxon, int[]>> iterator = sequenceMap.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry<Taxon, int[]> pairs = (Entry<Taxon, int[]>) iterator.next();
            Taxon taxon = pairs.getKey();
            int[] partitionSequence = pairs.getValue();
            if (alignmentMap.containsKey(taxon)) {
                int j = 0;
                for (int i = partition.from; i <= partition.to; i += partition.every) {
                    alignmentMap.get(taxon)[i] = partitionSequence[j];
                    j++;
                }
            // END: i loop
            } else {
                int[] sequence = new int[siteCount];
                // dirty solution for gaps when taxa between the tree
                // topologies don't match
                Arrays.fill(sequence, gapFlag);
                int j = 0;
                for (int i = partition.from; i <= partition.to; i += partition.every) {
                    sequence[i] = partitionSequence[j];
                    j++;
                }
                // END: i loop
                alignmentMap.put(taxon, sequence);
            }
        // END: key check
        }
    // END: iterate seqMap
    }
    // END: partitions loop
    Iterator<Entry<Taxon, int[]>> iterator = alignmentMap.entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<Taxon, int[]> pairs = (Entry<Taxon, int[]>) iterator.next();
        Taxon taxon = (Taxon) pairs.getKey();
        int[] intSequence = (int[]) pairs.getValue();
        Sequence sequence = //
        Utils.intArray2Sequence(//
        taxon, //
        intSequence, //
        gapFlag, dataType);
        //			sequence.setDataType(dataType);
        simpleAlignment.addSequence(sequence);
        iterator.remove();
    }
    return simpleAlignment;
}
Also used : Entry(java.util.Map.Entry) SimpleAlignment(dr.evolution.alignment.SimpleAlignment) Taxon(dr.evolution.util.Taxon) Sequence(dr.evolution.sequence.Sequence) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class DataModelImporter method createAlignment.

private Map createAlignment(Alignment alignment) {
    Map a = new HashMap();
    a.put("id", (alignment.getId() != null ? alignment.getId() : "alignment"));
    List<Map> ss = new ArrayList<Map>();
    for (int i = 0; i < alignment.getSequenceCount(); i++) {
        Sequence sequence = alignment.getSequence(i);
        ss.add(createSequence(sequence));
    }
    a.put("sequences", ss);
    return a;
}
Also used : Sequence(dr.evolution.sequence.Sequence)

Example 15 with Sequence

use of dr.evolution.sequence.Sequence in project beast-mcmc by beast-dev.

the class PartitionParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    int from = 0;
    int to = -1;
    int every = xo.getAttribute(EVERY, 1);
    if (xo.hasAttribute(FROM)) {
        from = xo.getIntegerAttribute(FROM) - 1;
        if (from < 0) {
            throw new XMLParseException("Illegal 'from' attribute in patterns element");
        }
    }
    if (xo.hasAttribute(TO)) {
        to = xo.getIntegerAttribute(TO) - 1;
        if (to < 0 || to < from) {
            throw new XMLParseException("Illegal 'to' attribute in patterns element");
        }
    }
    if (every <= 0) {
        throw new XMLParseException("Illegal 'every' attribute in patterns element");
    }
    // END: every check
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    GammaSiteRateModel siteModel = (GammaSiteRateModel) xo.getChild(GammaSiteRateModel.class);
    FrequencyModel freqModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
    Sequence rootSequence = (Sequence) xo.getChild(Sequence.class);
    BranchRateModel rateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    if (rateModel == null) {
        rateModel = new DefaultBranchRateModel();
    }
    BranchModel branchModel = (BranchModel) xo.getChild(BranchModel.class);
    if (branchModel == null) {
        SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
        branchModel = new HomogeneousBranchModel(substitutionModel);
    }
    Partition partition = new Partition(tree, branchModel, siteModel, rateModel, freqModel, from, to, every);
    if (rootSequence != null) {
        partition.setRootSequence(rootSequence);
    }
    return partition;
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) TreeModel(dr.evomodel.tree.TreeModel) Partition(dr.app.beagle.tools.Partition) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) Sequence(dr.evolution.sequence.Sequence) XMLParseException(dr.xml.XMLParseException) BranchModel(dr.evomodel.branchmodel.BranchModel) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel)

Aggregations

Sequence (dr.evolution.sequence.Sequence)31 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)15 Taxon (dr.evolution.util.Taxon)12 DataType (dr.evolution.datatype.DataType)6 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)6 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)5 TreeModel (dr.evomodel.tree.TreeModel)5 Parameter (dr.inference.model.Parameter)5 Tree (dr.evolution.tree.Tree)4 Date (dr.evolution.util.Date)4 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)4 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)4 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)4 Partition (dr.app.beagle.tools.Partition)3 NewickImporter (dr.evolution.io.NewickImporter)3 HKY (dr.evomodel.substmodel.nucleotide.HKY)3 ArrayList (java.util.ArrayList)3 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)2 ImportException (dr.evolution.io.Importer.ImportException)2 Taxa (dr.evolution.util.Taxa)2