Download anatomical data and convert to BIDS
168505
def proc_anat(config, args):
    '''
    
    '''
    refs = dict()
    for scan in iterconfig(config, 'anat'):
        ref = scan.get('id', None)
        templ = 'sub-${sub}_ses-${ses}'
        if 'acquisition' in scan:
            templ += '_acq-${acquisition}'
        if 'run' in scan:
            templ += '_run-${run}'
        templ += '_${modality}'
        templ = string.Template(templ)
        fbase = templ.safe_substitute(
            sub=legal.sub('', args.subject),
            ses=legal.sub('', args.session),
            acquisition=scan.get('acquisition', None),
            run=scan.get('run', None),
            modality=scan.get('modality', None),
        )
        # download data to bids sourcedata directory
        sourcedata_dir = os.path.join(args.sourcedata, scan['type'])
        if not os.path.exists(sourcedata_dir):
            os.makedirs(sourcedata_dir)
        dicom_dir = os.path.join(sourcedata_dir, '{0}.dicom'.format(fbase))
        logger.info('downloading session=%s, scan=%s, loc=%s', args.session, scan['scan'], dicom_dir)
        args.xnat.download(args.session, [scan['scan']], out_dir=dicom_dir)
        # convert to nifti
        fname = '{0}.nii.gz'.format(fbase)
        refs[ref] = os.path.join(scan['type'], fname)
        fullfile = os.path.join(args.bids, scan['type'], fname)
        logger.info('converting %s to %s', dicom_dir, fullfile)
        convert(dicom_dir, fullfile)
    return refs
636428
def download(csvpath, asset_manager_id, data_id_type, data_id_list):
        """"""
        interface = interface_direct_csvpath(csvpath)
        logging.config.dictConfig(DEFAULT_LOGGING)
        logger = logging.getLogger(__name__)
        objs = []
        for data_id in data_id_list:
            Dict = dict()
            Dict[data_id_type] = data_id
            objs.append(interface.retrieve(asset_manager_id=asset_manager_id, **Dict))
        return objs
739390
def split_request(start_dt, end_dt, player_id, url):
    
    current_dt = datetime.datetime.strptime(start_dt, '%Y-%m-%d')
    end_dt = datetime.datetime.strptime(end_dt, '%Y-%m-%d')
    results = []  # list to hold data as it is returned
    player_id = str(player_id)
    print('Gathering Player Data')
    # break query into multiple requests
    while current_dt < end_dt:
        remaining = end_dt - current_dt
        # increment date ranges by at most 60 days
        delta = min(remaining, datetime.timedelta(days=2190))
        next_dt = current_dt + delta
        start_str = current_dt.strftime('%Y-%m-%d')
        end_str = next_dt.strftime('%Y-%m-%d')
        # retrieve data
        data = requests.get(url.format(start_str, end_str, player_id))
        df = pd.read_csv(io.StringIO(data.text))
        # add data to list and increment current dates
        results.append(df)
        current_dt = next_dt + datetime.timedelta(days=1)
    return pd.concat(results)
