Example #1
0
File: validate.py Project: chdem/TS
def validate(upload_id, base_path, meta, bed_file, bed_type):
    print("Validating %s file: %s" % (bed_type,bed_file))
    print
    path_end = '/'+meta["reference"]+"/unmerged/detail/"+bed_file
    data, response, raw = api.get("content", publisher_name='BED', format='json', path__endswith=path_end)
    if int(data['meta']['total_count']) > 0:
        if meta['is_ampliseq']:
            return data['objects'][0]['file']
        #api.post('log', upload='/rundb/api/v1/contentupload/%s/' % str(upload_id),
        #         text='Error: The file %s already exists. Please rename your file.'%bed_file)
        print 'ERROR: The file %s already exists. Please rename your file.' % bed_file
        sys.exit(1)
    
    result_UD_dir = os.path.join(base_path,meta['reference'],'unmerged','detail')
    result_UP_dir = os.path.join(base_path,meta['reference'],'unmerged','plain')
    result_MD_dir = os.path.join(base_path,meta['reference'],'merged','detail')
    result_MP_dir = os.path.join(base_path,meta['reference'],'merged','plain')
    if not os.path.exists(result_UD_dir):
        os.makedirs(result_UD_dir)
    if not os.path.exists(result_UP_dir):
        os.makedirs(result_UP_dir)
    if not os.path.exists(result_MD_dir):
        os.makedirs(result_MD_dir)
    if not os.path.exists(result_MP_dir):
        os.makedirs(result_MP_dir)
    #output_log = os.path.join(base_path, bed_file+'.log')
    output_json = os.path.join(base_path, bed_file+'.json')

    cmd =       '/usr/local/bin/tvcutils validate_bed'
    cmd +=      '  --reference /results/referenceLibrary/tmap-f3/%s/%s.fasta' % (meta['reference'],meta['reference'])
    if bed_type == 'target regions BED':
        cmd +=  '  --target-regions-bed "%s"'   % os.path.join(base_path,        bed_file)
    elif bed_type == 'hotspots BED':
        cmd +=  '  --hotspots-bed "%s"'         % os.path.join(base_path,        bed_file)
            
    cmd +=      '  --unmerged-detail-bed "%s"'  % os.path.join(result_UD_dir,    bed_file)
    cmd +=      '  --unmerged-plain-bed "%s"'   % os.path.join(result_UP_dir,    bed_file)
    cmd +=      '  --merged-detail-bed "%s"'    % os.path.join(result_MD_dir,    bed_file)
    cmd +=      '  --merged-plain-bed "%s"'     % os.path.join(result_MP_dir,    bed_file)
    #cmd +=      '  --validation-log "%s"'       % output_log
    cmd +=      '  --meta-json "%s"'            % output_json
    #print cmd
    p = subprocess.Popen(cmd, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=True)
    print p.communicate()[0]
    #sys.stderr.write("=== -.- ===\n")
    #print stdout
    #print stderr
    
    #if os.path.exists(output_log):
    #  for line in open(output_log):
    #      api.post('log', upload='/rundb/api/v1/contentupload/%s/' % str(upload_id), text=line.strip())
    
    if os.path.exists(output_json):
      with open(output_json) as json_file:
        meta.update(json.load(json_file))
    
    if p.returncode != 0:
        sys.exit(p.returncode)

    return None
Example #2
0
 def get(self, endpoint, data=None):
     return get(VentataAPI.BASE_URL + endpoint, self.api_key, data)
Example #3
0
def validate(upload_id, base_path, meta, bed_file, bed_type):
    print("Validating %s file: %s" % (bed_type, bed_file))
    print
    path_end = '/' + meta["reference"] + "/unmerged/detail/" + bed_file
    data, response, raw = api.get("content",
                                  publisher_name='BED',
                                  format='json',
                                  path__endswith=path_end)
    if int(data['meta']['total_count']) > 0:
        if meta['is_ampliseq']:
            return data['objects'][0]['file']
        #api.post('log', upload='/rundb/api/v1/contentupload/%s/' % str(upload_id),
        #         text='Error: The file %s already exists. Please rename your file.'%bed_file)
        print 'ERROR: The file %s already exists. Please rename your file.' % bed_file
        sys.exit(1)

    result_UD_dir = os.path.join(base_path, meta['reference'], 'unmerged',
                                 'detail')
    result_UP_dir = os.path.join(base_path, meta['reference'], 'unmerged',
                                 'plain')
    result_MD_dir = os.path.join(base_path, meta['reference'], 'merged',
                                 'detail')
    result_MP_dir = os.path.join(base_path, meta['reference'], 'merged',
                                 'plain')
    if not os.path.exists(result_UD_dir):
        os.makedirs(result_UD_dir)
    if not os.path.exists(result_UP_dir):
        os.makedirs(result_UP_dir)
    if not os.path.exists(result_MD_dir):
        os.makedirs(result_MD_dir)
    if not os.path.exists(result_MP_dir):
        os.makedirs(result_MP_dir)
    #output_log = os.path.join(base_path, bed_file+'.log')
    output_json = os.path.join(base_path, bed_file + '.json')

    cmd = '/usr/local/bin/tvcutils validate_bed'
    cmd += '  --reference /results/referenceLibrary/tmap-f3/%s/%s.fasta' % (
        meta['reference'], meta['reference'])
    if bed_type == 'target regions BED':
        cmd += '  --target-regions-bed "%s"' % os.path.join(
            base_path, bed_file)
    elif bed_type == 'hotspots BED':
        cmd += '  --hotspots-bed "%s"' % os.path.join(base_path, bed_file)

    cmd += '  --unmerged-detail-bed "%s"' % os.path.join(
        result_UD_dir, bed_file)
    cmd += '  --unmerged-plain-bed "%s"' % os.path.join(
        result_UP_dir, bed_file)
    cmd += '  --merged-detail-bed "%s"' % os.path.join(result_MD_dir, bed_file)
    cmd += '  --merged-plain-bed "%s"' % os.path.join(result_MP_dir, bed_file)
    #cmd +=      '  --validation-log "%s"'       % output_log
    cmd += '  --meta-json "%s"' % output_json
    #print cmd
    p = subprocess.Popen(cmd,
                         stderr=subprocess.STDOUT,
                         stdout=subprocess.PIPE,
                         shell=True)
    print p.communicate()[0]
    #sys.stderr.write("=== -.- ===\n")
    #print stdout
    #print stderr

    #if os.path.exists(output_log):
    #  for line in open(output_log):
    #      api.post('log', upload='/rundb/api/v1/contentupload/%s/' % str(upload_id), text=line.strip())

    if os.path.exists(output_json):
        with open(output_json) as json_file:
            meta.update(json.load(json_file))

    if p.returncode != 0:
        sys.exit(p.returncode)

    return None
