-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathtransferHippocampusData.m
99 lines (83 loc) · 2.63 KB
/
transferHippocampusData.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
function [] = transferHippocampusData()
%TRANSFERHIPPOCAMPUSDATA To be called in the hmmsort_pbs.py to be sumitted
%as a job onto PBS queue.
%
% Detailed explanation goes here
cwd = pwd;
dataName = strrep(cwd,filesep,'_');
fileName = [dataName,'.tar.gz']; % tar.gz name
indexDay = strfind(cwd,'2018');
picassoDir = fullfile(filesep,'volume1','Hippocampus','Data','picasso');
dayStr = cwd(indexDay:indexDay+7);
dayDir = fullfile(picassoDir, dayStr); % directory of the day
tempDir = fullfile(dayDir, 'transferTemp'); % direcotry of the temporary folder
targetDir = fullfile(tempDir, dataName); % directory to save the tar.gz file temporarily in hippocampus
sshHippocampus = 'ssh -p 8398 [email protected]';
cd ..
system(['tar -cvzf ',fileName,' ',cwd]);
disp(' ');
[flag, count] = resetFlags;
while ~flag && count < 100
try
system(['scp -P 8398 ',fileName,' [email protected]:~/']);
disp(['Secured copied ',fileName,' to home directory of hippocampus ...']);
flag = 1;
catch
disp('Retrying scp tar file to home directory of hippocampus...')
pause(10)
end
end
disp(' ');
[flag, count] = resetFlags;
while ~flag && count < 100
try
system([sshHippocampus,' mkdir -p ', targetDir]);
disp(['Made a directory ',targetDir,' ...']);
flag = 1;
catch
disp('Retrying making temporary directory...')
pause(10)
end
end
disp(' ');
flag = 0;
count = 1;
while ~flag && count < 100
try
system([sshHippocampus,' mv -v ',fileName,' ',targetDir]);
flag = 1;
catch
disp('Retrying moving tar file...')
end
end
disp(' ');
[flag, count] = resetFlags;
while ~flag && count < 100
try
system([sshHippocampus,' tar -xvzf ',fullfile(targetDir,fileName),' -C ',targetDir]);
flag = 1;
catch
disp('Retrying extracting tar file...')
end
end
disp(' ')
[flag, count] = resetFlags;
while ~flag && count < 100
try
system([sshHippocampus, ' find ',targetDir,' -name ',dayStr,' | while IFS= read file; do ',sshHippocampus,' cp -vrRup $file ',picassoDir,'; done']);
flag = 1;
delete(fileName); % delete tar file
system([sshHippocampus,' rm -rv ',fullfile(tempDir,[dataName,'*'])]) % remove directory in hippocapus temporary folder
fid = fopen(fullfile(cwd,'transferred.txt'),'w'); % to mark the channel has been successfully transferred
fclose(fid);
catch
disp('Retrying moving files to proper places...')
end
end
disp(' ');
%system([sshHippocampus,' rm -v ',fullfile(targetDir,dataName)]);
end
function [flag, count] = resetFlags()
flag = 0;
count = 1;
end