1308576
function buildRequests(validBidRequests, bidderRequest) {
  const bids = validBidRequests.map(requestsToBids);
  const bidObject = {'bids': bids};
  const pageInfo = getPageInfo();

  const payload = Object.assign(bidObject, pageInfo);

  if (bidderRequest && bidderRequest.gdprConsent) {
    payload.gdprConsent = {
      consentString: bidderRequest.gdprConsent.consentString,
      consentRequired: bidderRequest.gdprConsent.gdprApplies
    };
  }

  const payloadString = JSON.stringify(payload);

  return {
    method: 'POST',
    url: ENDPOINT,
    data: payloadString
  }
}
610222
def download_unicodedata(version, output=HOME, no_zip=False):
    """"""
    files = [
        'UnicodeData.txt',
        'Scripts.txt',
        'Blocks.txt',
        'PropList.txt',
        'DerivedCoreProperties.txt',
        'DerivedNormalizationProps.txt',
        'CompositionExclusions.txt',
        'PropertyValueAliases.txt',
        'PropertyAliases.txt',
        'EastAsianWidth.txt',
        'LineBreak.txt',
        'HangulSyllableType.txt',
        'DerivedAge.txt',
        'auxiliary/WordBreakProperty.txt',
        'auxiliary/SentenceBreakProperty.txt',
        'auxiliary/GraphemeBreakProperty.txt',
        'extracted/DerivedDecompositionType.txt',
        'extracted/DerivedNumericType.txt',
        'extracted/DerivedNumericValues.txt',
        'extracted/DerivedJoiningType.txt',
        'extracted/DerivedJoiningGroup.txt',
        'extracted/DerivedCombiningClass.txt'
    ]

    files.append('ScriptExtensions.txt')
    if PY35:
        files.append('IndicPositionalCategory.txt')
    else:
        files.append('IndicMatraCategory.txt')
    files.append('IndicSyllabicCategory.txt')

    if PY34:
        files.append('BidiBrackets.txt')

    if PY37:
        files.append('VerticalOrientation.txt')

    http_url = 'http://www.unicode.org/Public/%s/ucd/' % version
    ftp_url = 'ftp://ftp.unicode.org/Public/%s/ucd/' % version

    destination = os.path.join(output, 'unicodedata', version)
    if not os.path.exists(destination):
        os.makedirs(destination)

    zip_data = not no_zip

    for f in files:
        file_location = os.path.join(destination, os.path.basename(f))
        retrieved = False
        if not os.path.exists(file_location):
            for url in (ftp_url, http_url):
                furl = url + f
                try:
                    print('Downloading: %s --> %s' % (furl, file_location))
                    response = urlopen(furl, timeout=30)
                    data = response.read()
                except Exception:
                    print('Failed: %s' % url)
                    continue
                with open(file_location, 'w') as uf:
                    uf.write(data.decode('utf-8'))
                retrieved = True
                break
            if not retrieved:
                print('Failed to acquire all needed Unicode files!')
                break
        else:
            retrieved = True
            print('Skipping: found %s' % file_location)

        if not retrieved:
            zip_data = False
            break

    if zip_data and not os.path.exists(os.path.join(output, 'unicodedata', '%s.zip' % version)):
        zip_unicode(output, version)
707761
function(bidRequests, bidderRequest) {
    const userId = find(bidRequests, hasUserId);
    const pubcid = find(bidRequests, hasPubcid);
    const publisherId = find(bidRequests, hasPublisherId);
    const auctionId = find(bidRequests, hasAuctionId);
    let bidUrl = find(bidRequests, hasBidUrl);
    let url = find(bidRequests, hasUrl);
    let test = find(bidRequests, hasTestParam);
    const seats = find(bidRequests, hasSeatsParam);
    const deviceId = find(bidRequests, hasDeviceIdParam);
    const ifa = find(bidRequests, hasIfaParam);
    const tid = find(bidRequests, hasTidParam);
    bidUrl = bidUrl ? bidUrl.params.bidUrl : URL;
    url = url ? url.params.url : (config.getConfig('pageUrl') || utils.getTopWindowUrl());
    test = test ? test.params.test : undefined;
    var adRequests = bidRequests.map(bidToAdRequest);

    const payload = {
      auctionId: auctionId ? auctionId.auctionId : undefined,
      publisherId: publisherId ? publisherId.params.publisherId : undefined,
      userId: userId ? userId.params.userId : (pubcid ? pubcid.crumbs.pubcid : undefined),
      url: url,
      test: test,
      seats: seats ? seats.params.seats : undefined,
      deviceId: deviceId ? deviceId.params.deviceId : undefined,
      ifa: ifa ? ifa.params.ifa : undefined,
      tid: tid ? tid.params.tid : undefined,
      version: VERSION,
      gdprApplies: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.gdprApplies : undefined,
      gdprConsent: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.consentString : undefined,
      cookieSupport: !utils.isSafariBrowser() && utils.cookiesAreEnabled(),
      rcv: getAdblockerRecovered(),
      adRequests: [...adRequests]
    };
    const payloadString = JSON.stringify(payload);
    return {
      method: 'POST',
      url: bidUrl,
      data: payloadString,
    };
  }
393963
def fetch():
    
    doi = '10.7910/DVN/VBSI4A'
    
    for component in ['dust', 'err']:
        requirements = {'filename': 'PG_{}_4096_ngp.fits'.format(component)}
        local_fname = os.path.join(
            data_dir(),
            'pg2010', 'PG_{}_4096_ngp.fits'.format(component))
        print('Downloading P&G (2010) {} data file to {}'.format(
            component, local_fname))
        fetch_utils.dataverse_download_doi(
            doi,
            local_fname,
            file_requirements=requirements)
29247
def download_data():
    """"""

    n_datasets = 2
    for d in range(1, n_datasets + 1):
        if not os.path.isdir('enron%d' % d):

            URL = url[d-1]
            print("Downloading %d/%d: %s" % (d, n_datasets, URL))
            folderzip = 'enron%d.zip' % d

            with urlopen(URL) as remotedata:
                with open(folderzip, 'wb') as z:
                    z.write(remotedata.read())

            with ZipFile(folderzip) as z:
                z.extractall()
            os.remove(folderzip)
390862
def download_structure(inputpdbid):
    """"""
    try:
        if len(inputpdbid) != 4 or extract_pdbid(inputpdbid.lower()) == 'UnknownProtein':
            sysexit(3, 'Invalid PDB ID (Wrong format)\n')
        pdbfile, pdbid = fetch_pdb(inputpdbid.lower())
        pdbpath = tilde_expansion('%s/%s.pdb' % (config.BASEPATH.rstrip('/'), pdbid))
        create_folder_if_not_exists(config.BASEPATH)
        with open(pdbpath, 'w') as g:
            g.write(pdbfile)
        write_message('file downloaded as %s\n\n' % pdbpath)
        return pdbpath, pdbid

    except ValueError:  # Invalid PDB ID, cannot fetch from RCBS server
        sysexit(3, 'Invalid PDB ID (Entry does not exist)\n')
110764
function (bidRequests, bidderRequest) {
    return {
      data: bidToTag(bidRequests, bidderRequest),
      bidderRequest,
      method: 'GET',
      url: URL
    };
  }
1230302
def from_dict(data, ctx):
        

        data = data.copy()

        if data.get('bid') is not None:
            data['bid'] = \
                ctx.instrument.CandlestickData.from_dict(
                    data['bid'], ctx
                )

        if data.get('ask') is not None:
            data['ask'] = \
                ctx.instrument.CandlestickData.from_dict(
                    data['ask'], ctx
                )

        if data.get('mid') is not None:
            data['mid'] = \
                ctx.instrument.CandlestickData.from_dict(
                    data['mid'], ctx
                )

        return Candlestick(**data)
478174
def get_raw_data_from_url(pdb_id, reduced=False):
    "
    url = get_url(pdb_id,reduced)
    request = urllib2.Request(url)
    request.add_header('Accept-encoding', 'gzip')
    response = urllib2.urlopen(request)
    if response.info().get('Content-Encoding') == 'gzip':
        data = ungzip_data(response.read())
    else:
        data = response.read()
    return _unpack(data)
1273945
def existing(self):
        
        catalog = api.portal.get_tool('portal_catalog')
        results = []
        layout_path = self._get_layout_path(
            self.request.form.get('layout', '')
        )
        for brain in catalog(layout=layout_path):
            results.append({
                'title': brain.Title,
                'url': brain.getURL()
            })
        return json.dumps({
            'total': len(results),
            'data': results
        })
948664
def download(dataset, node, entityids, products, api_key=None):
    

    payload = {
        "datasetName": dataset,
        "node": node,
        "apiKey": api_key,
        "entityIds": entityids,
        "products": products
    }

    return json.dumps(payload)
175339
def _parse_gene_anatomy(self, fh, limit):
        
        dataframe = pd.read_csv(fh, sep='\t')
        col = self.files['anat_entity']['columns']
        if list(dataframe) != col:
            LOG.warning(
                '\nExpected headers:  %s\nRecived headers:  %s', col, list(dataframe))

        gene_groups = dataframe.sort_values(
            'rank score', ascending=False).groupby('Ensembl gene ID')

        if limit is None:
            limit = 20
        gene_groups = gene_groups.head(limit).groupby('Ensembl gene ID')

        for gene, group in gene_groups:
            for index, row in group.iterrows():
                self._add_gene_anatomy_association(
                    row['Ensembl gene ID'].strip(),
                    row['anatomical entity ID'].strip(),
                    row['rank score']
                )
                # uberon <==> bto equivelance?
        return
1034215
def _get_display_data_with_images(data, images):
  """"""

  if not images:
    return data

  display_data = copy.deepcopy(data)
  for img_col in images:
    for d, im in zip(display_data, images[img_col]):
      if im == '':
        d[img_col + '_image'] = ''
      else:
        im = im.copy()
        im.thumbnail((128, 128), Image.ANTIALIAS)
        buf = BytesIO()
        im.save(buf, "PNG")
        content = base64.b64encode(buf.getvalue()).decode('ascii')
        d[img_col + '_image'] = content

  return display_data
433744
def data(cls, cube, weighted, prune):
        """"""
        return cls()._data(cube, weighted, prune)