[Phylobase-commits] r743 - in pkg/src: . ncl

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Mar 3 21:31:03 CET 2010


Author: francois
Date: 2010-03-03 21:31:03 +0100 (Wed, 03 Mar 2010)
New Revision: 743

Modified:
   pkg/src/NCLInterface.cpp
   pkg/src/NCLInterface.h
   pkg/src/ReadWithNCL.cpp
   pkg/src/ncl/nxsreader.h
   pkg/src/nxscharactersblock.cpp
   pkg/src/nxspublicblocks.cpp
   pkg/src/nxsreader.cpp
Log:
updated ncl interface (code written by Mark Holder)

Modified: pkg/src/NCLInterface.cpp
===================================================================
--- pkg/src/NCLInterface.cpp	2010-02-28 05:40:26 UTC (rev 742)
+++ pkg/src/NCLInterface.cpp	2010-03-03 20:31:03 UTC (rev 743)
@@ -17,15 +17,591 @@
 //	GNU General Public License for more details.
 //
 //	You should have received a copy of the GNU General Public License
-//	along with NCL; if not, write to the Free Software Foundation, Inc., 
+//	along with NCL; if not, write to the Free Software Foundation, Inc.,
 //	59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 //
 
 #include <ncl/ncl.h>
 #include "NCLInterface.h"
+
+#include <iostream>
 #include <sstream>
 #include <cassert>
 
