diff --git a/scientific_library/tvb/analyzers/freesurfer.py b/scientific_library/tvb/analyzers/freesurfer.py new file mode 100644 index 0000000000000000000000000000000000000000..09b3debead462315ee276e8d0ee4789167f8161a --- /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 fa7e189b66996d07c8e3ac8fa596b4caa5fc82eb..01b6e828782adf11a0f22151551f55bf26a0eea6 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.")