comparison data_stores/vdb_biomaj.py @ 1:5c5027485f7d draft

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