+
+
+std::string BASICCMDLINE::TestRunning() {
+	string output="The NCL has been loaded";
+	return output;
+}
+
+#if defined(NEW_NCL_INTERFACE)
+
+MultiFormatReader * instantiateReader(int gStrictLevel);
+
+
+
+void BASICCMDLINE::AppendRContent(
+  NxsString & nexuscharacters,
+  NxsCharactersBlock &characters,
+  bool allchar,
+  bool polymorphictomissing,
+  bool levelsall) const
+{
+
+	int nchartoreturn = 0;
+	NxsTaxaBlockAPI * taxa = characters.GetTaxaBlockPtr();
+	if (!taxa)
+		return;
+	int ntax = taxa->GetNumTaxonLabels();
+
+	if (!characters.IsEmpty())
+		{
+		//characters.Report(cerr);
+		if (1==characters.GetDataType()) { //standard datatype
+		//if((characters.GetDatatypeName())=="standard") {
+			//nexuscharacters=characters.GetDatatypeName();
+			nexuscharacters+="data.frame(";
+
+			if (allchar) {
+				nchartoreturn=characters.GetNCharTotal();
+			}
+			else {
+				nchartoreturn=characters.GetNChar();
+			}
+			for (int character=0; character<nchartoreturn; character++) { //We only pass the non-eliminated chars
+				NxsString charlabel=characters.GetCharLabel(character);
+				if (character>0) {
+					nexuscharacters+=", ";
+				}
+				if (charlabel.length()>1) {
+					nexuscharacters+="'";
+					nexuscharacters+=charlabel;
+					nexuscharacters+="'";
+				}
+				else {
+					nexuscharacters+="standard_char_";
+					nexuscharacters+=character+1;
+				}
+				nexuscharacters+=" = ";
+
+				nexuscharacters+="factor(c(";
+				for (int taxon=0;taxon<ntax;taxon++) {
+					int statenumber=characters.GetInternalRepresentation(taxon,character,0);
+
+					if(characters.IsMissingState(taxon,character)) {
+						nexuscharacters+="NA";
+					}
+					else if (characters.GetNumStates(taxon,character)>1) {
+						if(polymorphictomissing) {
+							nexuscharacters+="NA";
+						}
+						else {
+							nexuscharacters+='{';
+							for (unsigned int k=0;k<characters.GetNumStates(taxon,character);k++) {
+								nexuscharacters+=characters.GetInternalRepresentation(taxon,character,0);
+								if (k+1<characters.GetNumStates(taxon,character)) {
+									nexuscharacters+=',';
+								}
+							}
+							nexuscharacters+='}';
+						}
+					}
+					else {
+						nexuscharacters+=statenumber;
+					}
+					if (taxon+1<ntax) {
+						nexuscharacters+=',';
+					}
+				}
+				nexuscharacters+=')';
+				if (levelsall) {
+					nexuscharacters+=", levels=c(";
+					for (unsigned int l=0;l<characters.GetMaxObsNumStates(); l++) {
+						nexuscharacters+=l;
+						if (l+1<characters.GetMaxObsNumStates()) {
+							nexuscharacters+=',';
+						}
+					}
+					nexuscharacters+=')';
+				}
+				else {
+
+					NxsString levels=", levels=c(";
+					NxsString labels=", labels=c(";
+					unsigned int totallabellength=0;
+					for (unsigned int l=0;l<characters.GetObsNumStates(character); l++) {
+						labels+='"';
+						labels+= characters.GetStateLabel(character,l);
+						totallabellength+=(characters.GetStateLabel(character,l)).length();
+						labels+='"';
+						levels+= l;
+						if (l+1<characters.GetObsNumStates(character)) {
+							labels+=',';
+							levels+=',';
+						}
+					}
+					levels+=')';
+					labels+=')';
+					//cout<<"labels.length="<<labels.length()<<endl<<"levels.length="<<levels.length()<<endl<<"total label length="<<totallabellength<<endl;
+					if (totallabellength>characters.GetObsNumStates(character)) {
+						nexuscharacters+=levels;
+						nexuscharacters+=labels;
+					}
+				}
+				nexuscharacters+=")\n";
+			}
+			nexuscharacters+=", row.names=c(";
+			for (int taxon=0;taxon<ntax;taxon++) {
+				nexuscharacters+='"';
+				nexuscharacters+=RemoveUnderscoresAndSpaces(characters.GetTaxonLabel(taxon));
+				nexuscharacters+='"';
+				if (taxon+1<ntax) {
+					nexuscharacters+=',';
+				}
+			}
+			nexuscharacters+="))";
+		}
+		else if (2==characters.GetDataType() || 3==characters.GetDataType() || 4==characters.GetDataType()) { //dna, rna, nucleotide
+	//	if((characters.GetDatatypeName())=="dna") {
+
+			nexuscharacters+="data.frame(";
+			if (2==characters.GetDataType()) {
+				nexuscharacters+="dna_alignment_1=c(";
+			}
+			else if (3==characters.GetDataType()) {
+				nexuscharacters+="rna_alignment_1=c(";
+			}
+			else {
+				nexuscharacters+="nucleotide_alignment_1=c(";
+			}
+
+			if (allchar) {
+				nchartoreturn=characters.GetNCharTotal();
+			}
+			else {
+				nchartoreturn=characters.GetNChar();
+			}
+			for (int taxon=0;taxon<ntax;taxon++) {
+				nexuscharacters+='"';
+				for (int character=0; character<nchartoreturn; character++) {
+					int numstates=characters.GetNumStates(taxon,character);
+					if (characters.IsGapState(taxon,character)) {
+						nexuscharacters+="-";
+					}
+					else if (characters.IsMissingState(taxon,character)) {
+						nexuscharacters+="?";
+					}
+					else if ( numstates == 1) {
+						nexuscharacters+=characters.GetState(taxon,character,0);
+					}
+					else {
+						bool hasA=false;
+						bool hasT=false;
+						bool hasG=false;
+						bool hasC=false;
+						for (int i=0;i<numstates;i++) {
+							unsigned currentstate=characters.GetState(taxon,character,i);
+							if (currentstate=='A') {
+								hasA=true;
+							}
+							else if (currentstate=='T') {
+								hasT=true;
+							}
+							else if (currentstate=='G') {
+								hasG=true;
+							}
+							else if (currentstate=='C') {
+								hasC=true;
+							}
+							else {
+								cout<<"Error: currentstate "<<currentstate<<" does not match ATGC"<<endl;
+							}
+						}
+						if (hasA && hasG && !hasT && !hasC) {
+							nexuscharacters+="R";
+						}
+						else if (!hasA && !hasG && hasC && hasT) {
+							nexuscharacters+="Y";
+						}
+						else if (hasA && !hasG && hasC && !hasT) {
+							nexuscharacters+="M";
+						}
+						else if (!hasA && hasG && !hasC && hasT) {
+							nexuscharacters+="K";
+						}
+						else if (!hasA && hasG && hasC && !hasT) {
+							nexuscharacters+="S";
+						}
+						else if (hasA && !hasG && !hasC && hasT) {
+							nexuscharacters+="W";
+						}
+						else if (hasA && !hasG && hasC && hasT) {
+							nexuscharacters+="H";
+						}
+						else if (!hasA && hasG && hasC && hasT) {
+							nexuscharacters+="B";
+						}
+						else if (hasA && hasG && hasC && !hasT) {
+							nexuscharacters+="V";
+						}
+						else if (hasA && hasG && !hasC && hasT) {
+							nexuscharacters+="D";
+						}
+						else if (hasA && hasG && hasC && hasT) {
+							nexuscharacters+="N";
+						}
+						else {
+							nexuscharacters+="N";
+						}
+					}
+				}
+				nexuscharacters+='"';
+				if (taxon+1<ntax) {
+					nexuscharacters+=',';
+				}
+			}
+
+			nexuscharacters+="), row.names=c(";
+			for (int taxon=0;taxon<ntax;taxon++) {
+				nexuscharacters+='"';
+				nexuscharacters+=RemoveUnderscoresAndSpaces(characters.GetTaxonLabel(taxon));
+				nexuscharacters+='"';
+				if (taxon+1<ntax) {
+					nexuscharacters+=',';
+				}
+			}
+			nexuscharacters+="), stringsAsFactors=FALSE)";
+
+		}
+		else if (5==characters.GetDataType()) { //protein
+			nexuscharacters+="data.frame(";
+			nexuscharacters+="aa_alignment_1=c(";
+
+
+			if (allchar) {
+				nchartoreturn=characters.GetNCharTotal();
+			}
+			else {
+				nchartoreturn=characters.GetNChar();
+			}
+			for (int taxon=0;taxon<ntax;taxon++) {
+				nexuscharacters+='"';
+				for (int character=0; character<nchartoreturn; character++) {
+					int numstates=characters.GetNumStates(taxon,character);
+					if (characters.IsGapState(taxon,character)) {
+						nexuscharacters+="-";
+					}
+					else if (characters.IsMissingState(taxon,character)) {
+						nexuscharacters+="?";
+					}
+					else if ( numstates == 1) {
+						nexuscharacters+=characters.GetState(taxon,character,0);
+					}
+					else {
+						nexuscharacters+="X";
+					}
+				}
+				nexuscharacters+='"';
+				if (taxon+1<ntax) {
+					nexuscharacters+=',';
+				}
+			}
+
+			nexuscharacters+="), row.names=c(";
+			for (int taxon=0;taxon<ntax;taxon++) {
+				nexuscharacters+='"';
+				nexuscharacters+=RemoveUnderscoresAndSpaces(characters.GetTaxonLabel(taxon));
+				nexuscharacters+='"';
+				if (taxon+1<ntax) {
+					nexuscharacters+=',';
+				}
+			}
+			nexuscharacters+="), stringsAsFactors=FALSE)";
+		}
+		else if (6==characters.GetDataType()) { //continuousnexuscharacters+="data.frame(";
+			nexuscharacters+="data.frame(";
+
+			if (allchar) {
+				nchartoreturn=characters.GetNCharTotal();
+			}
+			else {
+				nchartoreturn=characters.GetNChar();
+			}
+			for (int character=0; character<nchartoreturn; character++) { //We only pass the non-eliminated chars
+				NxsString charlabel=characters.GetCharLabel(character);
+				if (character>0) {
+					nexuscharacters+=", ";
+				}
+				if (charlabel.length()>1) {
+					nexuscharacters+="'";
+					nexuscharacters+=charlabel;
+					nexuscharacters+="'";
+				}
+				else {
+					nexuscharacters+="continuous_char_";
+					nexuscharacters+=character+1;
+				}
+				nexuscharacters+=" = ";
+
+				nexuscharacters+="c(";
+				for (int taxon=0;taxon<ntax;taxon++) {
+					double state=characters.GetSimpleContinuousValue(taxon,character);
+					//cout<<"State at "<<taxon+1<<" char "<<character+1<<" = "<<state<<endl;
+					if (state==DBL_MAX) {
+							nexuscharacters+="NA";
+					}
+					else {
+						nexuscharacters+=state;
+					}
+
+					if (taxon+1<ntax) {
+						nexuscharacters+=',';
+					}
+				}
+				nexuscharacters+=")";
+			}
+			nexuscharacters+=", row.names=c(";
+			for (int taxon=0;taxon<ntax;taxon++) {
+				nexuscharacters+='"';
+				nexuscharacters+=RemoveUnderscoresAndSpaces(characters.GetTaxonLabel(taxon));
+				nexuscharacters+='"';
+				if (taxon+1<ntax) {
+					nexuscharacters+=',';
+				}
+			}
+			nexuscharacters+="))";
+			//message="Warning: Continuous characters do not work";
+			//PrintMessage();
+		}
+		else {
+			std::string message="Error: character matrix loaded, but does not match any category (dna, standard, etc.)";
+			errorMessage(message);
+		}
+		nexuscharacters=RemoveUnderscoresAndSpaces(nexuscharacters);
+	}
+
+}
+
+void BASICCMDLINE::AppendRContent(
+  NxsString & nexustrees,
+  NxsTreesBlock &treesB) const
+{
+	NxsTaxaBlockAPI * taxa = treesB.GetTaxaBlockPtr();
+	if (!taxa)
+		return;
+	if (!treesB.IsEmpty())
+	{
+
+		nexustrees+= "\nBEGIN TREES;\n";
+		for (unsigned k = 0; k < treesB.GetNumTrees(); k++)
+		{
+			NxsString s = treesB.GetTreeName(k);
+			s.BlanksToUnderscores();
+			nexustrees+="\tTREE ";
+			nexustrees+=s;
+			nexustrees+=" = ";
+			if (treesB.IsRootedTree(k))
+				nexustrees+="[&R]";
+			else
+				nexustrees+="[&U]";
+			nexustrees+=treesB.GetTranslatedTreeDescription(k);
+			nexustrees+=";\n";
+		}
+		nexustrees+="END;\n";
+	}
+}
+
+void BASICCMDLINE::AppendRContent(
+  NxsString & nexusdistances,
+  NxsDistancesBlock &distancesB) const
+{
+	NxsTaxaBlockAPI * taxa = distancesB.GetTaxaBlockPtr();
+	if (!taxa)
+		return;
+	int ntax = taxa->GetNumTaxonLabels();
+
+	if (!distancesB.IsEmpty())
+	{ //fill cols first, first col has taxon 1, first row has taxon 2 (no diags)
+		nexusdistances+="\ndistances <- structure(c(";
+		vector<double> distancevector;
+		for (int col=0;col<ntax-1;col++) {
+			for (int row=col+1;row<ntax;row++) {
+				distancevector.push_back(distancesB.GetDistance(row,col));
+			}
+		}
+		for (unsigned int i=0;i<distancevector.size();i++) {
+			nexusdistances+=distancevector.at(i);
+			if (i+1<distancevector.size()) {
+				nexusdistances+=',';
+			}
+		}
+		nexusdistances+="), Size = ";
+		nexusdistances+=ntax;
+		nexusdistances+="L, Labels = c(";
+		for (int taxon=0; taxon<ntax;taxon++) {
+			nexusdistances+='"';
+			nexusdistances+=RemoveUnderscoresAndSpaces(taxa->GetTaxonLabel(taxon));
+			nexusdistances+='"';
+			if (taxon+1<ntax) {
+				nexusdistances+=", ";
+			}
+		}
+		nexusdistances+="), Upper = FALSE, Diag = FALSE, class = \"dist\")\n";
+	}
+}
+
+
+void BASICCMDLINE::RReturnCharacters(NxsString & outputstring, bool allchar, bool polymorphictomissing, bool levelsall)
+{
+	if (!nexusReader)
+		return;
+	const unsigned nTaxaBlocks = nexusReader->GetNumTaxaBlocks();
+	for (unsigned t = 0; t < nTaxaBlocks; ++t) {
+		const NxsTaxaBlock * tb = nexusReader->GetTaxaBlock(t);
+		const unsigned nCharBlocks = nexusReader->GetNumCharactersBlocks(tb);
+		if (nCharBlocks == 0)
+			continue;
+		for (unsigned i = 0; i < nCharBlocks; ++i) {
+			NxsCharactersBlock * cb = nexusReader->GetCharactersBlock(tb, i);
+			if (cb) {
+				AppendRContent(outputstring, *cb, allchar, polymorphictomissing, levelsall);
+			}
+		}
+	}
+}
+
+
+void BASICCMDLINE::RReturnTrees(NxsString & outputstring)
+{
+	if (!nexusReader)
+		return;
+	const unsigned nTaxaBlocks = nexusReader->GetNumTaxaBlocks();
+	for (unsigned t = 0; t < nTaxaBlocks; ++t) {
+		const NxsTaxaBlock * tb = nexusReader->GetTaxaBlock(t);
+		const unsigned nTreesBlocks = nexusReader->GetNumTreesBlocks(tb);
+		if (nTreesBlocks == 0)
+			continue;
+		for (unsigned i = 0; i < nTreesBlocks; ++i) {
+			NxsTreesBlock * treesb = nexusReader->GetTreesBlock(tb, i);
+			if (treesb) {
+				AppendRContent(outputstring, *treesb);
+			}
+		}
+	}
+}
+
+void BASICCMDLINE::RReturnDistances(NxsString & outputstring)
+{
+	if (!nexusReader)
+		return;
+	const unsigned nTaxaBlocks = nexusReader->GetNumTaxaBlocks();
+	for (unsigned t = 0; t < nTaxaBlocks; ++t) {
+		const NxsTaxaBlock * tb = nexusReader->GetTaxaBlock(t);
+		const unsigned nDistancesBlocks = nexusReader->GetNumDistancesBlocks(tb);
+		if (nDistancesBlocks == 0)
+			continue;
+		for (unsigned i = 0; i < nDistancesBlocks; ++i) {
+			NxsDistancesBlock * distancesb = nexusReader->GetDistancesBlock(tb, i);
+			if (distancesb) {
+				AppendRContent(outputstring, *distancesb);
+			}
+		}
+	}
+}
+
+
+
+void BASICCMDLINE::writeMessage(MessageLevel level, const std::string & m)  const {
+	if (level >= int(this->verboseLevel)) {
+		std::cerr << m << std::endl;
+	}
+}
+
+
+MultiFormatReader * instantiateReader(int gStrictLevel)
+{
+	MultiFormatReader * nexusReader = new MultiFormatReader(-1, NxsReader::WARNINGS_TO_STDERR);
+
+
+	if (gStrictLevel != 2)
+		nexusReader->SetWarningToErrorThreshold((int)NxsReader::FATAL_WARNING + 1 - (int) gStrictLevel);
+	NxsCharactersBlock * charsB = nexusReader->GetCharactersBlockTemplate();
+	NxsDataBlock * dataB = nexusReader->GetDataBlockTemplate();
+	charsB->SetAllowAugmentingOfSequenceSymbols(true);
+	dataB->SetAllowAugmentingOfSequenceSymbols(true);
+
+	NxsTreesBlock * treesB = nexusReader->GetTreesBlockTemplate();
+	assert(treesB);
+	if (gStrictLevel < 2)
+		treesB->SetAllowImplicitNames(true);
+	if (gStrictLevel < 2)
+		{
+		NxsStoreTokensBlockReader *storerB =  nexusReader->GetUnknownBlockTemplate();
+		assert(storerB);
+		storerB->SetTolerateEOFInBlock(true);
+		}
+	nexusReader->conversionOutputRecord.addNumbersToDisambiguateNames = true;
+	return nexusReader;
+}
+
+
+void BASICCMDLINE::Clear()
+{
+	if (nexusReader) {
+		MultiFormatReader * nr = nexusReader;
+		nexusReader = 0L;
+		try {
+			nr->DeleteBlocksFromFactories();
+		}
+		catch (...) {
+			delete nr;
+			throw;
+		}
+		delete nr;
+	}
+
+}
+
+
+
+////////////////////////////////////////////////////////////////////////////////
+// Creates a NxsReader, and tries to read the file `filename`.  If the
+//	read succeeds, then processContent will be called.
+////////////////////////////////////////////////////////////////////////////////
+void BASICCMDLINE::processFilepath(const char * filename) // enum indicating the file format to expect.
+{
+	if (! (this->nexusReader)) {
+		nexusReader = instantiateReader(this->gStrictLevel);
+	}
+
+	nexusReader->SetWarningOutputLevel(this->warningLevel);
+
+	std::string m("Reading ");
+	if (filename)
+		m.append(filename);
+	this->statusMessage(m);
+
+	nexusReader->ReadFilepath(filename, fmt);
+
+	m.assign("Finished reading ");
+	if (filename)
+		m.append(filename);
+	statusMessage(m);
+
+
+}
+
+
+
+
+
+
+
+#else // #if defined(NEW_NCL_INTERFACE)
+
+
+
 /*----------------------------------------------------------------------------------------------------------------------
  |	The constructor simply passes along `i' to the base class constructor. Nothing else needs to be done.
  */
