Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge tests #21

Merged
merged 21 commits into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added FIGURES/NetworkSummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added FIGURES/NetworkSummary_LowRes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion SCRIPTS/make_figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3382,7 +3382,7 @@ def network_summary_fig(corrmat_file, NodalMeasures_file, GlobalMeasures_file, R
ax = plt.Subplot(big_fig, grid[0])
big_fig.add_subplot(ax)

ax = plot_anatomical_network(G,
ax = plot_anatomical_network(G, # does this need to be here, if we abandon the edges do we need any information from G
NodalMeasures_file,
measure='module',
orientation='sagittal',
Expand Down
3 changes: 1 addition & 2 deletions SCRIPTS/make_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ def calculate_nodal_measures(G, centroids, aparc_names, nodal_partition=None, na
* 34_name (Desikan Killiany atlas region)
* 68_name (Desikan Killiany atlas region with hemisphere)
'''
#IS: Currently I'm having trouble with this. When network_analysis_from_corrmat tries to convert the output nodal_dict ino a dataframe it fails because inside the np.arrays we have dict_values objects. I am replacing np.array with list in all relevant instances. Hopefully this works. SUCCESS!

import numpy as np
import networkx as nx
Expand Down Expand Up @@ -679,7 +678,7 @@ def shortest_path(G):
shortestpl_dict = {}

for node in G.nodes():
shortestpl_dict[node] = np.average(list(shortestpl_dict_dict[node].values()))# IS: I've been getting an error here beause numpy functions do not take dict_values objects so I've put a list() around it.
shortestpl_dict[node] = np.average(list(shortestpl_dict_dict[node].values()))

return shortestpl_dict

Expand Down
6 changes: 4 additions & 2 deletions SCRIPTS/useful_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ def read_in_data(regional_measures_file, names_file, covars_file=None, names_308

# Load the input files
df = pd.read_csv(regional_measures_file)
names = [ line.strip() for line in open(names_file) ]
with open(names_file) as f:
names = [ line.strip() for line in f ]

if covars_file:
covars_list = [ line.strip() for line in open(covars_file) ]
with open(covars_file) as f:
covars_list = [ line.strip() for line in f ]
else:
covars_list = []

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Well caught 🙌

Expand Down
Empty file added TESTS/__init__.py
Empty file.
61 changes: 61 additions & 0 deletions TESTS/regression_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import unittest
import filecmp
import os

class FixturesTest(unittest.TestCase):

#------------------- setup and teardown ---------------------------
@classmethod
def setUpClass(cls):
print('\nin set up - this takes about 80 secs')
# We should have fixtures (generated by write_fixtures) saved
# in TESTS/test_fixtures. To set up we run write_fixtures again
# to generate new files in a temporary (/tmp) folder.
# Later we will test that these files are identical to the old
# ones
from write_fixtures import write_fixtures
write_fixtures('/tmp')
# define paths to individual files for checking, relative to
# the folder write_fixtures has saved in
cls.corrmat = '/corrmat_file.txt'
cls.gm = '/network-analysis/GlobalMeasures_corrmat_file_COST010.csv'
cls.lm = '/network-analysis/NodalMeasures_corrmat_file_COST010.csv'
cls.rich = '/network-analysis/RICH_CLUB_corrmat_file_COST010.csv'

@classmethod
def tearDownClass(cls):
import shutil
print('\nin tear down - deleting files')
# delete all files generated in setup
shutil.rmtree(os.getcwd()+'/tmp')

#--------------------------- Tests --------------------------------
# Each of these tests checks that ourly newly generated version of
# file_x matches the fixture version

def test_corrmat_matches_fixture(self):
# test new correlation matrix against fixture
print('\ntesting new correlation matrix against fixture')
self.assertTrue(filecmp.cmp(os.getcwd()+'/tmp'+self.corrmat,
os.getcwd()+'/TESTS/test_fixtures'+self.corrmat))

def test_gm_against_fixture(self):
# test new global measures against fixture
print('\ntesting new global measures against fixture')
self.assertTrue(filecmp.cmp(os.getcwd()+'/tmp'+self.gm,
os.getcwd()+'/TESTS/test_fixtures'+self.gm))

def test_lm_against_fixture(self):
# test new local measures against fixture
print('\ntesting new local measures against fixture')
self.assertTrue(filecmp.cmp(os.getcwd()+'/tmp'+self.lm,
os.getcwd()+'/TESTS/test_fixtures'+self.lm))

def test_rich_against_fixture(self):
# test rich club against fixture
print('\ntesting rich club against fixture')
self.assertTrue(filecmp.cmp(os.getcwd()+'/tmp'+self.rich,
os.getcwd()+'/TESTS/test_fixtures'+self.rich))

if __name__ == '__main__':
unittest.main()
308 changes: 308 additions & 0 deletions TESTS/test_fixtures/corrmat_file.txt

Large diffs are not rendered by default.

Binary file added TESTS/test_fixtures/figures/NetworkSummary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added TESTS/test_fixtures/figures/corrmat_picture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
,C,C_rand,E,E_rand,L,L_rand,M,M_rand,a,a_rand,sigma,sigma_rand
0,0.44501157500471683,0.2396872949320527,0.4304588561073706,0.48411062496129836,2.3985363171030922,2.0993273827150047,0.39148198969632453,0.1249772927086647,0.09839954481630904,-0.0700837697837918,1.6250254433756204,1.0
1,0.44501157500471683,0.2174227562868005,0.4304588561073706,0.4847265379086393,2.3985363171030922,2.095731629933584,0.39148198969632453,0.12731870848392296,0.09839954481630904,-0.07679807569425844,1.788363015246689,1.0
2,0.44501157500471683,0.22092106802269246,0.4304588561073706,0.48403281395004144,2.3985363171030922,2.0997927154278946,0.39148198969632453,0.13036605163106316,0.09839954481630904,-0.08266456062740023,1.7634546652489054,1.0
3,0.44501157500471683,0.21856495556002697,0.4304588561073706,0.48340967256640077,2.3985363171030922,2.1020982275053934,0.39148198969632453,0.12549473019465238,0.09839954481630904,-0.05266971271118482,1.7844216581434573,1.0
4,0.44501157500471683,0.2276831828667354,0.4304588561073706,0.4838304070463133,2.3985363171030922,2.1006599263928254,0.39148198969632453,0.13131361885790951,0.09839954481630904,-0.07657874897168201,1.7117873214190515,1.0
5,0.44501157500471683,0.22756787299188863,0.4304588561073706,0.4854780925985942,2.3985363171030922,2.092368543508609,0.39148198969632453,0.12797845829875495,0.09839954481630904,-0.09161575675817406,1.7058947815404288,1.0
6,0.44501157500471683,0.21978595203448484,0.4304588561073706,0.484643545098188,2.3985363171030922,2.0962604171073225,0.39148198969632453,0.13341693967455034,0.09839954481630904,-0.07528298446703349,1.7695804520474392,1.0
7,0.44501157500471683,0.22130242377743747,0.4304588561073706,0.4835040403042075,2.3985363171030922,2.1023308938618386,0.39148198969632453,0.13050373916136204,0.09839954481630904,-0.0667199522043918,1.7625437689454024,1.0
8,0.44501157500471683,0.21647140482862245,0.4304588561073706,0.48430800311722366,2.3985363171030922,2.0987139895934686,0.39148198969632453,0.12302424263054784,0.09839954481630904,-0.08673604011831655,1.7987786763522513,1.0
9,0.44501157500471683,0.22394406446908866,0.4304588561073706,0.48465418183949754,2.3985363171030922,2.0961335081856256,0.39148198969632453,0.128253340360523,0.09839954481630904,-0.07014799252576139,1.7366183795743748,1.0
Loading