Skip to content

Commit

Permalink
Merge pull request galaxyproject#18776 from PlushZ/fastagz-view-issue
Browse files Browse the repository at this point in the history
fix fasta.gz viewer issue
  • Loading branch information
mvdbeek authored Sep 6, 2024
2 parents c42710a + 1bb00d3 commit 4e47fce
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions lib/galaxy/datatypes/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,34 @@ def get_split_commands_sequential(

return [cmd]

def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
**kwd,
):
headers = kwd.get("headers", {})
if preview:
with compression_utils.get_fileobj(dataset.get_file_name()) as fh:
max_peek_size = 100000
try:
chunk = fh.read(max_peek_size + 1)
except UnicodeDecodeError:
raise InvalidFileFormatError("Dataset appears to contain binary data, cannot display.")
if len(chunk) <= max_peek_size:
mime = "text/plain"
self._clean_and_set_mime_type(trans, mime, headers)
return chunk[:-1], headers
return (
trans.fill_template_mako("/dataset/large_file.mako", truncated_data=chunk[:-1], data=dataset),
headers,
)
else:
return super().display_data(trans, dataset, preview, filename, to_ext, **kwd)


class Alignment(data.Text):
"""Class describing an alignment"""
Expand Down Expand Up @@ -764,34 +792,6 @@ def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
return False
return self.check_first_block(file_prefix)

def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
**kwd,
):
headers = kwd.get("headers", {})
if preview:
with compression_utils.get_fileobj(dataset.get_file_name()) as fh:
max_peek_size = 100000
try:
chunk = fh.read(max_peek_size + 1)
except UnicodeDecodeError:
raise InvalidFileFormatError("Dataset appears to contain binary data, cannot display.")
if len(chunk) <= max_peek_size:
mime = "text/plain"
self._clean_and_set_mime_type(trans, mime, headers)
return chunk[:-1], headers
return (
trans.fill_template_mako("/dataset/large_file.mako", truncated_data=chunk[:-1], data=dataset),
headers,
)
else:
return Sequence.display_data(self, trans, dataset, preview, filename, to_ext, **kwd)

@classmethod
def split(cls, input_datasets: List, subdir_generator_function: Callable, split_params: Optional[Dict]) -> None:
"""
Expand Down

0 comments on commit 4e47fce

Please sign in to comment.