Esempio n. 1
0
/** Execute function */
RevPtr<RevVariable> Func_concatenate::execute( void )
{
    const AbstractHomologousDiscreteCharacterData& a = static_cast<const AbstractHomologousDiscreteCharacterData &>( args[0].getVariable()->getRevObject() );
    const AbstractHomologousDiscreteCharacterData& b = static_cast<const AbstractHomologousDiscreteCharacterData &>( args[1].getVariable()->getRevObject() );
    const std::string& type = static_cast<const RlString &>( args[2].getVariable()->getRevObject() ).getValue();

    AbstractHomologousDiscreteCharacterData* d = a.concatenate( b, type );
    for (size_t i = 3; i < args.size(); ++i)
    {
        const AbstractHomologousDiscreteCharacterData& c = static_cast<const AbstractHomologousDiscreteCharacterData &>( args[i].getVariable()->getRevObject() );
        
        AbstractHomologousDiscreteCharacterData* tmp = d->concatenate( c, type );
        delete d;
        
        d = tmp;
    }
    
    return new RevVariable( d );
}
Esempio n. 2
0
/**
 * This method simply writes a discrete character data object into a file in Nexus format.
 *
 * \param[in]   data        The discrete character data object which is written out.
 */
void NexusWriter::writeNexusBlock(const AbstractHomologousDiscreteCharacterData &data)
{
    // write initial lines of the character block
    outStream << std::endl;
    outStream << "Begin data;" << std::endl;
    outStream << "Dimensions ntax=" << data.getNumberOfIncludedTaxa() << " nchar=" << data.getNumberOfIncludedCharacters() << ";" << std::endl;
    outStream << "Format datatype=" << data.getDataType() << " ";
    if ( data.getDataType() == "Standard" )
    {
        outStream << "symbols=\"" << data.getTaxonData(0).getCharacter(0).getStateLabels() << "\" ";
    }
    outStream << "missing=? gap=-;" << std::endl;
    outStream << "Matrix" << std::endl;

    // get the taxon vector
    std::vector<Taxon> taxa = data.getTaxa();

    // sort the taxa (by name)
    std::sort(taxa.begin(), taxa.end());

    for (std::vector<Taxon>::const_iterator it = taxa.begin();  it != taxa.end(); ++it)
    {

        if ( !data.isTaxonExcluded( it->getName() ) )
        {
            outStream << it->getName() << "   ";
            const AbstractDiscreteTaxonData &taxon = data.getTaxonData( it->getName() );
            size_t nChars = taxon.getNumberOfCharacters();

            size_t count = 0;

            for (size_t i = 0; i < nChars; ++i)
            {
                if ( !data.isCharacterExcluded( i ) )
                {
                    const CharacterState &c = taxon.getCharacter( i );
                    outStream << c.getStringValue();
                    ++count;
                }
            }

            outStream << std::endl;
        }

    }

    outStream << ";" << std::endl;
    outStream << "End;" << std::endl;
    outStream << std::endl;

}
Esempio n. 3
0
/**
 * This method simply writes a character data object into a file in Fasta format.
 *
 * \param[in]   fileName    The name of the file into which the objects is to be written.
 * \param[in]   data        The character data object which is written out.
 */
void FastaWriter::writeData(std::string const &fileName, const AbstractHomologousDiscreteCharacterData &data)
{
    
    // the filestream object
    std::fstream outStream;
    
    RbFileManager f = RbFileManager(fileName);
    f.createDirectoryForFile();
    
    // open the stream to the file
    outStream.open( fileName.c_str(), std::fstream::out );
    
    const std::vector<Taxon> &taxa = data.getTaxa();
    for (std::vector<Taxon>::const_iterator it = taxa.begin();  it != taxa.end(); ++it)
    {

        if ( !data.isTaxonExcluded( it->getName() ) )
        {

            const AbstractDiscreteTaxonData &taxon = data.getTaxonData( it->getName() );

            outStream << ">" << it->getName() << std::endl;

            size_t nChars = taxon.getNumberOfCharacters();
            for (size_t i = 0; i < nChars; ++i)
            {
                if ( !data.isCharacterExcluded( i ) )
                {
                    const CharacterState &c = taxon.getCharacter( i );
                    outStream << c.getStringValue();
                }
            }
            outStream << std::endl;
        }
    }
    
    // close the stream
    outStream.close();
}