44 #include <Bpp/Exceptions.h>    45 #include <Bpp/Text/TextTools.h>    46 #include <Bpp/Io/FileTools.h>    49 #include <Bpp/Seq/Alphabet/DNA.h>    50 #include <Bpp/Seq/Alphabet/AlphabetTools.h>    73   plist += (num / LWORD);
    74   *plist |= (1 << (num % LWORD));
    82   plist += (num / LWORD);
    83   *plist &=  ~(1 << (num % LWORD));
    90   for (
size_t i = 0; i < len; i++)
    92     listet[i] = list1[i] & list2[i];
   100   for (
size_t i = 0; i < len; i++)
   102     listou[i] = list1[i] | list2[i];
   110   for (
size_t i = 0; i < len; i++)
   112     listnon[i] = ~list[i];
   120   plist += (num / LWORD);
   121   return (*plist) & (1 << (num % LWORD));
   129   bool checkElements) 
throw (Exception)
   131   vector<int*> bitBipL1, bitBipL2, twoBitBipL;
   132   vector<string> elements;
   134   if (i1 >= bipartL1.getNumberOfBipartitions())
   135     throw Exception(
"Bipartition index exceeds BipartitionList size");
   136   if (i2 >= bipartL2.getNumberOfBipartitions())
   137     throw Exception(
"Bipartition index exceeds BipartitionList size");
   139   if (checkElements && !VectorTools::haveSameElements(bipartL1.getElementNames(), bipartL2.getElementNames()))
   140     throw Exception(
"Distinct bipartition element sets");
   145   if (bipartL1.isSorted())
   147     elements = bipartL1.getElementNames();
   148     bitBipL1 = bipartL1.getBitBipartitionList();
   152     BipartitionList provBipartL(bipartL1.getElementNames(), bipartL1.getBitBipartitionList());
   154     elements = provBipartL.getElementNames();
   155     bitBipL1 = provBipartL.getBitBipartitionList();
   158   if (bipartL2.isSorted())
   160     bitBipL2 = bipartL2.getBitBipartitionList();
   164     BipartitionList provBipartL(bipartL2.getElementNames(), bipartL2.getBitBipartitionList());
   166     bitBipL2 = provBipartL.getBitBipartitionList();
   171   twoBitBipL.push_back(bitBipL1[i1]);
   172   twoBitBipL.push_back(bitBipL2[i2]);
   184   BipartitionList* twoBipL = buildBipartitionPair(bipartL1, i1, bipartL2, i2, checkElements);
   197   BipartitionList* twoBipL = buildBipartitionPair(bipartL1, i1, bipartL2, i2, checkElements);
   206   const vector<BipartitionList*>& vecBipartL,
   207   bool checkElements) 
throw (Exception)
   209   vector<string> elements;
   210   vector<int*> mergedBitBipL;
   214   if (vecBipartL.size() == 0)
   215     throw Exception(
"Empty vector passed");
   219     for (
size_t i = 1; i < vecBipartL.size(); ++i)
   221       if (!VectorTools::haveSameElements(vecBipartL[0]->getElementNames(), vecBipartL[0]->getElementNames()))
   222         throw Exception(
"BipartitionTools::mergeBipartitionLists. Distinct bipartition element sets");
   227   size_t nbword = (vecBipartL[0]->getElementNames().size() + lword - 1) / lword;
   228   size_t nbint  = nbword * lword / (CHAR_BIT * 
sizeof(int));
   230   elements = vecBipartL[0]->getElementNames();
   231   if (!vecBipartL[0]->isSorted())
   232     std::sort(elements.begin(), elements.end());
   234   for (
size_t i = 0; i < vecBipartL.size(); i++)
   236     vector<int*> bitBipL;
   237     if (vecBipartL[i]->isSorted())
   239       bitBipL = vecBipartL[i]->getBitBipartitionList();
   245       BipartitionList provBipartL(vecBipartL[i]->getElementNames(), vecBipartL[i]->getBitBipartitionList());
   249     for (
size_t j = 0; j < bitBipL.size(); j++)
   251       provBitBip = 
new int[nbint];
   252       for (
size_t k = 0; k < nbint; k++)
   254         provBitBip[k] = bitBipL[j][k];
   256       mergedBitBipL.push_back(provBitBip);
   267   const vector<BipartitionList*>& vecBipartL) 
