Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release_16.07' into backport-har…
Browse files Browse the repository at this point in the history
…dening-16.10
  • Loading branch information
natefoo committed Oct 13, 2017
2 parents e178879 + f925ffe commit e60f324
Show file tree
Hide file tree
Showing 45 changed files with 173 additions and 183 deletions.
6 changes: 3 additions & 3 deletions cron/build_chrom_db.py
Expand Up @@ -17,8 +17,8 @@
import os
import sys

import requests
from six.moves.urllib.parse import urlencode
from six.moves.urllib.request import urlopen

import parse_builds

Expand All @@ -36,8 +36,8 @@ def getchrominfo(url, db):
"hgta_regionType": "",
"position": "",
"hgta_doTopSubmit": "get info"})
page = urlopen(URL)
for line in page:
page = requests.get(URL).text
for line in page.split('\n'):
line = line.rstrip( "\r\n" )
if line.startswith("#"):
continue
Expand Down
5 changes: 2 additions & 3 deletions cron/parse_builds.py
Expand Up @@ -9,18 +9,17 @@
import sys
import xml.etree.ElementTree as ElementTree

from six.moves.urllib.request import urlopen
import requests


def getbuilds(url):
try:
page = urlopen(url)
text = requests.get(url).text
except:
print("#Unable to open " + url)
print("?\tunspecified (?)")
sys.exit(1)

text = page.read()
try:
tree = ElementTree.fromstring(text)
except:
Expand Down
6 changes: 3 additions & 3 deletions cron/parse_builds_3_sites.py
Expand Up @@ -6,7 +6,7 @@

import xml.etree.ElementTree as ElementTree

from six.moves.urllib.request import urlopen
import requests

