def wrapNewResource(path): # filter out non-resource file types: for ext in FILE_INDICES.keys(): if path.endswith(ext): log.debug('Index file {f} given as regular file, will be treated ' ' as an index file instead'.format(f=path)) return extRes = ExternalResource() path = resolveLocation(path) extRes.resourceId = path index_files = [ path + ext for ext in FILE_INDICES.keys() if os.path.exists(path + ext) ] if index_files: extRes.addIndices(index_files) # Check for sub resources: for ext in SUB_RESOURCES: filen = '.'.join(path.split('.')[:-2]) + ext # don't want to add e.g. scraps to scraps: if os.path.exists(filen) and path.endswith('subreads.bam'): log.debug("Adding {} as a subresource".format(filen)) subres = wrapNewResource(filen) setattr(extRes, ext.split('.')[1], subres) return extRes
def test_addExternalResources(self): ds = DataSet() er1 = ExternalResource() er1.resourceId = "test1.bam" er2 = ExternalResource() er2.resourceId = "test2.bam" er3 = ExternalResource() er3.resourceId = "test1.bam" ds.addExternalResources([er1], updateCount=False) self.assertEquals(ds.numExternalResources, 1) # different resourceId: succeeds ds.addExternalResources([er2], updateCount=False) self.assertEquals(ds.numExternalResources, 2) # same resourceId: fails ds.addExternalResources([er3], updateCount=False) self.assertEquals(ds.numExternalResources, 2) for extRef in ds.externalResources: self.assertEqual(type(extRef).__name__, "ExternalResource") extRef = ds.externalResources[0] self.assertEqual(type(extRef).__name__, "ExternalResource") self.assertEqual(extRef.resourceId, 'test1.bam') extRef = ds.externalResources[1] self.assertEqual(type(extRef).__name__, "ExternalResource") self.assertEqual(extRef.resourceId, 'test2.bam')
def wrapNewResource(path): possible_indices = [".fai", ".pbi", ".bai", ".metadata.xml"] for ext in possible_indices: if path.endswith(ext): log.debug( "Index file {f} given as regular file, will be treated " " as an index file instead".format(f=path) ) return extRes = ExternalResource() path = resolveLocation(path) extRes.resourceId = path index_files = [path + ext for ext in possible_indices if os.path.exists(path + ext)] if index_files: extRes.addIndices(index_files) return extRes
def wrapNewResource(path): possible_indices = ['.fai', '.pbi', '.bai', '.metadata.xml'] for ext in possible_indices: if path.endswith(ext): log.debug('Index file {f} given as regular file, will be treated ' ' as an index file instead'.format(f=path)) return extRes = ExternalResource() path = resolveLocation(path) extRes.resourceId = path index_files = [ path + ext for ext in possible_indices if os.path.exists(path + ext) ] if index_files: extRes.addIndices(index_files) return extRes
def wrapNewResource(path): # filter out non-resource file types: for ext in FILE_INDICES: if path.endswith(ext): log.debug('Index file {f} given as regular file, will be treated ' ' as an index file instead'.format(f=path)) return extRes = ExternalResource() path = resolveLocation(path) extRes.resourceId = path index_files = [path + ext for ext in FILE_INDICES if os.path.exists(path + ext)] if index_files: extRes.addIndices(index_files) # Check for sub resources: for ext in SUB_RESOURCES: filen = '.'.join(path.split('.')[:-2]) + ext # don't want to add e.g. scraps to scraps: if os.path.exists(filen) and path.endswith('subreads.bam'): subres = wrapNewResource(filen) setattr(extRes, ext.split('.')[1], subres) return extRes