@@ -47,14 +623,14 @@
 }
 
 /*----------------------------------------------------------------------------------------------------------------------
- |	Initializes the `id' data member to "BASICCMDLINE" and calls the FactoryDefaults member function to perform the 
+ |	Initializes the `id' data member to "BASICCMDLINE" and calls the FactoryDefaults member function to perform the
  |	remaining initializations. The data member `'' is set to NULL so that memory will be allocated for it in
  |	FactoryDefaults.
  */
 BASICCMDLINE::BASICCMDLINE()
 {
 	id				= "BASICCMDLINE";
-	
+
 	// Make sure all data members that are pointers are initialized to NULL!
 	// Failure to do this will result in problems because functions such as
 	// FactoryDefaults() will try to delete an object if it is non-NULL.
@@ -66,8 +642,24 @@
 	characters		= NULL;
 	data			= NULL;
 	next_command	= NULL;
-	
+
 	FactoryDefaults();
+
+	taxa			= new NxsTaxaBlock();
+	trees			= new NxsTreesBlock(taxa);
+	assumptions		= new NxsAssumptionsBlock(taxa);
+	characters		= new NxsCharactersBlock(taxa, assumptions);
+	distances		= new NxsDistancesBlock(taxa);
+	data			= new NxsDataBlock(taxa, assumptions);
+
+	Add(taxa);
+	Add(trees);
+	Add(assumptions);
+	Add(characters);
+	Add(distances);
+	Add(data);
+	Add(this);
+
 }
 
 /*----------------------------------------------------------------------------------------------------------------------
@@ -77,17 +669,17 @@
 {
 	assert(next_command != NULL);
 	delete [] next_command;
-	
+
 	if (logf_open)
 		logf.close();
 }
 
 /*----------------------------------------------------------------------------------------------------------------------
- |	The code here is identical to the base class version (simply returns 0), so the code here should either be 
- |	modified or this derived version eliminated altogether. Under what circumstances would you need to modify the 
- |	default code, you ask? This function should be modified to something meaningful if this derived class needs to 
- |	construct and run a NxsSetReader object to read a set involving characters. The NxsSetReader object may need to 
- |	use this function to look up a character label encountered in the set. A class that overrides this method should 
+ |	The code here is identical to the base class version (simply returns 0), so the code here should either be
+ |	modified or this derived version eliminated altogether. Under what circumstances would you need to modify the
+ |	default code, you ask? This function should be modified to something meaningful if this derived class needs to
+ |	construct and run a NxsSetReader object to read a set involving characters. The NxsSetReader object may need to
+ |	use this function to look up a character label encountered in the set. A class that overrides this method should
  |	return the character index in the range [1..`nchar']; i.e., add one to the 0-offset index.
  */
 unsigned BASICCMDLINE::CharLabelToNumber(
@@ -97,10 +689,10 @@
 }
 
 /*----------------------------------------------------------------------------------------------------------------------
- |	Called by the NxsReader object when a block named `blockName' is entered. Allows program to notify user of 
- |	progress in parsing the NEXUS file. Also gives program the opportunity to ask user if it is ok to purge data 
- |	currently contained in this block. If user is asked whether existing data should be deleted, and the answer comes 
- |	back no, then then return false, otherwise return true. Overrides pure virtual function in class NxsReader. 
+ |	Called by the NxsReader object when a block named `blockName' is entered. Allows program to notify user of
+ |	progress in parsing the NEXUS file. Also gives program the opportunity to ask user if it is ok to purge data
+ |	currently contained in this block. If user is asked whether existing data should be deleted, and the answer comes
+ |	back no, then then return false, otherwise return true. Overrides pure virtual function in class NxsReader.
  */
 bool BASICCMDLINE::EnteringBlock(
 								 NxsString blockName)	/* the name of the block just entered */