sites = ['http://genome.ucsc.edu/cgi-bin/',
'http://archaea.ucsc.edu/cgi-bin/',
Expand All @@ -20,11 +20,11 @@ def main():
trackurl = sites[i] + "hgTracks?"
builds = []
try:
page = urlopen(site)
text = requests.get(site).text
except:
print("#Unable to connect to " + site)
continue
text = page.read()

try:
tree = ElementTree.fromstring(text)
except:
Expand Down
13 changes: 5 additions & 8 deletions lib/galaxy/datatypes/binary.py
Expand Up @@ -285,10 +285,8 @@ def merge(split_files, output_file):

def _is_coordinate_sorted( self, file_name ):
"""See if the input BAM file is sorted from the header information."""
params = [ "samtools", "view", "-H", file_name ]
output = subprocess.Popen( params, stderr=subprocess.PIPE, stdout=subprocess.PIPE ).communicate()[0]
# find returns -1 if string is not found
return output.find( "SO:coordinate" ) != -1 or output.find( "SO:sorted" ) != -1
output = subprocess.check_output(["samtools", "view", "-H", file_name])
return 'SO:coordinate' in output or 'SO:sorted' in output

def dataset_content_needs_grooming( self, file_name ):
"""See if file_name is a sorted BAM file"""
Expand All @@ -313,8 +311,7 @@ def dataset_content_needs_grooming( self, file_name ):
return False
index_name = tempfile.NamedTemporaryFile( prefix="bam_index" ).name
stderr_name = tempfile.NamedTemporaryFile( prefix="bam_index_stderr" ).name
command = 'samtools index %s %s' % ( file_name, index_name )
proc = subprocess.Popen( args=command, shell=True, stderr=open( stderr_name, 'wb' ) )
proc = subprocess.Popen(['samtools', 'index', file_name, index_name], stderr=open(stderr_name, 'wb'))
proc.wait()
stderr = open( stderr_name ).read().strip()
if stderr:
Expand Down Expand Up @@ -357,8 +354,8 @@ def groom_dataset_content( self, file_name ):
tmp_sorted_dataset_file_name_prefix = os.path.join( tmp_dir, 'sorted' )
stderr_name = tempfile.NamedTemporaryFile( dir=tmp_dir, prefix="bam_sort_stderr" ).name
samtools_created_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
command = "samtools sort %s %s" % ( file_name, tmp_sorted_dataset_file_name_prefix )
proc = subprocess.Popen( args=command, shell=True, cwd=tmp_dir, stderr=open( stderr_name, 'wb' ) )
proc = subprocess.Popen(['samtools', 'sort', file_name, tmp_sorted_dataset_file_name_prefix],
cwd=tmp_dir, stderr=open(stderr_name, 'wb'))
exit_code = proc.wait()
# Did sort succeed?
stderr = open( stderr_name ).read().strip()
Expand Down
5 changes: 3 additions & 2 deletions lib/galaxy/datatypes/converters/interval_to_coverage.py
Expand Up @@ -133,8 +133,9 @@ def close(self):
# Sort through a tempfile first
temp_file = tempfile.NamedTemporaryFile(mode="r")
environ['LC_ALL'] = 'POSIX'
commandline = "sort -f -n -k %d -k %d -k %d -o %s %s" % (chr_col_1 + 1, start_col_1 + 1, end_col_1 + 1, temp_file.name, in_fname)
subprocess.check_call(commandline, shell=True)
subprocess.check_call([
'sort', '-f', '-n', '-k', chr_col_1 + 1, '-k', start_col_1 + 1, '-k', end_col_1 + 1, '-o', temp_file.name, in_fname
])

coverage = CoverageWriter( out_stream=open(out_fname, "a"),
chromCol=chr_col_2, positionCol=position_col_2,
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/datatypes/converters/lped_to_pbed_converter.py
Expand Up @@ -72,9 +72,9 @@ def rgConv(inpedfilepath, outhtmlname, outfilepath, plink):
if not missval:
print('### lped_to_pbed_converter.py cannot identify missing value in %s' % pedf)
missval = '0'
cl = '%s --noweb --file %s --make-bed --out %s --missing-genotype %s' % (plink, inpedfilepath, outroot, missval)
p = subprocess.Popen(cl, shell=True, cwd=outfilepath)
p.wait() # run plink
subprocess.check_call([plink, '--noweb', '--file', inpedfilepath,
'--make-bed', '--out', outroot,
'--missing-genotype', missval], cwd=outfilepath)


def main():
Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/datatypes/converters/pbed_ldreduced_converter.py
Expand Up @@ -41,8 +41,7 @@ def pruneLD(plinktasks=[], cd='./', vclbase=[]):
for task in plinktasks: # each is a list
vcl = vclbase + task
with open(plog, 'w') as sto:
x = subprocess.Popen(' '.join(vcl), shell=True, stdout=sto, stderr=sto, cwd=cd)
x.wait()
subprocess.check_call(vcl, stdout=sto, stderr=sto, cwd=cd)
try:
lplog = open(plog, 'r').readlines()
lplog = [elem for elem in lplog if elem.find('Pruning SNP') == -1]
Expand Down
4 changes: 1 addition & 3 deletions lib/galaxy/datatypes/converters/pbed_to_lped_converter.py
Expand Up @@ -40,9 +40,7 @@ def rgConv(inpedfilepath, outhtmlname, outfilepath, plink):
"""
basename = os.path.split(inpedfilepath)[-1] # get basename
outroot = os.path.join(outfilepath, basename)
cl = '%s --noweb --bfile %s --recode --out %s ' % (plink, inpedfilepath, outroot)
p = subprocess.Popen(cl, shell=True, cwd=outfilepath)
p.wait() # run plink
subprocess.check_call([plink, '--noweb', '--bfile', inpedfilepath, '--recode', '--out', outroot], cwd=outfilepath)


def main():
Expand Down
15 changes: 10 additions & 5 deletions lib/galaxy/datatypes/converters/sam_to_bam.py
Expand Up @@ -68,8 +68,10 @@ def __main__():
# convert to SAM
unsorted_bam_filename = os.path.join( tmp_dir, 'unsorted.bam' )
unsorted_stderr_filename = os.path.join( tmp_dir, 'unsorted.stderr' )
cmd = "samtools view -bS '%s' > '%s'" % ( input_filename, unsorted_bam_filename )
proc = subprocess.Popen( args=cmd, stderr=open( unsorted_stderr_filename, 'wb' ), shell=True, cwd=tmp_dir )
proc = subprocess.Popen(['samtools', 'view', '-bS', input_filename],
stdout=open(unsorted_bam_filename, 'wb'),
stderr=open(unsorted_stderr_filename, 'wb'),
cwd=tmp_dir)
return_code = proc.wait()
if return_code:
stderr_target = sys.stderr
Expand All @@ -90,10 +92,13 @@ def __main__():
# samtools changed sort command arguments (starting from version 1.3)
samtools_version = LooseVersion(_get_samtools_version())
if samtools_version < LooseVersion('1.0'):
cmd = "samtools sort -o '%s' '%s' > '%s'" % ( unsorted_bam_filename, sorting_prefix, output_filename )
sort_args = ['-o', unsorted_bam_filename, sorting_prefix]
else:
cmd = "samtools sort -T '%s' '%s' > '%s'" % ( sorting_prefix, unsorted_bam_filename, output_filename )
proc = subprocess.Popen( args=cmd, stderr=open( sorted_stderr_filename, 'wb' ), shell=True, cwd=tmp_dir )
sort_args = ['-T', sorting_prefix, unsorted_bam_filename]
proc = subprocess.Popen(['samtools', 'sort'] + sort_args,
stdout=open(output_filename, 'wb'),
stderr=open(sorted_stderr_filename, 'wb'),
cwd=tmp_dir)
return_code = proc.wait()

if return_code:
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/datatypes/sequence.py
Expand Up @@ -8,6 +8,7 @@
import os
import re
import string
import subprocess
import sys
from cgi import escape

Expand Down Expand Up @@ -662,8 +663,7 @@ def process_split_file(data):
else:
commands = Sequence.get_split_commands_sequential(is_gzip(input_name), input_name, output_name, start_sequence, sequence_count)
for cmd in commands:
if 0 != os.system(cmd):
raise Exception("Executing '%s' failed" % cmd)
subprocess.check_call(cmd, shell=True)
return True
process_split_file = staticmethod(process_split_file)

Expand Down
14 changes: 6 additions & 8 deletions lib/galaxy/datatypes/tabular.py
Expand Up @@ -9,6 +9,7 @@
import logging
import os
import re
import shutil
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -519,15 +520,12 @@ def merge( split_files, output_file):
Multiple SAM files may each have headers. Since the headers should all be the same, remove
the headers from files 1-n, keeping them in the first file only
"""
cmd = 'mv %s %s' % ( split_files[0], output_file )
result = os.system(cmd)
if result != 0:
raise Exception('Result %s from %s' % (result, cmd))
shutil.move(split_files[0], output_file)

if len(split_files) > 1:
cmd = 'egrep -v -h "^@" %s >> %s' % ( ' '.join(split_files[1:]), output_file )
result = os.system(cmd)
if result != 0:
raise Exception('Result %s from %s' % (result, cmd))
cmd = ['egrep', '-v', '-h', '^@'] + split_files[1:] + ['>>', output_file]
subprocess.check_call(cmd, shell=True)

merge = staticmethod(merge)

# Dataproviders
Expand Down
11 changes: 6 additions & 5 deletions lib/galaxy/datatypes/text.py
Expand Up @@ -10,6 +10,8 @@
import subprocess
import tempfile

from six.moves import shlex_quote

from galaxy.datatypes.data import get_file_peek, Text
from galaxy.datatypes.metadata import MetadataElement, MetadataParameter
from galaxy.datatypes.sniff import get_headers
Expand Down Expand Up @@ -144,13 +146,12 @@ def _display_data_trusted(self, trans, dataset, preview=False, filename=None, to
ofilename = ofile_handle.name
ofile_handle.close()
try:
cmd = 'ipython nbconvert --to html --template full %s --output %s' % (dataset.file_name, ofilename)
log.info("Calling command %s" % cmd)
subprocess.call(cmd, shell=True)
cmd = ['ipython', 'nbconvert', '--to', 'html', '--template', 'full', dataset.file_name, '--output', ofilename]
subprocess.check_call(cmd)
ofilename = '%s.html' % ofilename
except:
except subprocess.CalledProcessError:
ofilename = dataset.file_name
log.exception( 'Command "%s" failed. Could not convert the IPython Notebook to HTML, defaulting to plain text.' % cmd )
log.exception('Command "%s" failed. Could not convert the IPython Notebook to HTML, defaulting to plain text.', ' '.join(map(shlex_quote, cmd)))
return open( ofilename )

def set_meta( self, dataset, **kwd ):
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/external_services/actions.py
@@ -1,6 +1,6 @@
# Contains actions that are used in External Services
import logging
from urllib import urlopen
import requests
from galaxy.web import url_for
from galaxy.util.template import fill_template
from result_handlers.basic import ExternalServiceActionResultHandler
Expand Down Expand Up @@ -104,7 +104,7 @@ def __init__( self, name, param_dict, url, method, target ): # display_handler
@property
def content( self ):
if self._content is None:
self._content = urlopen( self.url ).read()
self._content = requests.get(self.url).text
return self._content


Expand Down
10 changes: 5 additions & 5 deletions lib/galaxy/jobs/deferred/pacific_biosciences_smrt_portal.py
Expand Up @@ -2,14 +2,14 @@
Module for managing jobs in Pacific Bioscience's SMRT Portal and automatically transferring files
produced by SMRT Portal.
"""
import json
import logging
from string import Template

from six.moves.urllib.request import urlopen
import requests

from .data_transfer import DataTransfer


log = logging.getLogger( __name__ )

__all__ = ( 'SMRTPortalPlugin', )
Expand Down Expand Up @@ -87,9 +87,9 @@ def check_job( self, job ):
if job.params[ 'type' ] == 'init_transfer':
if self._missing_params( job.params, [ 'smrt_host', 'smrt_job_id' ] ):
return self.job_states.INVALID
url = 'http://' + job.params[ 'smrt_host' ] + self.api_path + '/Jobs/' + job.params[ 'smrt_job_id' ] + '/Status'
r = urlopen( url )
status = json.loads( r.read() )
url = 'http://' + job.params['smrt_host'] + self.api_path + '/Jobs/' + job.params['smrt_job_id'] + '/Status'
r = requests.get(url)
status = r.json()
# TODO: error handling: unexpected json or bad response, bad url, etc.
if status[ 'Code' ] == 'Completed':
log.debug( "SMRT Portal job '%s' is Completed. Initiating transfer." % job.params[ 'smrt_job_id' ] )
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/jobs/runners/pulsar.py
Expand Up @@ -7,6 +7,7 @@
import errno
import logging
import os
import subprocess
from distutils.version import LooseVersion
from time import sleep

Expand Down Expand Up @@ -217,7 +218,7 @@ def __init_pulsar_app( self, pulsar_conf_path ):
else:
log.info("Loading Pulsar app configuration from %s" % pulsar_conf_path)
with open(pulsar_conf_path, "r") as f:
conf.update(yaml.load(f) or {})
conf.update(yaml.safe_load(f) or {})
if "job_metrics_config_file" not in conf:
conf["job_metrics"] = self.app.job_metrics
if "staging_directory" not in conf:
Expand Down Expand Up @@ -382,8 +383,7 @@ def __prepare_input_files_locally(self, job_wrapper):
prepare_input_files_cmds = getattr(job_wrapper, 'prepare_input_files_cmds', None)
if prepare_input_files_cmds is not None:
for cmd in prepare_input_files_cmds: # run the commands to stage the input files
if 0 != os.system(cmd):
raise Exception('Error running file staging command: %s' % cmd)
subprocess.check_call(cmd, shell=True)
job_wrapper.prepare_input_files_cmds = None # prevent them from being used in-line

def _populate_parameter_defaults( self, job_destination ):
Expand Down
21 changes: 13 additions & 8 deletions lib/galaxy/jobs/runners/util/job_script/__init__.py
@@ -1,3 +1,4 @@
import logging
import os
import subprocess
import time
Expand All @@ -8,6 +9,7 @@

from galaxy.util import unicodify

log = logging.getLogger(__name__)
DEFAULT_SHELL = '/bin/bash'

DEFAULT_JOB_FILE_TEMPLATE = Template(
Expand Down Expand Up @@ -118,24 +120,27 @@ def _handle_script_integrity(path, config):
sleep_amt = getattr(config, "check_job_script_integrity_sleep", DEFAULT_INTEGRITY_SLEEP)
for i in range(count):
try:
proc = subprocess.Popen([path], shell=True, env={"ABC_TEST_JOB_SCRIPT_INTEGRITY_XYZ": "1"})
proc.wait()
if proc.returncode == 42:
returncode = subprocess.call([path], env={"ABC_TEST_JOB_SCRIPT_INTEGRITY_XYZ": "1"})
if returncode == 42:
script_integrity_verified = True
break

log.debug("Script integrity error: returncode was %d", returncode)

# Else we will sync and wait to see if the script becomes
# executable.
try:
# sync file system to avoid "Text file busy" problems.
# These have occurred both in Docker containers and on EC2 clusters
# under high load.
subprocess.check_call(INTEGRITY_SYNC_COMMAND)
except Exception:
pass
time.sleep(sleep_amt)
except Exception:
pass
except Exception as e:
log.debug("Error syncing the filesystem: %s", unicodify(e))

except Exception as exc:
log.debug("Script not available yet: %s", unicodify(exc))

time.sleep(sleep_amt)

if not script_integrity_verified:
raise Exception("Failed to write job script, could not verify job script integrity.")
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/jobs/runners/util/kill.py
@@ -1,7 +1,7 @@
import os
import subprocess
from platform import system
from time import sleep
from subprocess import Popen

try:
from psutil import Process, NoSuchProcess
Expand Down Expand Up @@ -41,8 +41,8 @@ def _stock_kill_pid(pid):

def __kill_windows(pid):
try:
Popen("taskkill /F /T /PID %i" % pid, shell=True)
except Exception:
subprocess.check_call(['taskkill', '/F', '/T', '/PID', pid])
except subprocess.CalledProcessError:
pass


Expand Down

0 comments on commit e60f324

Please sign in to comment.