From f4df578cdeff737f4f70a46c0c3c1bb55e37d9eb Mon Sep 17 00:00:00 2001
From: Marmaduke Woodman <marmaduke.woodman@univ-amu.fr>
Date: Fri, 7 Feb 2020 11:07:44 +0100
Subject: [PATCH] initial idea of freesurfer analyzer, lacks adapter

I want to start adding funcitonality
---
 .../tvb/analyzers/freesurfer.py               | 21 +++++++++++++++++++
 scientific_library/tvb/datatypes/volumes.py   | 18 ++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 scientific_library/tvb/analyzers/freesurfer.py

diff --git a/scientific_library/tvb/analyzers/freesurfer.py b/scientific_library/tvb/analyzers/freesurfer.py
new file mode 100644
index 000000000..09b3debea
--- /dev/null
+++ b/scientific_library/tvb/analyzers/freesurfer.py
@@ -0,0 +1,21 @@
+import os.path
+import subprocess
+from tvb.datatypes.volumes import Volume, VolumeInFile, FreeSurferSubject
+from tvb.basic.neotraits.api import HasTraits, Attr
+
+class FreeSurferRun(HasTraits):
+    input_T1 = Volume(label="Input T1.")
+    def evaluate(self):
+        vol: VolumeInFile = VolumeInFile.from_volume(self.input_T1)
+        path = vol.file_path
+        tmp_dir = '/tmp/tvb-fs'
+        cmd = 'freesurfer -i {} -all -s {}'
+        proc = subprocess.Popen(
+            cmd.format(path, 'tvb').split(),
+            env={'SUBJECTS_DIR': tmp_dir},
+            stderr=subprocess.STDIN,
+            stdin=subprocess.PIPE,
+        )
+        proc.wait()
+        return FreeSurferSubject(
+            subject_folder=os.path.join(tmp_dir, 'tvb'))
\ No newline at end of file
diff --git a/scientific_library/tvb/datatypes/volumes.py b/scientific_library/tvb/datatypes/volumes.py
index fa7e189b6..01b6e8287 100644
--- a/scientific_library/tvb/datatypes/volumes.py
+++ b/scientific_library/tvb/datatypes/volumes.py
@@ -53,3 +53,21 @@ class Volume(HasTraits):
             "Voxel size": self.voxel_size,
             "Units": self.voxel_unit
         }
+
+
+class VolumeInFile(Volume):
+    """
+    Volume in a file.
+    """
+    file_path = Attr(str, label="Path to data files.")
+
+    @classmethod
+    def from_volume(self, vol: Volume):
+        raise NotImplemented
+
+
+class FreeSurferSubject(HasTraits):
+    """
+    Analysis of volume by FreeSurfer
+    """
+    subject_folder = Volume(label="Input data for analysis.")
-- 
GitLab