bpp-seq  2.2.0
BppOAlphabetIndex2Format.cpp
Go to the documentation of this file.
1 //
2 // File: BppOAlphabetIndex2Format.cpp
3 // Created by: Julien Dutheil
4 // Created on: Thursday Februar 07th, 19:26
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
42 #include "../Alphabet/AlphabetTools.h"
43 #include "../AlphabetIndex/BLOSUM50.h"
44 #include "../AlphabetIndex/GranthamAAChemicalDistance.h"
45 #include "../AlphabetIndex/MiyataAAChemicalDistance.h"
46 #include "../AlphabetIndex/SimpleIndexDistance.h"
47 #include "../AlphabetIndex/AAIndex2Entry.h"
48 #include "../AlphabetIndex/AlphabetIndex1.h"
49 
50 #include <Bpp/Text/KeyvalTools.h>
51 #include <Bpp/App/ApplicationTools.h>
52 
53 #include <string>
54 #include <memory>
55 
56 using namespace bpp;
57 using namespace std;
58 
59 AlphabetIndex2* BppOAlphabetIndex2Format::read(const std::string& description) throw (Exception)
60 {
61  if (description != "None")
62  {
63  string name;
64  map<string, string> args;
65  KeyvalTools::parseProcedure(description, name, args);
66  if (verbose_)
67  ApplicationTools::displayResult(message_, description);
68 
69  //Currently, only protein indices are supported:
70  if (!AlphabetTools::isProteicAlphabet(alphabet_))
71  throw Exception("BppOAlphabetIndex2Format::read. This index is only supported with a protein alphabet.");
72  if (name == "Blosum50")
73  {
74  return new BLOSUM50();
75  }
76  else if (name == "Grantham")
77  {
78  bool sym = ApplicationTools::getBooleanParameter("symmetrical", args, true, "", true, 1);
80  M->setSymmetric(sym);
81  if (!sym) M->setPC1Sign(true);
82  return M;
83  }
84  else if (name == "Miyata")
85  {
86  bool sym = ApplicationTools::getBooleanParameter("symmetrical", args, true, "", true, 1);
88  M->setSymmetric(sym);
89  return M;
90  }
91  else if (name == "Diff")
92  {
93  string index1Desc = ApplicationTools::getStringParameter("index1", args, "None", "", true, 1);
94  bool sym = ApplicationTools::getBooleanParameter("symmetrical", args, true, "", true);
95  BppOAlphabetIndex1Format index1Reader(alphabet_, "" , false);
96  AlphabetIndex1* index1 = index1Reader.read(index1Desc);
97  if (index1) {
99  M->setSymmetric(sym);
100  return M;
101  } else {
102  throw Exception("BppOAlphabetIndex2Format::read. Diff: index1 should be provided.");
103  }
104  }
105  else if (name == "User")
106  {
107  bool sym = ApplicationTools::getBooleanParameter("symmetrical", args, true, "", true, 1);
108  string aax2FilePath = ApplicationTools::getAFilePath("file", args, true, true, "", false);
109  ifstream aax2File(aax2FilePath.c_str(), ios::in);
110  AAIndex2Entry* M = new AAIndex2Entry(aax2File, sym);
111  aax2File.close();
112  return M;
113  }
114  else
115  {
116  throw Exception("Invalid index2 '" + name + "'.");
117  }
118  }
119  else
120  {
121  return 0;
122  }
123 }
124 
This alphabet is used to deal NumericAlphabet.
STL namespace.
AlphabetIndex1 I/O in BppO format.
Miyata et al. (1979) Amino-Acid chemical distance.
Grantham (1974) Amino-Acid chemical distance.
One dimensionnal alphabet index interface.
Create a AlphabetIndex2 object from an AAIndex2 entry.
Definition: AAIndex2Entry.h:52
AlphabetIndex2 * read(const std::string &description)
Read a AlphabetIndex1 object from a string.
Two dimensionnal alphabet index interface.
Simple dissimilarity distance.
AlphabetIndex1 * read(const std::string &description)
Read a AlphabetIndex1 object from a string.
BLOSUM 50 Substitution Matrix.
Definition: BLOSUM50.h:64
static bool isProteicAlphabet(const Alphabet *alphabet)
void setPC1Sign(bool yn)
The sign of the distance is computed using the coordinate on the first axis of a principal component ...