throw (Exception)
   269   vector<string> all_elements;
   270   map<string, bool> bip;
   271   vector<string> bip_elements;
   272   const DNA* alpha = &AlphabetTools::DNA_ALPHABET;
   273   vector<string> sequences;
   275   if (vecBipartL.size() == 0)
   276     throw Exception(
"Empty vector passed");
   278   vector< vector<string> > vecElementLists;
   279   for (
size_t i = 0; i < vecBipartL.size(); i++)
   281     vecElementLists.push_back(vecBipartL[i]->getElementNames());
   284   all_elements = VectorTools::vectorUnion(vecElementLists);
   286   sequences.resize(all_elements.size());
   288   for (
size_t i = 0; i < vecBipartL.size(); i++)
   290     for (
size_t j = 0; j < vecBipartL[i]->getNumberOfBipartitions(); j++)
   292       bip = vecBipartL[i]->getBipartition(j);
   293       bip_elements = MapTools::getKeys(bip);
   295       for (
size_t k = 0; k < all_elements.size(); k++)
   297         if (VectorTools::contains(bip_elements, all_elements[k]))
   299           if (bip[all_elements[k]])
   300             sequences[k].push_back(
'C');
   302             sequences[k].push_back(
'A');
   305           sequences[k].push_back(
'N');
   310   vector<const Sequence*> vec_sequences;
   311   for (
size_t i = 0; i < all_elements.size(); i++)
   313     const Sequence* seq = 
new BasicSequence(all_elements[i], sequences[i], alpha);
   314     vec_sequences.push_back(seq);
   317   VectorSequenceContainer vec_seq_cont(vec_sequences, alpha);
   318   for (
size_t i = 0; i < all_elements.size(); i++)
   320     delete vec_sequences[i];
   323   VectorSiteContainer* vec_site_cont = 
new VectorSiteContainer(vec_seq_cont);
   325   return vec_site_cont;
   331                                                  const vector<BipartitionList*>& vecBipartL) 
throw (Exception)
   333     vector<string> all_elements;
   334     map<string, bool> bip;
   335     vector<string> bip_elements;
   336     const DNA* alpha = &AlphabetTools::DNA_ALPHABET;
   337     vector<string> sequences;
   339     if (vecBipartL.size() == 0)
   340         throw Exception(
"Empty vector passed");
   342     vector< vector<string> > vecElementLists;
   343     for (
size_t i = 0; i < vecBipartL.size(); i++)
   345         vecElementLists.push_back(vecBipartL[i]->getElementNames());
   348     all_elements = VectorTools::vectorUnion(vecElementLists);
   350     sequences.resize(all_elements.size());
   352     for (
size_t i = 0; i < vecBipartL.size(); i++)
   354         for (
size_t j = 0; j < vecBipartL[i]->getNumberOfBipartitions(); j++)
   356             bip = vecBipartL[i]->getBipartition(j);
   357             bip_elements = MapTools::getKeys(bip);
   359             vector< string > zeroes;
   360             vector< string > ones;
   361             for (
size_t k = 0; k < all_elements.size(); k++)
   363                 if (VectorTools::contains(bip_elements, all_elements[k]))
   365                     if (bip[all_elements[k]])
   366                         ones.push_back(all_elements[k]);
   368                         zeroes.push_back(all_elements[k]);
   371             vector<string> inter = VectorTools::vectorIntersection(ones, zeroes);
   372             if (inter.size() != 0) { 
   373                 for (
size_t k = 0; k < all_elements.size(); k++)
   375                     sequences[k].push_back(
'N');
   380                 for (
size_t k = 0; k < all_elements.size(); k++)
   382                     if (VectorTools::contains(bip_elements, all_elements[k]))
   384                         if (bip[all_elements[k]])
   385                             sequences[k].push_back(
'C');
   387                             sequences[k].push_back(
'A');
   390                         sequences[k].push_back(
'N');
   396     vector<const Sequence*> vec_sequences;
   397     for (
size_t i = 0; i < all_elements.size(); i++)
   399         const Sequence* seq = 
new BasicSequence(all_elements[i], sequences[i], alpha);
   400         vec_sequences.push_back(seq);
   403     VectorSequenceContainer vec_seq_cont(vec_sequences, alpha);
   404     for (
size_t i = 0; i < all_elements.size(); i++)
   406         delete vec_sequences[i];
   409     VectorSiteContainer* vec_site_cont = 
new VectorSiteContainer(vec_seq_cont);
   411     return vec_site_cont;
 
bool areIdentical(size_t k1, size_t k2) const
bool areCompatible(size_t k1, size_t k2) const
Tells whether 2 bipartitions from the list are compatible. 
This class deals with the bipartitions defined by trees. 
const std::vector< int * > & getBitBipartitionList() const