@@ -109,12 +701,12 @@
 	message += blockName;
 	message += " block...";
 	PrintMessage();
-	
+
 	return true;
 }
 
 /*----------------------------------------------------------------------------------------------------------------------
- |	Called by the NxsReader object when exiting a block named `blockName'. Allows program to notify user of progress 
+ |	Called by the NxsReader object when exiting a block named `blockName'. Allows program to notify user of progress
  |	in parsing the NEXUS file. Virtual function that overrides the pure virtual function in the base class NxsReader.
  */
 void BASICCMDLINE::ExitingBlock(
@@ -123,9 +715,9 @@
 }
 
 /*----------------------------------------------------------------------------------------------------------------------
- |	Sets all data members to their factory default settings: `inf_open', `logf_open' and `quit_now' are set to false; 
- |	`message' to the null string, and the pointers `data', `characters', `assumptions', `taxa' and `trees' 
- |	are all set to NULL. The C-string `next_command' is allocated COMMAND_MAXLEN + 1 bytes if it is currently NULL, 
+ |	Sets all data members to their factory default settings: `inf_open', `logf_open' and `quit_now' are set to false;
+ |	`message' to the null string, and the pointers `data', `characters', `assumptions', `taxa' and `trees'
+ |	are all set to NULL. The C-string `next_command' is allocated COMMAND_MAXLEN + 1 bytes if it is currently NULL,
  |	and its first byte is set to the null character to create an empty `next_command' string.
  */
 void BASICCMDLINE::FactoryDefaults()
