Test reading and storing data

To test the new Data class, replace the contents of main.cpp with the following:

#include <iostream>
#include "data.hpp"
#include "node.hpp"
#include "tree.hpp"
#include "tree_manip.hpp"

using namespace strom;

int main(int argc, const char * argv[])
    {
    std::cout << "Starting..." << std::endl;

    // Test Tree, Node, and TreeManip classes
    TreeManip tm;
    std::string newick = std::string("(1:0.3,2:0.3,(3:0.2,(4:0.1,5:0.1):0.1):0.1)");
    tm.buildFromNewick(newick, false, false);
    std::cout << tm.makeNewick(3) << std::endl;

    std::cout << std::endl;

    // Test Data class
    Data d;
    d.getDataFromFile("rbcL.nex");
    std::cout << "Number of taxa:     " << d.getNumTaxa() << std::endl;
    std::cout << "Sequence length:    " << d.getSeqLen() << std::endl;
    std::cout << "Number of patterns: " << d.getNumPatterns() << std::endl;

    std::cout << "\nFinished!" << std::endl;

    return 0;
    }

Before running it, however, you will need to create the file rbcL.nex. This file does not need to be in your project, so you can use any text editor to create it (e.g. TextWrangler on the Mac or NotePad++ on Windows). Here is a Nexus-formatted data file containing 60 sites from the large subunit of the gene encoding the enzyme RuBisCO (rbcL):

#NEXUS

Begin data;
    Dimensions ntax=14 nchar=60;
    Format datatype=dna gap=-;
    Matrix
        Atractomorpha_echinata          CCTGATTATGTTGTAAGAGACACTGATATTCTTGCTGCTTTCCGTATGACTCCTCAACCA
        Bracteacoccus_aerius            CCAGATTACGTAGTTAAAGATACTGATATTTTAGCTGCATTCCGTATGACTCCACAACCA
        Bracteacoccus_minor             CCAGATTACCTAGTTAAAGATACTGACATTTTATCTGCATTCCGTATGACTCCACAACCA
        Chlorotetraedron_incus          CCTGATTACGTTATCAAAGATACTGATATTTTAGCAGCATTCCGTATGACTCCACAACCA
        Chromochloris_zofingiensis      CCTGATTACGTAGTTAAAGATACAGATATTTTAGCAGCTTTCCGTATGACTCCTCAACCA
        Kirchneriella_aperta            CCTGATTACGTAGTAAGAGAGACTGACATCTTAGCTGCATTCCGTATGACTCCACAACCA
        Mychonastes_homosphaera         CCAGATTACGTTGTTAAAGATACTGACATCTTAGCAGCATTCCGTATGACTCCACAACCA
        Neochloris_aquatica             CCAGATTATGTTGTAAAAGATACTGATATTTTAGCTGCATTCCGTATGACTCCTCAACCA
        Ourococcus_multisporus          CCTGATTACGTTGTAAAAGATACTGATATTTTAGCTGCATTCCGTATGACTCCACAACCA
        Pediastrum_duplex               CCAGATTATGTTGTAAAAGATACTGATATTTTAGCTGCATTCCGTATGACTCCTCAACCA
        Pseudomuriella_schumacherensis  CCTGATTACGTAGTAAAAGAAACAGACATTCTAGCTGCATTCCGTATGACTCCTCAACCA
        Rotundella_rotunda              CCAGATTACGTTGTAAAAGAAACTGATATTTTAGCAGCATTCCGTATGACTCCTCAACCA
        Scenedesmus_obliquus            CCANATTACGTTGTAAAAGATACTGATATTTTAGCAGCATTCCGTATGACTCCACAACCA
        Stigeoclonium_helveticum        CCAGATTATATGGTTAAAGATACTGATATTCTTGCTGCTTTCCGTATGACTCCTCAACCT
    ;
end;

If using Visual Studio on Windows…

Right-clicking the strom solution in the Solution Explorer pane, choosing Properties, then Debugging, and finally looking at Working Directory reveals that a program started running in the debugger will use $(ProjectDir) as its working directory. The directory pointed to by $(ProjectDir) is the directory in which the project file strom.vcxproj resides. This is therefore the directory in which you should create the rbcL.nex file. Or, if you’ve already created rbcL.nex, move it into the project directory before running the program.

If using Xcode on a Mac…

If you are using Xcode on a Mac, you will need to specify the working directory used when the program is run in the debugger. At the top of the Xcode IDE, to the right of the square button that stops execution of the program when it is running, there is a button labeled strom (just left of a button labeled My Mac). Click the strom button and choose Edit Scheme… from the popup menu that appears. Under Run > Options, check the Use custom working directory checkbox and specify the directory containing the rbcL.nex file you just created. Press the Close button when finished.

Finding the current working directory

If running the program reveals that the rbcL.nex is not being found, you can get the program to tell you its current working directory by placing the following additional line inside the Data constructor function:

std::cout << "Current working directory: " << boost::filesystem::current_path() << std::endl;

To use the current_path function, you will need to include the boost/filesystem/operations.hpp header at the top of the data.hpp file:

#include <boost/filesystem/operations.hpp>

Expected output

In the middle of the output you should see these three lines, indicating that there were 14 taxa, 60 sites, and 23 unique data patterns found in the rbcL.nex file:

Number of taxa:     14
Sequence length:    60
Number of patterns: 23

The output should also include 2 lines indicating that a Data object was created and a Data object was destroyed.