Example #4
0
	def get(self, endpoint, data=None):
		return get(VentataAPI.BASE_URL + endpoint, self.api_key, data)
Example #5
0
def validate(upload_id, base_path, meta, bed_file, bed_type):
    print("Validating %s file: %s" % (bed_type, bed_file))
    print()
    if meta["is_ampliseq"] and bed_file and not meta["reference"]:
        print(
            "ERROR: The Bed file (%s) exists without reference. Please check your ampliseq bundle "
            "or contact Technical Support." % bed_file)
        sys.exit(1)

    path_end = "/" + meta["reference"] + "/unmerged/detail/" + bed_file
    data, response, raw = api.get("content",
                                  publisher_name="BED",
                                  format="json",
                                  path__endswith=path_end)

    if int(data["meta"]["total_count"]) > 0:
        if meta["is_ampliseq"]:
            return data["objects"][0]["file"]
        # api.post('log', upload='/rundb/api/v1/contentupload/%s/' % str(upload_id),
        #         text='Error: The file %s already exists. Please rename your file.'%bed_file)
        print("ERROR: The file %s already exists. Please rename your file." %
              bed_file)
        sys.exit(1)

    result_UD_dir = os.path.join(base_path, meta["reference"], "unmerged",
                                 "detail")
    result_UP_dir = os.path.join(base_path, meta["reference"], "unmerged",
                                 "plain")
    result_MD_dir = os.path.join(base_path, meta["reference"], "merged",
                                 "detail")
    result_MP_dir = os.path.join(base_path, meta["reference"], "merged",
                                 "plain")
    if not os.path.exists(result_UD_dir):
        os.makedirs(result_UD_dir)
    if not os.path.exists(result_UP_dir):
        os.makedirs(result_UP_dir)
    if not os.path.exists(result_MD_dir):
        os.makedirs(result_MD_dir)
    if not os.path.exists(result_MP_dir):
        os.makedirs(result_MP_dir)

    # output_log = os.path.join(base_path, bed_file+'.log')
    output_json = os.path.join(base_path, bed_file + ".json")

    cmd = "/usr/local/bin/tvcutils validate_bed"
    cmd += "  --reference /results/referenceLibrary/tmap-f3/%s/%s.fasta" % (
        meta["reference"],
        meta["reference"],
    )
    if bed_type == publisher_types.TARGET:
        cmd += '  --target-regions-bed "%s"' % os.path.join(
            base_path, bed_file)
    elif bed_type == publisher_types.HOTSPOT:
        cmd += '  --hotspots-bed "%s"' % os.path.join(base_path, bed_file)
    elif bed_type == publisher_types.SSE:
        cmd += '  --hotspots-bed "%s"' % os.path.join(base_path, bed_file)

    cmd += '  --unmerged-detail-bed "%s"' % os.path.join(
        result_UD_dir, bed_file)
    cmd += '  --unmerged-plain-bed "%s"' % os.path.join(
        result_UP_dir, bed_file)
    cmd += '  --merged-detail-bed "%s"' % os.path.join(result_MD_dir, bed_file)
    cmd += '  --merged-plain-bed "%s"' % os.path.join(result_MP_dir, bed_file)
    # cmd +=      '  --validation-log "%s"'       % output_log
    cmd += '  --meta-json "%s"' % output_json
    # print cmd
    p = subprocess.Popen(cmd,
                         stderr=subprocess.STDOUT,
                         stdout=subprocess.PIPE,
                         shell=True)
    print(p.communicate()[0])
    # sys.stderr.write("=== -.- ===\n")
    # print stdout
    # print stderr

    # if os.path.exists(output_log):
    #  for line in open(output_log):
    #      api.post('log', upload='/rundb/api/v1/contentupload/%s/' % str(upload_id), text=line.strip())

    if os.path.exists(output_json):
        with open(output_json) as json_file:
            meta.update(json.load(json_file))

    if p.returncode != 0:
        sys.exit(p.returncode)

    return None