@@ -135,49 +727,49 @@
 	logf_open = false;
 	quit_now = false;
 	message.clear();
-	
+
 	if (trees != NULL)
 	{
 		Detach(trees);
 		delete trees;
 		trees = NULL;
 	}
-	
+
 	if (taxa != NULL)
 	{
 		Detach(taxa);
 		delete taxa;
 		taxa = NULL;
 	}
-	
+
 	if (assumptions != NULL)
 	{
 		Detach(assumptions);
 		delete assumptions;
 		assumptions = NULL;
 	}
-	
+
 	if (distances != NULL)
 	{
 		Detach(distances);
 		delete distances;
 		distances = NULL;
 	}
-	
+
 	if (characters != NULL)
 	{
 		Detach(characters);
 		delete characters;
 		characters = NULL;
 	}
-	
+
 	if (data != NULL)
 	{
 		Detach(data);
 		delete data;
 		data = NULL;
 	}
-	
+
 	if (next_command == NULL)
 		next_command = new char[COMMAND_MAXLEN + 1];
 	next_command[0] = '\0';
@@ -190,25 +782,25 @@
 							  const char *fn)	/* the name of the file to check */
 {
 	bool exists = false;
-	
+
 	FILE *fp = fopen(fn, "r");
 	if (fp != NULL)
 	{
 		fclose(fp);
 		exists = true;
 	}
-	
+
 	return exists;
 }
 
 /*----------------------------------------------------------------------------------------------------------------------
- |	Called whenever a file name needs to be read from either the command line or a file. Expects next token to be "=" 
- |	followed by the token representing the file name. Call this function after, say, the keyword "file" has been read 
+ |	Called whenever a file name needs to be read from either the command line or a file. Expects next token to be "="
+ |	followed by the token representing the file name. Call this function after, say, the keyword "file" has been read
  |	in the following LOG command:
  |>
  |	log file=doofus.txt start replace;
  |>
- |	Note that this function will read only the "=doofus.txt " leaving "start replace;" in the stream for reading at 
+ |	Note that this function will read only the "=doofus.txt " leaving "start replace;" in the stream for reading at
  |	a later time.
  */
 NxsString BASICCMDLINE::GetFileName(
@@ -217,7 +809,7 @@
 	// Eat the equals sign
 	//
 	token.GetNextToken();
-	
+
 	if (!token.Equals("="))
 	{
 		errormsg = "Expecting an equals sign, but found ";
@@ -225,11 +817,11 @@
 		errormsg += " instead";
 		throw NxsException(errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn());
 	}
-	
+
 	// Now get the filename itself
 	//
 	token.GetNextToken();
-	
+
 	return token.GetToken();
 }
 
