-
Notifications
You must be signed in to change notification settings - Fork 1
/
OMERO_upload_attachment.py
executable file
·53 lines (40 loc) · 1.61 KB
/
OMERO_upload_attachment.py
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
# Import files to OMERO dataset
#
# *****NOTE*****
#
# -change username to your username
# -may require specific group, e.g., if None Type error
# -requires command line arguments for -dataset and -indir
from omero.gateway import BlitzGateway
import getpass
import argparse
import sys
import os
PASS = getpass.getpass("Enter Password:")
conn = BlitzGateway('bioc1301', PASS, host='omero1.bioch.ox.ac.uk', port=4064, group='davisgroup')
conn.connect()
group = conn.getGroupFromContext()
def main(argList):
parser= argparse.ArgumentParser()
# specify infile and where to put it
parser.add_argument('-dataset', help='dataset where file should be attached')
parser.add_argument('-indir', help='directory of files to be attached')
args= parser.parse_args(args=argList)
# find dataset in OMERO
dataset_id = args.dataset
dataset = conn.getObject("Dataset", dataset_id)
# get a local file e.g. result of some analysis
infiles = os.listdir(args.indir)
# loop through files
for i in infiles:
#can specificy namespace
#namespace = "imperial.training.demo"
# also include ns=namespace, in file_ann below
i = os.path.join(args.indir, i)
print "\nCreating FileAnnotation for", i
file_ann = conn.createFileAnnfromLocalFile(i, mimetype="text/plain", desc=None)
print "Attaching FileAnnotation to Dataset: ", "File ID:", file_ann.getId(), \
",", file_ann.getFile().getName(), "Size:", file_ann.getFile().getSize()
dataset.linkAnnotation(file_ann) # link it to dataset.
if __name__=='__main__':
main(sys.argv[1:])