Skip to content

Commit

Permalink
refactor: change stream_cram to use cram_path instead of cram_name, a…
Browse files Browse the repository at this point in the history
…nd to take advantage of the added self.s3_endpoint and self.htsget_endpoint to point to the requested CRAM file.
  • Loading branch information
AssafSternberg committed Apr 23, 2024
1 parent aa7fc97 commit 2fd9ac4
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions modo/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,31 +379,25 @@ def enrich_metadata(self):
continue

def stream_cram(
self, cram_name: str, region: str = None, output: str = None
self, cram_path: str, region: str = None, output: str = None
):
"""Slices and streams the requested CRAM file, both local and remote,
and either outputs a data stream or writes data to local file"""

# check requested CRAM exists in MODO
path = ""
filepaths = list(self.list_files())
for filepath in filepaths:
if cram_name == str(filepath).split("/")[-1]:
path = filepath
break
if path == "":
raise ValueError(f"{cram_name} not fount in {self.path}.")
if Path(cram_path) not in self.list_files():
raise ValueError(f"{cram_path} not found in {self.path}.")

if self.s3_endpoint:
# http://domain/s3 + bucket/modo/file.cram --> http://domain/htsget/reads/modo/file.cram
url = (
re.sub(r"s3$", "", self.s3_endpoint)
+ "htsget/reads/"
+ path.split("/", maxsplit=1)
self.htsget_endpoint
+ "/reads/"
+ str(Path(*Path(cram_path).parts[1:]))
)
# str(Path(*Path(cram_path).parts[1:])) same as path.split("/", maxsplit=1)[1] but cross-platform
slice_remote_cram(url, region, output)
else:
# assuming user did not change directory, filepath should be the
# relative path to the file.
iter = slice_cram(path, region)
iter = slice_cram(cram_path, region)
return iter

0 comments on commit 2fd9ac4

Please sign in to comment.