-
Notifications
You must be signed in to change notification settings - Fork 16
/
test_process_fingerprint.py
71 lines (59 loc) · 2.76 KB
/
test_process_fingerprint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# ----------------------------------------------------------------------------
# Copyright (c) 2016-2018, QIIME 2 development team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
from unittest import TestCase, main
from biom import load_table
import pandas as pd
import os
import pkg_resources
import qiime2
from q2_qemistree import CSIDirFmt
from q2_qemistree._process_fingerprint import (collate_fingerprint,
get_feature_smiles)
data = pkg_resources.resource_filename('q2_qemistree', 'data')
class FingerprintTests(TestCase):
def setUp(self):
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
self.featureTable = os.path.join(THIS_DIR,
'data/features_formated.biom')
self.emptycsi = os.path.join(os.path.join(THIS_DIR,
'data/emptycsi'))
self.goodcsi = qiime2.Artifact.load(os.path.join(THIS_DIR,
'data/csiFolder.qza'))
properties_path = os.path.join(data, 'molecular_properties.csv')
self.properties = pd.read_csv(properties_path, dtype=str, sep='\t')
self.properties.set_index('absoluteIndex', inplace=True)
def test_fingerprintOut(self):
msg = "Fingerprint file is empty!"
with self.assertRaisesRegex(ValueError, msg):
collate_fingerprint(self.emptycsi)
def test_featureMatch1(self):
goodcsi = self.goodcsi.view(CSIDirFmt)
tablefp = collate_fingerprint(goodcsi)
features = load_table(self.featureTable)
allfeatrs = set(features.ids(axis='observation'))
fpfeatrs = set(tablefp.index)
self.assertEqual(fpfeatrs <= allfeatrs, True)
def test_featureMatch2(self):
goodcsi = self.goodcsi.view(CSIDirFmt)
tablefp = collate_fingerprint(goodcsi)
smiles = get_feature_smiles(goodcsi, tablefp)
fpfeatrs = set(tablefp.index)
smlfeatrs = set(smiles.index)
self.assertEqual(fpfeatrs == smlfeatrs, True)
def test_pubchemTrue(self):
goodcsi = self.goodcsi.view(CSIDirFmt)
tablefp = collate_fingerprint(goodcsi, qc_properties=True)
indx = self.properties.loc[self.properties.type == 'PUBCHEM'].index
self.assertEqual(set(tablefp.columns) == set(indx), True)
def test_pubchemFalse(self):
goodcsi = self.goodcsi.view(CSIDirFmt)
tablefp = collate_fingerprint(goodcsi)
indx = self.properties.index
self.assertEqual(set(tablefp.columns) == set(indx), True)
if __name__ == '__main__':
main()