@@ -240,7 +832,7 @@
 	//
 	NxsString null=ReturnDataForR(false, true, false);
 	token.GetNextToken();
-	
+
 	if (!token.Equals(";"))
 	{
 		errormsg = "Expecting ';' to terminate the RETURNDATA command, but found ";
@@ -251,64 +843,17 @@
 }
 
 void BASICCMDLINE::RReturnCharacters(NxsString & nexuscharacters, bool allchar, bool polymorphictomissing, bool levelsall) {
-/*	if (!taxa->IsEmpty())
-	{
-		cerr << "\n  TAXA block found" << endl;
-		taxa->Report(cerr);
-		if (logf_open)
-			taxa->Report(logf);
-	}
-	
-	if (!trees->IsEmpty())
-	{
-		cerr << "\n  TREES block found" << endl;
-		trees->Report(cerr);
-		if (logf_open)
-			trees->Report(logf);
-	}
-	
-	if (!assumptions->IsEmpty())
-	{
-		cerr << "\n  ASSUMPTIONS block found" << endl;
-		assumptions->Report(cerr);
-		if (logf_open)
-			assumptions->Report(logf);
-	}
-	
-	if (!distances->IsEmpty())
-	{
-		cerr << "\n  DISTANCES block found" << endl;
-		distances->Report(cerr);
-		if (logf_open)
-			distances->Report(logf);
-	}
-	
-	if (!characters->IsEmpty())
-	{
-		cerr << "\n  CHARACTERS block found" << endl;
-		characters->Report(cerr);
-		if (logf_open)
-			characters->Report(logf);
-	}
-	
-	if (!data->IsEmpty())
-	{
-		cerr << "\n  DATA block found" << endl;
-		data->Report(cerr);
-		if (logf_open)
-			data->Report(logf);
-	}*/
-	
+
 	int nchartoreturn=0;
-	int ntax = taxa->GetNumTaxonLabels(); 
+	int ntax = taxa->GetNumTaxonLabels();
 	if (!characters->IsEmpty())
 	{
 		//characters->Report(cerr);
 		if (1==characters->GetDataType()) { //standard datatype
-		//if((characters->GetDatatypeName())=="standard") { 
+		//if((characters->GetDatatypeName())=="standard") {
 			//nexuscharacters=characters->GetDatatypeName();
 			nexuscharacters+="data.frame(";
-			
+
 			if (allchar) {
 				nchartoreturn=characters->GetNCharTotal();
 			}
@@ -330,11 +875,11 @@
 					nexuscharacters+=character+1;
 				}
 				nexuscharacters+=" = ";
-				
+
 				nexuscharacters+="factor(c(";
 				for (int taxon=0;taxon<ntax;taxon++) {
 					int statenumber=characters->GetInternalRepresentation(taxon,character,0);
-					
+
 					if(characters->IsMissingState(taxon,character)) {
 						nexuscharacters+="NA";
 					}
@@ -372,7 +917,7 @@
 					nexuscharacters+=')';
 				}
 				else {
-					
+
 					NxsString levels=", levels=c(";
 					NxsString labels=", labels=c(";
 					unsigned int totallabellength=0;
@@ -409,7 +954,7 @@
 			nexuscharacters+="))";
 		}
 		else if (2==characters->GetDataType() || 3==characters->GetDataType() || 4==characters->GetDataType()) { //dna, rna, nucleotide
-	//	if((characters->GetDatatypeName())=="dna") { 
+	//	if((characters->GetDatatypeName())=="dna") {
 
 			nexuscharacters+="data.frame(";
 			if (2==characters->GetDataType()) {
@@ -421,7 +966,7 @@
 			else {
 				nexuscharacters+="nucleotide_alignment_1=c(";
 			}
-			
+
 			if (allchar) {
 				nchartoreturn=characters->GetNCharTotal();
 			}
@@ -430,7 +975,7 @@
 			}
 			for (int taxon=0;taxon<ntax;taxon++) {
 				nexuscharacters+='"';
-				for (int character=0; character<nchartoreturn; character++) { 
+				for (int character=0; character<nchartoreturn; character++) {
 					int numstates=characters->GetNumStates(taxon,character);
 					if (characters->IsGapState(taxon,character)) {
 						nexuscharacters+="-";
@@ -518,13 +1063,13 @@
 				}
 			}
 			nexuscharacters+="), stringsAsFactors=FALSE)";
-			
+
 		}
 		else if (5==characters->GetDataType()) { //protein
 			nexuscharacters+="data.frame(";
 			nexuscharacters+="aa_alignment_1=c(";
-			
-			
+
+
 			if (allchar) {
 				nchartoreturn=characters->GetNCharTotal();
 			}
@@ -533,7 +1078,7 @@
 			}
 			for (int taxon=0;taxon<ntax;taxon++) {
 				nexuscharacters+='"';
-				for (int character=0; character<nchartoreturn; character++) { 
+				for (int character=0; character<nchartoreturn; character++) {
 					int numstates=characters->GetNumStates(taxon,character);
 					if (characters->IsGapState(taxon,character)) {
 						nexuscharacters+="-";
@@ -553,7 +1098,7 @@
 					nexuscharacters+=',';
 				}
 			}
-			
+
 			nexuscharacters+="), row.names=c(";
 			for (int taxon=0;taxon<ntax;taxon++) {
 				nexuscharacters+='"';
@@ -589,7 +1134,7 @@
 					nexuscharacters+=character+1;
 				}
 				nexuscharacters+=" = ";
-				
+
 				nexuscharacters+="c(";
 				for (int taxon=0;taxon<ntax;taxon++) {
 					double state=characters->GetSimpleContinuousValue(taxon,character);
@@ -600,7 +1145,7 @@
 					else {
 						nexuscharacters+=state;
 					}
-					
+
 					if (taxon+1<ntax) {
 						nexuscharacters+=',';
 					}
@@ -619,7 +1164,7 @@
 			nexuscharacters+="))";
 			//message="Warning: Continuous characters do not work";
 			//PrintMessage();
-		} 
+		}
 		else {
 				message="Error: character matrix loaded, but does not match any category (dna, standard, etc.)";
 			PrintMessage();
@@ -629,59 +1174,9 @@
 }
 
 void BASICCMDLINE::RReturnTrees(NxsString & nexustrees) {
-/*	if (!taxa->IsEmpty())
-	{
-		cerr << "\n  TAXA block found" << endl;
-		taxa->Report(cerr);
-		if (logf_open)
-			taxa->Report(logf);
-	}
-	
 	if (!trees->IsEmpty())
 	{
-		cerr << "\n  TREES block found" << endl;
-		trees->Report(cerr);
-		if (logf_open)
-			trees->Report(logf);
-	}
-	
-	if (!assumptions->IsEmpty())
-	{
-		cerr << "\n  ASSUMPTIONS block found" << endl;
-		assumptions->Report(cerr);
-		if (logf_open)
-			assumptions->Report(logf);
-	}
-	
-	if (!distances->IsEmpty())
-	{
-		cerr << "\n  DISTANCES block found" << endl;
-		distances->Report(cerr);
-		if (logf_open)
-			distances->Report(logf);
-	}
-	
-	if (!characters->IsEmpty())
-	{
-		cerr << "\n  CHARACTERS block found" << endl;
-		characters->Report(cerr);
-		if (logf_open)
-			characters->Report(logf);
-	}
-	
-	if (!data->IsEmpty())
-	{
-		cerr << "\n  DATA block found" << endl;
-		data->Report(cerr);
-		if (logf_open)
-			data->Report(logf);
-	}
-	*/
-        // int ntax = taxa->GetNumTaxonLabels(); 
 
-	if (!trees->IsEmpty())
-	{
-		
 		nexustrees+= "\nBEGIN TREES;\n";
 		for (unsigned k = 0; k < trees->GetNumTrees(); k++)
 		{
@@ -699,59 +1194,11 @@
 		}
 		nexustrees+="END;\n";
 	}
-	
+
 }
 
 void BASICCMDLINE::RReturnDistances(NxsString  & nexusdistances) {
-/*	if (!taxa->IsEmpty())
-	{
-		cerr << "\n  TAXA block found" << endl;
-		taxa->Report(cerr);
-		if (logf_open)
-			taxa->Report(logf);
-	}
-	
-	if (!trees->IsEmpty())
-	{
-		cerr << "\n  TREES block found" << endl;
-		trees->Report(cerr);
-		if (logf_open)
-			trees->Report(logf);
-	}
-	
-	if (!assumptions->IsEmpty())
-	{
-		cerr << "\n  ASSUMPTIONS block found" << endl;
-		assumptions->Report(cerr);
-		if (logf_open)
-			assumptions->Report(logf);
-	}
-	
-	if (!distances->IsEmpty())
-	{
-		cerr << "\n  DISTANCES block found" << endl;
-		distances->Report(cerr);
-		if (logf_open)
-			distances->Report(logf);
-	}
-	
-	if (!characters->IsEmpty())
-	{
-		cerr << "\n  CHARACTERS block found" << endl;
-		characters->Report(cerr);
-		if (logf_open)
-			characters->Report(logf);
-	}
-	
-	if (!data->IsEmpty())
-	{
-		cerr << "\n  DATA block found" << endl;
-		data->Report(cerr);
-		if (logf_open)
-			data->Report(logf);
-	}*/
-	
-	int ntax = taxa->GetNumTaxonLabels(); 
+	int ntax = taxa->GetNumTaxonLabels();
 
 	if (!distances->IsEmpty())
 	{ //fill cols first, first col has taxon 1, first row has taxon 2 (no diags)
@@ -783,11 +1230,6 @@
 	}
 }
 
-string BASICCMDLINE::TestRunning() {
-	string output="The NCL has been loaded";
-	return output;
-}
-
 //Break into separate functions,Input is string reference rather than return string
 NxsString BASICCMDLINE::ReturnDataForR(bool allchar, bool polymorphictomissing, bool levelsall) {
 	//allchar: return even eliminated characters if true
@@ -802,13 +1244,13 @@
 	//Make a data frame of all this
 	//Give the data frame to R
 	int nchartoreturn=0;
-	int ntax = taxa->GetNumTaxonLabels(); 
+	int ntax = taxa->GetNumTaxonLabels();
 	NxsString outputforR = "";
 	if (!characters->IsEmpty())
 	{
 		outputforR+=characters->GetDatatypeName();
 		outputforR+=" <- data.frame(taxa=c(";
-		
+
 		for (int taxon=0;taxon<ntax;taxon++) {
 			outputforR+='"';
 			outputforR+=RemoveUnderscoresAndSpaces(characters->GetTaxonLabel(taxon));
@@ -837,11 +1279,11 @@
 				outputforR+=character+1;
 			}
 			outputforR+=" = ";
-			
+
 			outputforR+="factor(c(";
 			for (int taxon=0;taxon<ntax;taxon++) {
 				int statenumber=characters->GetInternalRepresentation(taxon,character,0);
-				
+
 				if(characters->IsMissingState(taxon,character)) {
 					outputforR+="<NA>";
 				}
@@ -879,10 +1321,10 @@
 				outputforR+=')';
 			}
 			else {
-				
+
 				NxsString levels=", levels=c(";
 				NxsString labels=", labels=c(";
-				
+
 				for (unsigned int l=0;l<characters->GetObsNumStates(character); l++) {
 					labels+= characters->GetStateLabel(character,l);
 					levels+= l;
@@ -905,10 +1347,10 @@
 	if (!taxa->IsEmpty())
 	{
 	}
-	
+
 	if (!trees->IsEmpty())
 	{
-		
+
 		outputforR+= "\nBEGIN TREES;\n";
 		for (unsigned k = 0; k < trees->GetNumTrees(); k++)
 		{
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/phylobase -r 743


More information about the Phylobase-commits mailing list