00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef NCL_NXSMULTIFORMAT_H
00021 #define NCL_NXSMULTIFORMAT_H
00022 #include <iostream>
00023
00024 #include "ncl/nxsdefs.h"
00025 #include "ncl/nxspublicblocks.h"
00026 class FileToCharBuffer;
00038 class MultiFormatReader: public PublicNexusReader
00039 {
00040 public:
00046 enum DataFormatType
00047 {
00048 NEXUS_FORMAT,
00049 FASTA_DNA_FORMAT,
00050 FASTA_AA_FORMAT,
00051 FASTA_RNA_FORMAT,
00052 PHYLIP_DNA_FORMAT,
00053 PHYLIP_RNA_FORMAT,
00054 PHYLIP_AA_FORMAT,
00055 PHYLIP_DISC_FORMAT,
00056 INTERLEAVED_PHYLIP_DNA_FORMAT,
00057 INTERLEAVED_PHYLIP_RNA_FORMAT,
00058 INTERLEAVED_PHYLIP_AA_FORMAT,
00059 INTERLEAVED_PHYLIP_DISC_FORMAT,
00060 RELAXED_PHYLIP_DNA_FORMAT,
00061 RELAXED_PHYLIP_RNA_FORMAT,
00062 RELAXED_PHYLIP_AA_FORMAT,
00063 RELAXED_PHYLIP_DISC_FORMAT,
00064 INTERLEAVED_RELAXED_PHYLIP_DNA_FORMAT,
00065 INTERLEAVED_RELAXED_PHYLIP_RNA_FORMAT,
00066 INTERLEAVED_RELAXED_PHYLIP_AA_FORMAT,
00067 INTERLEAVED_RELAXED_PHYLIP_DISC_FORMAT,
00068 ALN_DNA_FORMAT,
00069 ALN_RNA_FORMAT,
00070 ALN_AA_FORMAT,
00071 PHYLIP_TREE_FORMAT,
00072 RELAXED_PHYLIP_TREE_FORMAT,
00073 NEXML_FORMAT,
00074 UNSUPPORTED_FORMAT
00075 };
00076
00082 static std::vector<std::string> getFormatNames();
00087 static DataFormatType formatNameToCode(const std::string &);
00088
00089
00097 MultiFormatReader(const int blocksToRead = -1, NxsReader::WarningHandlingMode mode=NxsReader::WARNINGS_TO_STDERR)
00098 :PublicNexusReader(blocksToRead, mode)
00099 {}
00100 virtual ~MultiFormatReader(){}
00105 void ReadStream(std::istream & inp, const char * formatName);
00110 void ReadStream(std::istream & inp, DataFormatType format, const char * filepath=0L);
00111
00116 void ReadFilepath(const char * filepath, const char * formatName);
00121 void ReadFilepath(const char * filepath, DataFormatType format);
00122
00127 void readFastaFile(std::istream & inf, NxsCharactersBlock::DataTypesEnum dt);
00128
00129 private:
00130 void addTaxaNames(const std::list<std::string> & taxaName, NxsTaxaBlockAPI * taxa);
00131 void moveDataToDataBlock(const std::list<std::string> & taxaNames, std::list<NxsDiscreteStateRow> & matList, const unsigned nchar, NxsDataBlock * dataB);
00132 void moveDataToMatrix(std::list<NxsDiscreteStateRow> & matList, NxsDiscreteStateMatrix &mat);
00133 void moveDataToUnalignedBlock(const std::list<std::string> & taxaNames, std::list<NxsDiscreteStateRow> & matList, NxsUnalignedBlock * uB);
00134 bool readFastaSequences(FileToCharBuffer & ftcb, const NxsDiscreteDatatypeMapper &dm, std::list<std::string> & taxaNames, std::list<NxsDiscreteStateRow> & matList, size_t & longest);
00135 void readPhylipFile(std::istream & inf, NxsCharactersBlock::DataTypesEnum dt, bool relaxedNames, bool interleaved);
00136 void readPhylipTreeFile(std::istream & inf, bool relaxedNames);
00137 void readAlnFile(std::istream & inf, NxsCharactersBlock::DataTypesEnum dt);
00138 bool readAlnData(FileToCharBuffer & ftcb, const NxsDiscreteDatatypeMapper &dm, std::list<std::string> & taxaNames, std::list<NxsDiscreteStateRow> & matList);
00139
00140 unsigned readPhylipHeader(std::istream & inf, unsigned & ntax, unsigned & nchar);
00141 void readPhylipData(FileToCharBuffer & ftcb, const NxsDiscreteDatatypeMapper &dm, std::list<std::string> & taxaNames, std::list<NxsDiscreteStateRow> & matList, const unsigned n_taxa, const unsigned n_char, bool relaxedNames);
00142 void readInterleavedPhylipData(FileToCharBuffer & ftcb, const NxsDiscreteDatatypeMapper &dm, std::list<std::string> & taxaNames, std::list<NxsDiscreteStateRow> & matList, const unsigned n_taxa, const unsigned n_char, bool relaxedNames);
00143 std::string readPhylipName(FileToCharBuffer & ftcb, unsigned i, bool relaxedNames);
00144
00145
00146 };
00147
00236 #endif
00237