Improvements to datatypes suggested by @nsoranzo

This commit is contained in:
mvdbeek
2017-12-10 12:13:37 +01:00
parent 46371d1251
commit 309b71720e
5 changed files with 13 additions and 14 deletions
+5 -5
View File
@@ -210,7 +210,7 @@ class Bam(Binary):
@staticmethod
def merge(split_files, output_file):
"""
Merges Bam files
Merges BAM files
:param split_files: List of bam file paths to merge
:param output_file: Write merged bam file to this location
@@ -232,7 +232,7 @@ class Bam(Binary):
with open(os.devnull, 'w') as devnull:
subprocess.check_call(cmd, stderr=devnull, shell=False)
needs_sorting = False
except Exception:
except subprocess.CalledProcessError:
needs_sorting = True
try:
os.unlink(index_name)
@@ -242,10 +242,10 @@ class Bam(Binary):
def groom_dataset_content(self, file_name):
"""
Ensures that the Bam file contents are sorted. This function is called
Ensures that the BAM file contents are sorted. This function is called
on an output dataset after the content is initially generated.
"""
# Use pysam to sort the Bam file
# Use pysam to sort the BAM file
# This command may also creates temporary files <out.prefix>.%d.bam when the
# whole alignment cannot fit into memory.
# do this in a unique temp directory, because of possible <out.prefix>.%d.bam temp files
@@ -254,7 +254,7 @@ class Bam(Binary):
return
tmp_dir = tempfile.mkdtemp()
tmp_sorted_dataset_file_name_prefix = os.path.join(tmp_dir, 'sorted')
sorted_file_name = "%s.bam" % tmp_sorted_dataset_file_name_prefix # samtools accepts a prefix, not a filename, it always adds .bam to the prefix
sorted_file_name = "%s.bam" % tmp_sorted_dataset_file_name_prefix
slots = os.environ.get('GALAXY_SLOTS', 1)
try:
pysam.sort("-@%s" % slots, file_name, '-T', tmp_sorted_dataset_file_name_prefix, '-O', 'BAM', '-o', sorted_file_name)
+2 -3
View File
@@ -16,7 +16,6 @@ from cgi import escape
from json import dumps
import pysam
import pysam.bcftools
from galaxy import util
from galaxy.datatypes import binary, data, metadata
@@ -740,7 +739,7 @@ class Vcf(BaseVcf):
def sniff(self, filename):
if is_gzip(filename):
return False
return BaseVcf.sniff(self, filename)
return super(Vcf, self).sniff(filename)
class VcfGz(BaseVcf, binary.Binary):
@@ -752,7 +751,7 @@ class VcfGz(BaseVcf, binary.Binary):
def sniff(self, filename):
if not is_gzip(filename):
return False
return BaseVcf.sniff(self, filename)
return super(VcfGz, self).sniff(filename)
def set_meta(self, dataset, **kwd):
super(BaseVcf, self).set_meta(dataset, **kwd)
Binary file not shown.
@@ -322,7 +322,7 @@ class TabixDataProvider(FilterableMixin, GenomeDataProvider):
@contextmanager
def open_data_file(self):
# We create a symlnk to the index file. This is
# We create a symlink to the index file. This is
# required until https://github.com/pysam-developers/pysam/pull/586 is merged.
if PYSAM_INDEX_SYMLINK_NECESSARY:
fd, index_path = tempfile.mkstemp(suffix='.tbi')
+5 -5
View File
@@ -9,12 +9,12 @@ from galaxy.util.hash_util import md5_hash_file
@contextmanager
def get_dataset(file, index_attr='bam_index', dataset_id=1, has_data=True):
def get_dataset(filename, index_attr='bam_index', dataset_id=1, has_data=True):
dataset = Bunch()
dataset.has_data = lambda: True
dataset.id = dataset_id
dataset.metadata = Bunch()
with get_input_files(file) as input_files, get_tmp_path() as index_path:
with get_input_files(filename) as input_files, get_tmp_path() as index_path:
dataset.file_name = input_files[0]
index = Bunch()
index.file_name = index_path
@@ -39,9 +39,9 @@ def get_input_files(*args):
temp_dir = tempfile.mkdtemp()
test_files = []
try:
for file in args:
shutil.copy(get_test_fname(file), temp_dir)
test_files.append(os.path.join(temp_dir, file))
for filename in args:
shutil.copy(get_test_fname(filename), temp_dir)
test_files.append(os.path.join(temp_dir, filename))
md5_sums = [md5_hash_file(f) for f in test_files]
yield test_files
new_md5_sums = [md5_hash_file(f) for f in test_files]