-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
190 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import sys | ||
import os | ||
parentScriptDir = "/".join(os.path.dirname( | ||
os.path.realpath(__file__)).split("/")[:-1]) | ||
sys.path.append(parentScriptDir+"/sourcepredictlib") | ||
|
||
print(sys.path) | ||
|
||
import ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import sys | ||
import os | ||
import pandas as pd | ||
import random | ||
|
||
parentScriptDir = "/".join(os.path.dirname( | ||
os.path.realpath(__file__)).split("/")[:-1]) | ||
sys.path.append(parentScriptDir+"/sourcepredictlib") | ||
random.seed(42) | ||
|
||
import ml | ||
import utils | ||
|
||
|
||
def test_sourceunknown_init(): | ||
|
||
PYTHONHASHSEED = 0 | ||
|
||
labels = os.path.dirname(os.path.abspath( | ||
__file__)) + '/../data/modern_gut_microbiomes_labels.csv' | ||
sources = os.path.dirname(os.path.abspath( | ||
__file__))+'/../data/modern_gut_microbiomes_sources.csv' | ||
sink_file = os.path.dirname(os.path.abspath( | ||
__file__))+'/../data/test/dog_test_sample.csv' | ||
sink = utils.split_sinks(sink_file)[0] | ||
|
||
su = ml.sourceunknown(source=sources, sink=sink, labels=labels) | ||
|
||
assert su.ref.shape == (5664, 432) | ||
assert su.y.shape == (432,) | ||
assert su.y_unk.shape == (432,) | ||
assert su.tmp_sink.shape == (570, 1) | ||
assert su.combined.shape == (5664, 433) | ||
assert hash(str(su.combined)) == -1867655657877779130 | ||
|
||
|
||
# def test_sourceunknown_add_unkown(): | ||
# PYTHONHASHSEED = 0 | ||
# labels = os.path.dirname(os.path.abspath( | ||
# __file__)) + '/../data/modern_gut_microbiomes_labels.csv' | ||
# sources = os.path.dirname(os.path.abspath( | ||
# __file__))+'/../data/modern_gut_microbiomes_sources.csv' | ||
# sink_file = os.path.dirname(os.path.abspath( | ||
# __file__))+'/../data/test/dog_test_sample.csv' | ||
# sink = utils.split_sinks(sink_file)[0] | ||
|
||
# su = ml.sourceunknown(source=sources, sink=sink, labels=labels) | ||
# su.add_unknown(alpha=0.1, seed=42) | ||
|
||
# assert su.ref_u.shape == (570, 144) | ||
# assert su.ref_u.dtypes == | ||
# assert hash(str(su.ref_u.columns)) == 5867343156924504419 | ||
# assert hash(str(su.ref_u.index)) == 4313932402357376923 | ||
# assert hash(str(su.ref_u_labs)) == -5906979299339891562 | ||
|
||
|
||
# def test_sourceunknown_normalized(): | ||
|
||
# labels = os.path.dirname(os.path.abspath( | ||
# __file__)) + '/data/modern_gut_microbiomes_labels.csv' | ||
# sources = os.path.dirname(os.path.abspath( | ||
# __file__))+'/data/modern_gut_microbiomes_sources.csv' | ||
# sink_file = os.path.dirname(os.path.abspath( | ||
# __file__))+'data/test/dog_test_sample.csv' | ||
# sink = utils.split_sinks(sink_file)[0] | ||
|
||
# su = ml.sourceunknown(source=sources, sink=sink, labels=labels) | ||
# su.add_unknown(alpha=0.1, seed=42) | ||
# su_rle = su.normalize(method='rle', threads=1) | ||
# su_subsample = su.normalize(method='subsample', threads=1) | ||
# su_gmpr = su.normalize(method='gmpr', threads=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import sys | ||
import os | ||
import numpy as np | ||
import pandas as pd | ||
|
||
parentScriptDir = "/".join(os.path.dirname( | ||
os.path.realpath(__file__)).split("/")[:-1]) | ||
sys.path.append(parentScriptDir+"/sourcepredictlib") | ||
|
||
import normalize | ||
|
||
|
||
def test_RLE(): | ||
""" | ||
Test RLE normalization | ||
""" | ||
|
||
input_df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) | ||
output_df = pd.DataFrame( | ||
[[1.0, 2.0, 2.0], [5.0, 5.0, 5.0], [9.0, 8.0, 7.0]]) | ||
|
||
assert normalize.RLE_normalize( | ||
input_df).all().all() == output_df.all().all() | ||
|
||
|
||
def test_subsample(): | ||
""" | ||
Test subsample normalization | ||
""" | ||
|
||
input_df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) | ||
output_df = pd.DataFrame( | ||
[[0.0, 0.0, 0.0], [4.0, 4.0, 4.0], [9.0, 9.0, 9.0]]) | ||
|
||
assert normalize.subsample_normalize_pd( | ||
input_df).all().all() == output_df.all().all() | ||
|
||
|
||
def test_gmpr_size_factor(): | ||
""" | ||
Test GMPR normalization size factor | ||
""" | ||
|
||
input_ar = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) | ||
output = 1.0137003325955667 | ||
assert normalize.gmpr_size_factor(col=1, ar=input_ar) == output | ||
|
||
|
||
def test_GMPR(): | ||
""" | ||
Test GMPR normalization | ||
""" | ||
|
||
input_df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) | ||
output_df = pd.DataFrame([[1.2331060371652351, 1.9729696594643762, 2.4662120743304703], | ||
[4.932424148660941, 4.932424148660941, | ||
4.932424148660941], | ||
[8.631742260156646, 7.891878637857505, 7.398636222991411]]) | ||
assert normalize.GMPR_normalize( | ||
input_df, 1).all().all() == output_df.all().all() | ||
assert normalize.GMPR_normalize( | ||
input_df, 2).all().all() == output_df.all().all() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import sys | ||
import os | ||
|
||
parentScriptDir = "/".join(os.path.dirname( | ||
os.path.realpath(__file__)).split("/")[:-1]) | ||
sys.path.append(parentScriptDir+"/sourcepredictlib") | ||
|
||
import utils | ||
|
||
|
||
def test_checks(): | ||
assert utils.check_norm('rle') == 'RLE' | ||
assert utils.check_embed('tsne') == 'TSNE' | ||
assert utils.check_distance('Weighted_unifrac') == 'weighted_unifrac' | ||
assert utils.check_gen_seed(42) == 42 | ||
assert type(utils.check_gen_seed(seed=None)) is int |