All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lphy.base.function.io.WriteFasta Maven / Gradle / Ivy

Go to download

The standard library of LPhy, which contains the required generative distributions and basic functions.

The newest version!
package lphy.base.function.io;

import lphy.base.evolution.alignment.Alignment;
import lphy.base.evolution.alignment.FastaAlignment;
import lphy.core.model.DeterministicFunction;
import lphy.core.model.Value;
import lphy.core.model.annotation.GeneratorCategory;
import lphy.core.model.annotation.GeneratorInfo;
import lphy.core.model.annotation.ParameterInfo;

public class WriteFasta extends DeterministicFunction {


    public WriteFasta(@ParameterInfo(name = ReaderConst.ALIGNMENT,
                              description = "the lphy alignment that is written into the fasta file.")
                      Value alignmentValue ) {


        if (alignmentValue == null) throw new IllegalArgumentException("The alignment can't be null!");
        setParam(ReaderConst.ALIGNMENT, alignmentValue);
    }


    @GeneratorInfo(name="fasta", verbClause = "can be saved as a fasta format into", narrativeName = "file",
            category = GeneratorCategory.TAXA_ALIGNMENT, examples = {"jcc2Fasta.lphy"},
            description = "A function that returns an alignment which can be saved as a fasta file later " +
                    "using lphy studio or slphy.")
    public Value apply() {

        Alignment alignment = ((Value) getParams().get(ReaderConst.ALIGNMENT)).value();

        // this only creates taxa and nchar
        FastaAlignment faData = new FastaAlignment(alignment.nchar(), alignment);

        // fill in states
        for (int i=0; i < alignment.ntaxa(); i++) {
            for (int j = 0; j < alignment.nchar(); j++) {
                faData.setState(i, j, alignment.getState(i, j));
            }
        }

        return new Value<>(null, faData, this);

    }



}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy