comparison src/breadcrumbs/src/Ordination.py @ 0:0de566f21448 draft default tip

v2
author sagun98
date Thu, 03 Jun 2021 18:13:32 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0de566f21448
1 """
2 Author: Timothy Tickle
3 Description: Base class for ordination plots.
4 """
5
6 #####################################################################################
7 #Copyright (C) <2012>
8 #
9 #Permission is hereby granted, free of charge, to any person obtaining a copy of
10 #this software and associated documentation files (the "Software"), to deal in the
11 #Software without restriction, including without limitation the rights to use, copy,
12 #modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
13 #and to permit persons to whom the Software is furnished to do so, subject to
14 #the following conditions:
15 #
16 #The above copyright notice and this permission notice shall be included in all copies
17 #or substantial portions of the Software.
18 #
19 #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
20 #INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
21 #PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 #HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 #SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #####################################################################################
26
27 __author__ = "Timothy Tickle"
28 __copyright__ = "Copyright 2013"
29 __credits__ = ["Timothy Tickle"]
30 __license__ = "MIT"
31 __maintainer__ = "Timothy Tickle"
32 __email__ = "ttickle@sph.harvard.edu"
33 __status__ = "Development"
34
35 #External libraries
36 import AbundanceTable
37 from ConstantsFiguresBreadCrumbs import ConstantsFiguresBreadCrumbs
38 import matplotlib.cm as cm
39 from matplotlib import pyplot as plt
40 from UtilityMath import UtilityMath
41 from ValidateData import ValidateData
42
43 class Ordination:
44 """
45 Base class for ordination methods and plots.
46 """
47
48 def __init__(self):
49 # Rows = Samples
50 self.dataMatrix = None
51 self.isRawData = None
52 self.lsIDs = []
53 self.dataProcessed = None
54
55 #Happy path tested
56 def loadData(self, xData, fIsRawData):
57 """
58 Loads data into the object (given a matrix or an abundance table)
59 Data can be the Abundance Table to be converted to a distance matrix or a distance matrix
60 If it is the AbundanceTable, indicate that it is rawData (tempIsRawData=True)
61 If it is the distance matrix already generated indicate (tempIsRawData=False)
62 and no conversion will occur in subsequent methods.
63
64 :params xData: AbundanceTable or Distance matrix . Taxa (columns) by samples (rows)(lists)
65 :type: AbundanceTable or DistanceMatrix
66 :param fIsRawData: Indicates if the xData is an AbudanceTable (True) or distance matrix (False; numpy array)
67 :type: boolean
68 :return boolean: indicator of success (True=Was able to load data)
69 """
70
71 if fIsRawData:
72 #Read in the file data to a numpy array.
73 #Samples (column) by Taxa (rows)(lists) without the column
74 data = xData.funcToArray()
75 if data==None:
76 print("Ordination:loadData::Error when converting AbundanceTable to Array, did not perform ordination.")
77 return False
78
79 #Transpose data to be Taxa (columns) by samples (rows)(lists)
80 data = UtilityMath.funcTransposeDataMatrix(data,fRemoveAdornments=False)
81 if(ValidateData.funcIsFalse(data)):
82 print("Ordination:loadData::Error when transposing data file, did not perform ordination.")
83 return False
84 else:
85 self.dataMatrix=data
86 self.isRawData=fIsRawData
87 self.lsIDs=xData.funcGetMetadata(xData.funcGetIDMetadataName())
88
89 #Otherwise load the data directly as passed.
90 else:
91 self.dataMatrix=xData
92 self.isRawData=fIsRawData
93 return True
94