annotate data_stores/vdb_biomaj.py @ 2:269d246ce6d0 draft default tip

Uploaded
author damion
date Fri, 23 Oct 2015 17:53:29 -0400
parents 5c5027485f7d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
1 #!/usr/bin/python
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
2 ## ******************************* Biomaj FOLDER *********************************
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
3 ##
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
4
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
5 import os
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
6 import time
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
7 import glob
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
8 import vdb_common
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
9 import vdb_data_stores
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
10
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
11 class VDBBiomajDataStore(vdb_data_stores.VDBDataStore):
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
12
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
13 versions = None
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
14 library = None
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
15
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
16 def __init__(self, retrieval_obj, spec_file_id):
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
17 """
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
18 Provides list of available versions where each version is a data file sitting in a Biomaj data store subfolder. e.g.
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
19
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
20 /projects2/ref_databases/biomaj/ncbi/blast/silva_rna/ silva_rna_119/flat
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
21 /projects2/ref_databases/biomaj/ncbi/genomes/Bacteria/ Bacteria_2014-07-25/flat
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
22
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
23 """
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
24 super(VDBBiomajDataStore, self).__init__(retrieval_obj, spec_file_id)
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
25
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
26 self.library = retrieval_obj.library
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
27
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
28 versions = []
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
29 # Linked, meaning that our data source spec file pointed to some folder on the server.
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
30 # Name of EACH subfolder should be a label for each version, including date/time and version id.
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
31
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
32 base_file_path = os.path.join(os.path.dirname(self.base_file_name),'*','flat','*')
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
33 try:
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
34 #Here we need to get subfolder listing of linked file location.
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
35 for item in glob.glob(base_file_path):
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
36
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
37 # Only interested in files, and not ones in the symlinked /current/ subfolder
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
38 # Also, Galaxy will strip off .gz suffixes - WITHOUT UNCOMPRESSING FILES!
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
39 # So, best to prevent data store from showing .gz files in first place.
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
40 if os.path.isfile(item) and not '/current/' in item and not item[-3:] == '.gz':
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
41 #Name includes last two subfolders: /[folder]/flat/[name]
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
42 item_name = '/'.join(item.rsplit('/',3)[1:])
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
43 # Can't count on creation date being spelled out in name
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
44 created = vdb_common.parse_date(time.ctime(os.path.getmtime(item)))
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
45 versions.append({'name':item_name, 'id':item_name, 'created': created})
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
46
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
47 except Exception as err:
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
48 # This is the first call to api so api url or authentication erro can happen here.
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
49 versions.append({
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
50 'name':'Error: Unable to get version list: ' + err.message,
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
51 'id':'',
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
52 'created':''
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
53 })
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
54
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
55 self.versions = sorted(versions, key=lambda x: x['name'], reverse=True)
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
56
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
57
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
58 def get_version(self, version_name):
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
59 """
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
60 Return server path of requested version info
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
61
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
62 @uses library_label_path string Full hierarchic label of a library file or folder, PARENT of version id folder.
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
63 @uses base_file_name string Server absolute path to data_store spec file
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
64 @param version_name alphaneumeric string
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
65 """
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
66 self.version_label = version_name
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
67 self.library_version_path = os.path.join(self.library_label_path, self.version_label)
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
68
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
69 #linked to some other folder, spec is location of base_file_name
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
70 self.version_path = os.path.join(self.data_store_path, version_name)
5c5027485f7d Uploaded correct file
damion
parents:
diff changeset
71