Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_project(project_name):
'''Try to find the project with the given name or id.'''
# First, see if the project is a project-id.
try:
project = dxpy.DXProject(project_name)
return project
except dxpy.DXError:
pass
project = dxpy.find_projects(name=project_name, return_handler=True, level="VIEW")
project = [p for p in project]
if len(project) == 0:
print('Did not find project {0}'.format(project_name))
return None
elif len(project) == 1:
return project[0]
else:
raise Exception('Found more than 1 project matching {0}'.format(project_name))
# filePath = filePath.replace("'","").replace('"','').replace("}","").replace("{","")
try:
dxlink = json.loads(filePath.strip("'"))
except:
dxlink = None
if project != None:
try:
if dxlink != None:
dxfile = dxpy.get_handler(dxlink,project=project)
else:
dxfile = dxpy.get_handler(filePath,project=project)
except:
try:
dxlink = dxpy.dxlink(filePath,project=project)
dxfile = dxpy.get_handler(dxlink)
except:
try:
proj_id = env_get_current_project_id()
dxfile = dxpy.DXFile(filePath,project=proj_id)
except:
sys.stderr.write('ERROR: unable to find file "' + filePath + '": \n')
sys.exit(0) # Do not error on tool run in dx script
else:
try:
if dxlink != None:
dxfile = dxpy.get_handler(dxlink)
else:
dxfile = dxpy.get_handler(filePath)
if project != None:
try:
if dxlink != None:
dxfile = dxpy.get_handler(dxlink,project=project)
else:
dxfile = dxpy.get_handler(filePath,project=project)
except:
try:
dxlink = dxpy.dxlink(filePath,project=project)
dxfile = dxpy.get_handler(dxlink)
except:
try:
proj_id = env_get_current_project_id()
dxfile = dxpy.DXFile(filePath,project=proj_id)
except:
sys.stderr.write('ERROR: unable to find file "' + filePath + '": \n')
sys.exit(0) # Do not error on tool run in dx script
else:
try:
if dxlink != None:
dxfile = dxpy.get_handler(dxlink)
else:
dxfile = dxpy.get_handler(filePath)
except:
try:
dxlink = dxpy.dxlink(filePath)
dxfile = dxpy.get_handler(dxlink)
except:
"\t\tshortLabel %s\n" %(name[:17]) + \
"\t\tparent %sviewpeaks on\n" %(accession) + \
"\t\ttype %s\n" %(tracktype) + \
"\t\tvisibility dense\n" + \
"\t\tview PK\n" + \
"\t\tpriority %d\n\n" %(n)
n_stanzas = 1
if not lowpass:
lowpass = []
if isinstance(lowpass,int):
lowpass = [lowpass]
extra_stanza_count = 0
for (i, cutoff) in enumerate(lowpass,start=1):
fn = dx.get_id()
if not os.path.isfile(fn):
dxpy.download_dxfile(dx.get_id(),fn)
cutoffstr = '-lt%d' %(cutoff)
outfn = fn + cutoffstr
print fn, os.path.getsize(fn), subprocess.check_output('wc -l %s' %(fn), shell=True).split()[0]
bed_fn = fn + '.bed'
common.block_on('bigBedToBed %s %s' %(fn, bed_fn))
common.run_pipe([
'cat %s' %(bed_fn),
r"""awk 'BEGIN{FS="\t";OFS="\t"}{if (($3-$2) < %d) {print $0}}'""" %(cutoff)], outfn)
print outfn, os.path.getsize(outfn), subprocess.check_output('wc -l %s' %(outfn), shell=True).split()[0]
if tracktype =='bigBed 6 +':
as_file = 'narrowPeak.as'
elif tracktype == 'bigBed 12 +':
as_file = 'gappedPeak.as'
else:
print "Cannot match tracktype %s to any .as file" %(tracktype)
bb_fn = common.bed2bb(outfn,'mm10.chrom.sizes',as_file)
if file_desc['class'] != 'file':
print("Skipping non-file data object {name} ({id})".format(**file_desc), file=sys.stderr)
return
if file_desc['state'] != 'closed':
print("Skipping file {name} ({id}) because it is not closed".format(**file_desc), file=sys.stderr)
return
try:
show_progress = args.show_progress
except AttributeError:
show_progress = False
try:
dxpy.download_dxfile(
file_desc['id'],
dest_filename,
show_progress=show_progress,
project=project,
describe_output=file_desc)
return
except:
err_exit()
"%s sort -@ %d -n %s %s" \
% (samtools, cpu_count(), input_bam_filename, final_nmsrt_bam_prefix)
logger.info(command)
subprocess.check_call(shlex.split(command))
final_BEDPE_filename = input_bam_basename + ".bedpe.gz"
out, err = common.run_pipe([
"bamToBed -bedpe -mate1 -i %s" % (final_nmsrt_bam_filename),
"gzip -cn"],
outfile=final_BEDPE_filename)
subprocess.check_output('ls -l', shell=True)
tagAlign_file = dxpy.upload_local_file(final_TA_filename)
if paired_end:
BEDPE_file = dxpy.upload_local_file(final_BEDPE_filename)
output = {}
output["tagAlign_file"] = dxpy.dxlink(tagAlign_file)
if paired_end:
output["BEDPE_file"] = dxpy.dxlink(BEDPE_file)
return output
line_count = wc_output.split()[0]
n_peaks = int(line_count)
#TODO batch consistency plot
# The following line(s) use the Python bindings to upload your file outputs
# after you have created them on the local file system. It assumes that you
# have used the output field name for the filename for each output, but you
# can change that behavior to suit your needs.
output = {}
EM_fit_output = None
empirical_curves_output = None
overlapped_peaks = None
EM_parameters_log = dxpy.upload_local_file(rep1_vs_rep2_prefix + '.log.txt')
IDR2_plot = dxpy.upload_local_file(pooled_common_peaks_IDR_filename + '.png')
output.update({
"IDR2_plot": dxpy.dxlink(IDR2_plot)
})
npeaks_pass = dxpy.upload_local_file(npeaks_pass_filename)
IDR_output = dxpy.upload_local_file(compress(pooled_common_peaks_IDR_filename))
IDR_peaks = dxpy.upload_local_file(compress(final_IDR_thresholded_filename))
#
# return { "app_output_field": postprocess_job.get_output_ref("answer"), ...}
#
subprocess.check_output('ls -l', shell=True, stderr=subprocess.STDOUT)
output.update({
global args
if job_input == None:
temp = vars(parser.parse_args(sys.argv[1:]))
for key in temp:
if temp[key] != None:
if key == 'tags':
args[key] = temp[key].split(",")
# remove whitespace around tags
for i in range(len(args[key])):
args[key][i] = args[key][i].rstrip().lstrip()
elif key == 'properties':
try:
args[key] = ast.literal_eval(temp[key])
except SyntaxError:
raise dxpy.AppError("Cannot parse properties: " + temp[key])
else:
args[key] = temp[key]
else:
args = job_input
print(args)
if 'file2' in args:
paired = True
else:
paired = False
is_fasta, is_colorspace, qual_encoding = sniff_fastq(args["file"])
if is_fasta == False and ('qual' in args or 'qual2' in args):
try:
dxlink = json.loads(filePath.strip("'"))
except:
dxlink = None
if project != None:
try:
if dxlink != None:
dxfile = dxpy.get_handler(dxlink,project=project)
else:
dxfile = dxpy.get_handler(filePath,project=project)
except:
try:
dxlink = dxpy.dxlink(filePath,project=project)
dxfile = dxpy.get_handler(dxlink)
except:
try:
proj_id = env_get_current_project_id()
dxfile = dxpy.DXFile(filePath,project=proj_id)
except:
sys.stderr.write('ERROR: unable to find file "' + filePath + '": \n')
sys.exit(0) # Do not error on tool run in dx script
else:
try:
if dxlink != None:
dxfile = dxpy.get_handler(dxlink)
else:
dxfile = dxpy.get_handler(filePath)
except:
dxfile = None
#if filePath.find("$dnanexus_link") != -1:
# filePath = filePath.split(' ')[1]
# filePath = filePath.replace("'","").replace('"','').replace("}","").replace("{","")
try:
dxlink = json.loads(filePath.strip("'"))
except:
dxlink = None
if project != None:
try:
if dxlink != None:
dxfile = dxpy.get_handler(dxlink,project=project)
else:
dxfile = dxpy.get_handler(filePath,project=project)
except:
try:
dxlink = dxpy.dxlink(filePath,project=project)
dxfile = dxpy.get_handler(dxlink)
except:
try:
proj_id = env_get_current_project_id()
dxfile = dxpy.DXFile(filePath,project=proj_id)
except:
sys.stderr.write('ERROR: unable to find file "' + filePath + '": \n')
sys.exit(0) # Do not error on tool run in dx script
else:
try:
if dxlink != None: