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

Writing network_measures to structure #61

Closed
JohannesWiesner opened this issue Jun 30, 2021 · 6 comments
Closed

Writing network_measures to structure #61

JohannesWiesner opened this issue Jun 30, 2021 · 6 comments

Comments

@JohannesWiesner
Copy link

I stumbled upon this thread on google groups because I am facing the same problem. It would be nice if network measures could be exported in a structured form (.mat, .json, etc.). Since the question is already 3 years I wonder if this has been implemented in the meantime?

@frankyeh
Copy link
Owner

frankyeh commented Jun 30, 2021 via email

@JohannesWiesner
Copy link
Author

No worries! :) I just wanted to make sure that I haven't overseen something :) Alright, I will write a python script then to parse the *network_measures.txt into a python dictionary or .json file

@JohannesWiesner
Copy link
Author

Just for completeness - here's my code (could probably be optimized but does what it is supposed to do):

def isFloat(string):
    try:
        float(string)
        return True
    except ValueError:
        return False

with open('571144.src.gz.hcp1065.qsdr.1.25.R73.fib.gz.tt.gz.HCP-MMP.ncount.end.network_measures.txt') as f:
    network_measures = [e.split() for e in f.readlines()]
    network_measures = {l[0]:l[1:] for l in network_measures}

    for k,l in network_measures.items():
        if len(l) == 1:
            network_measures[k] = float(l[0])
        elif len(l) > 1:
            network_measures[k] = [float(e) if isFloat(e) else e for e in l]

@frankyeh
Copy link
Owner

frankyeh commented Jun 30, 2021 via email

@mattcieslak
Copy link
Contributor

If this would be helpful, here is the function used in qsiprep: https://github.com/PennLINC/qsiprep/blob/master/qsiprep/interfaces/dsi_studio.py#L427

@frankyeh
Copy link
Owner

frankyeh commented Jun 30, 2021 via email

@frankyeh frankyeh closed this as completed Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants