Created
September 23, 2013 01:57
-
-
Save beOn/6665660 to your computer and use it in GitHub Desktop.
An interface that gathers all of the files you pass it into a single directory using hard links.
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
import os | |
from nipype.interfaces.base import BaseInterface, InputMultiPath,\ | |
OutputMultiPath, BaseInterfaceInputSpec, traits, File, TraitedSpec | |
class CCPGatherFilesInputSpec(BaseInterfaceInputSpec): | |
files = InputMultiPath( | |
traits.Either(traits.List(File(exists=True)),File(exists=True)), | |
mandatory=True, | |
desc='a list of files you would like to gather into one directory with symlinks', | |
copyfile=False) | |
class CCPGatherFilesOutputSpec(TraitedSpec): | |
links = OutputMultiPath( | |
traits.List(File(exists=True)), | |
desc='a list of files, all in the same directory.') | |
class CCPGatherFiles(BaseInterface): | |
input_spec = CCPGatherFilesInputSpec | |
output_spec = CCPGatherFilesOutputSpec | |
d_files = [] | |
def _run_interface(self, runtime): | |
import os | |
files = self.inputs.files | |
new_dir = os.path.abspath('link_dir') | |
os.mkdir(new_dir) | |
for f in files: | |
fname = os.path.split(f)[-1] | |
os.link(f, os.path.join(new_dir, fname)) | |
return runtime | |
def _list_outputs(self): | |
from glob import glob | |
import os | |
outputs = self._outputs().get() | |
outputs['links'] = glob(os.path.join(os.path.abspath('.'), 'link_dir','*')) | |
return outputs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment