Skip to content
This repository was archived by the owner on Aug 14, 2021. It is now read-only.

Commit e38dab3

Browse files
committed
added migration tools
1 parent 2327fda commit e38dab3

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

common_scripts/get_collection.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@
4343
h5_filename = sprintf('%s%d.h5', tempdir, collection_id);
4444
h5_filename = websave(h5_filename, url, omics_weboptions);
4545
collection = load_hdf5_collection(h5_filename);
46+
collection.x = collection.x'; % x is row vector here, but column vector on site

common_scripts/post_collection.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
% file upload routes take multipart/form-data instead of JSON
3939
outdir = tempname;
4040
mkdir(outdir);
41+
collection.x = collection.x'; % row vector here, column vector on site
4142
filename = save_collection(outdir, suffix, collection);
43+
collection.x = collection.x'; % convert back to row vector
4244
fid = fopen(filename, 'r');
4345
data = fread(fid);
4446
fclose(fid);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
function [collection,message] = get_old_collection(collection_id,username,password)
2+
% Gets the given collection from the birg website using the given username
3+
% and password. If called without any of the parameters, displays dialogs
4+
% to get them from the user.
5+
%
6+
% Returns the collection or {} on error. If there is an error, message
7+
% contains an error message for the user.
8+
message = [];
9+
10+
if ~exist('username','var') || ~exist('password','var')
11+
[username,password] = logindlg;
12+
if isempty(username) && isempty(password)
13+
collection = {};
14+
message = 'You must enter a username and password';
15+
return;
16+
end
17+
end
18+
19+
if ~exist('collection_id','var') || isempty(collection_id)
20+
prompt={'Collection ID:'};
21+
name='Enter the collection ID from the website';
22+
numlines=1;
23+
defaultanswer={''};
24+
answer=inputdlg(prompt,name,numlines,defaultanswer);
25+
if isempty(answer)
26+
message = 'You must enter a collection ID';
27+
collection = {};
28+
return;
29+
end
30+
collection_id = str2double(answer{1});
31+
if isnan(collection_id) || length(collection_id) ~= 1
32+
message = 'You must enter a number as the collection ID';
33+
collection = {};
34+
return;
35+
end
36+
end
37+
38+
url = sprintf('http://birg.cs.wright.edu/omics_analysis/collections/%d.xml',collection_id);
39+
try
40+
if exist('proxy.conf','file')
41+
load_proxy('proxy.conf');
42+
end
43+
%[xml, urlstatus] = webread(url, 'name', username, 'password', password);
44+
[xml,urlstatus] = urlread(url, 'Timeout', 360, 'get',{'name',username,'password',password});
45+
if ~isempty(regexp(xml,'password', 'once'))
46+
message = 'Invalid password';
47+
collection = {};
48+
return;
49+
end
50+
if urlstatus == 0
51+
error('urlread failed with status 0: %s',url); %#ok<SPERR>
52+
end
53+
catch ME
54+
disp(urlstatus);
55+
throw(ME);
56+
end
57+
n = regexp(xml,'<data>(.*)</data>','tokens');
58+
data = n{1}{1};
59+
% file = tempname;
60+
% fid = fopen(file,'w');
61+
% fwrite(fid,xml);
62+
% %fprintf(fid,xml);
63+
% fclose(fid);
64+
% collection_xml = xml2struct(file);
65+
% data = collection_xml.Children(2).Children.Data;
66+
file = tempname;
67+
fid = fopen(file,'w');
68+
fwrite(fid,data);
69+
%fprintf(fid,data);
70+
fclose(fid);
71+
72+
collection = load_collection(file,'');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function migrate_collections
2+
%MIGRATE_COLLECTIONS Summary of this function goes here
3+
% Detailed explanation goes here
4+
collections = get_old_collections;
5+
for i = 1:length(collections)
6+
collections{i}.('name') = sprintf('%s (from %s)', collections{i}.description, collections{i}.collection_id);
7+
end
8+
post_collections('', collections);
9+
end
10+

0 commit comments

Comments
 (0)