Write the continuous  dataset using sonic visualiser xml conventions
333189
def writexml(self, writer, indent="", addindent="", newl=""):
        
        # dataset = self.data.appendChild(self.doc.createElement('dataset'))
        # dataset.setAttribute('id', str(imodel))
        # dataset.setAttribute('dimensions', '2')
        writer.write('%s<dataset id="%s" dimensions="%s">%s' % (indent, self.datasetid, self.dimensions, newl))
        indent2 = indent + addindent
        for l, x, y in zip(self.labels, self.frames, self.values):
            writer.write('%s<point label="%s" frame="%d" value="%f"/>%s' % (indent2, self.int2label[l], x, y, newl))
        writer.write('%s</dataset>%s' % (indent, newl))
682809
def save_to_file(self, data, stamp):
        
        self.datafile.append(self.current_dataset_name, data)
        # save stimulu info
        info = dict(self._stimulus.componentDoc().items() + self._stimulus.testDoc().items())
        print 'saving doc', info
        info['time_stamps'] = [stamp]
        info['samplerate_ad'] = self.player.aifs
        self.datafile.append_trace_info(self.current_dataset_name, info)
326999
def generate_data(self, data_dir, tmp_dir, task_id=-1):
    """"""
    filepath_fns = {
        problem.DatasetSplit.TRAIN: self.training_filepaths,
        problem.DatasetSplit.EVAL: self.dev_filepaths,
        problem.DatasetSplit.TEST: self.test_filepaths,
    }

    # We set shuffled=True as we don't want to shuffle on disk later.
    split_paths = [(split["split"], filepath_fns[split["split"]](
        data_dir, split["shards"], shuffled=True))
                   for split in self.dataset_splits]
    all_paths = []
    for _, paths in split_paths:
      all_paths.extend(paths)

    if self.is_generate_per_split:
      for split, paths in split_paths:
        generator_utils.generate_files(
            self.generate_encoded_samples(data_dir, tmp_dir, split),
            paths,
            cycle_every_n=self.total_number_of_frames // len(paths))
    else:
      generator_utils.generate_files(
          self.generate_encoded_samples(data_dir, tmp_dir,
                                        problem.DatasetSplit.TRAIN),
          all_paths,
          cycle_every_n=self.total_number_of_frames // len(all_paths))
171806
public static void write(IDataSet dataSet, Writer writer) throws DataSetException {
		logger.debug("write(dataSet={}, writer={}) - start", dataSet, writer);
		write(dataSet, writer, null);
	}
587463
def write_data_set(file_path, dataset, output_dir, color_array_info, new_name=None, compress=True):
    """"""
    fileName = new_name if new_name else os.path.basename(file_path)
    dataset_dir = os.path.join(output_dir, fileName)
    data_dir = os.path.join(dataset_dir, 'data')

    if not os.path.exists(data_dir):
        os.makedirs(data_dir)

    root = {}
    root['metadata'] = {}
    root['metadata']['name'] = fileName

    writer = writer_mapping[dataset.GetClassName()]
    if writer:
        writer(dataset_dir, data_dir, dataset, color_array_info, root, compress)
    else:
        print(dataObject.GetClassName(), 'is not supported')

    with open(os.path.join(dataset_dir, "index.json"), 'w') as f:
        f.write(json.dumps(root, indent=2))

    return dataset_dir
254311
function Dataset(sc, dependencies) {
  this.id = sc.datasetIdCounter++;
  this.dependencies = dependencies || [];
  this.persistent = false;
  this.sc = sc;
}
832738
def _write(self, session, openFile, maskMap):
        
        # Magic numbers
        FIRST_VALUE_INDEX = 12

        # Write the header
        openFile.write('DATASET\r\n')

        if self.type == self.SCALAR_TYPE:
            openFile.write('OBJTYPE {0}\r\n'.format(self.objectType))
            openFile.write('BEGSCL\r\n')

        elif self.type == self.VECTOR_TYPE:
            openFile.write('VECTYPE {0}\r\n'.format(self.vectorType))
            openFile.write('BEGVEC\r\n')

        openFile.write('OBJID {0}\r\n'.format(self.objectID))
        openFile.write('ND {0}\r\n'.format(self.numberData))
        openFile.write('NC {0}\r\n'.format(self.numberCells))
        openFile.write('NAME {0}\r\n'.format(self.name))

        # Retrieve the mask map to use as the status rasters
        statusString = ''
        if isinstance(maskMap, RasterMapFile):
            # Convert Mask Map to GRASS ASCII Raster
            statusGrassRasterString = maskMap.getAsGrassAsciiGrid(session)

            if statusGrassRasterString is not None:
                # Split by lines
                statusValues = statusGrassRasterString.split()
            else:
                statusValues = maskMap.rasterText.split()

            # Assemble into a string in the WMS Dataset format
            for i in range(FIRST_VALUE_INDEX, len(statusValues)):
                statusString += statusValues[i] + '\r\n'

        # Write time steps
        for timeStepRaster in self.rasters:
            # Write time step header
            openFile.write('TS {0} {1}\r\n'.format(timeStepRaster.iStatus, timeStepRaster.timestamp))

            # Write status raster (mask map) if applicable
            if timeStepRaster.iStatus == 1:
                openFile.write(statusString)

            # Write value raster
            valueString = timeStepRaster.getAsWmsDatasetString(session)

            if valueString is not None:
                openFile.write(valueString)

            else:
                openFile.write(timeStepRaster.rasterText)

        # Write ending tag for the dataset
        openFile.write('ENDDS\r\n')
1192463
def _preprocess_data(audio_data, verbose=True):
        '''
        
        '''
        from .vggish_input import waveform_to_examples

        last_progress_update = _time.time()
        progress_header_printed = False

        # Can't run as a ".apply(...)" due to numba.jit decorator issue:
        # https://github.com/apple/turicreate/issues/1216
        preprocessed_data, audio_data_index = [], []
        for i, audio_dict in enumerate(audio_data):
            scaled_data = audio_dict['data'] / 32768.0
            data = waveform_to_examples(scaled_data, audio_dict['sample_rate'])

            for j in data:
                preprocessed_data.append([j])
                audio_data_index.append(i)

            # If `verbose` is set, print an progress update about every 20s
            if verbose and _time.time() - last_progress_update >= 20:
                if not progress_header_printed:
                    print("Preprocessing audio data -")
                    progress_header_printed = True
                print("Preprocessed {} of {} examples".format(i, len(audio_data)))
                last_progress_update = _time.time()

        if progress_header_printed:
            print("Preprocessed {} of {} examples\n".format(len(audio_data), len(audio_data)))
        return _np.asarray(preprocessed_data), audio_data_index
511660
def draw(filestems, gformat):
    
    # Draw heatmaps
    for filestem in filestems:
        fullstem = os.path.join(args.outdirname, filestem)
        outfilename = fullstem + ".%s" % gformat
        infilename = fullstem + ".tab"
        df = pd.read_csv(infilename, index_col=0, sep="\t")
        logger.info("Writing heatmap to %s", outfilename)
        params = pyani_graphics.Params(
            params_mpl(df)[filestem],
            pyani_tools.get_labels(args.labels),
            pyani_tools.get_labels(args.classes),
        )
        if args.gmethod == "mpl":
            pyani_graphics.heatmap_mpl(
                df, outfilename=outfilename, title=filestem, params=params
            )
        elif args.gmethod == "seaborn":
            pyani_graphics.heatmap_seaborn(
                df, outfilename=outfilename, title=filestem, params=params
            )
576378
def write_output_files(self):
        
        os.mkdir("analysis")
        os.chdir("analysis")
        os.mkdir("hydrogen_bonds")
        os.chdir("hydrogen_bonds")
        for traj in range(len(self.trajectory)):
            with open('hbonds_data_total_'+str(traj)+'.csv', 'wb') as outfile:
                hwriter = csv.writer(outfile, delimiter=' ')
                for time in self.hbonds_by_time[traj]:
                    hwriter.writerow([time[0],time[1]])
            for bond in self.hbonds_by_type[traj]:
                if bond["donor_resnm"]=="LIG" and (bond["acceptor_idx"],bond["donor_idx"]) in [(k[0],k[3]) for k,v in self.hbonds_for_drawing.items()]:
                    with open('hbond_'+bond["acceptor_resnm"]+"_"+str(bond["acceptor_resid"])+"_"+bond["donor_atom"]+"_"+str(traj)+".csv","wb") as outfile:
                        hwriter = csv.writer(outfile, delimiter=' ')
                        for time in self.hbonds_timesteps[traj]:
                            result = [1 if x[0]==time and x["acceptor_idx"]==bond["acceptor_idx"] else 0 for x in self.hbonds[traj]][0]
                            hwriter.writerow([time,result])
                if bond["donor_resnm"]!="LIG" and (bond["donor_idx"],bond["acceptor_idx"]) in [(k[0],k[3]) for k,v in self.hbonds_for_drawing.items()]:
                    with open('hbond_'+bond["donor_resnm"]+"_"+str(bond["donor_resid"])+"_"+bond["acceptor_atom"]+"_"+str(traj)+".csv","wb") as outfile:
                        hwriter = csv.writer(outfile, delimiter=' ')
                        for time in self.hbonds_timesteps[traj]:
                            result = [1 if x[0]==time and x["donor_idx"]==bond["donor_idx"] else 0 for x in self.hbonds[traj]][0]
                            hwriter.writerow([time,result])
        os.chdir("../../")
1031423
def plotImagesWithNoise(suite, noise_values, plotPath):
  
  datadir = suite.cfgparser.defaults()["datadir"]

  transform = transforms.Compose([transforms.ToTensor(),
                                  transforms.Normalize((0.1307,), (0.3081,))])
  dataset = datasets.MNIST(datadir, train=False, download=True,
                           transform=transform)

  num_noise = len(noise_values)
  fig = plt.figure(figsize=(num_noise, 4))
  for y in range(4):
    for x in range(num_noise):
      transform.transforms.append(
        RandomNoise(noise_values[x], whiteValue=0.1307 + 2 * 0.3081))
      img, _ = dataset[y]
      transform.transforms.pop()

      ax = fig.add_subplot(4, num_noise, y * num_noise + x + 1)
      ax.set_axis_off()
      ax.imshow(img.numpy().reshape((28, 28)), cmap='gray')
      if y == 0:
        ax.set_title("{0}%".format(noise_values[x] * 100))

  plt.tight_layout()
  plt.savefig(plotPath)
  plt.close()
1014654
def display_workflows(prefix, **kwargs):
    
    from IPython.display import display, Markdown

    def create_svg(name, workflow):
        """Create an SVG file with rendered graph from a workflow."""
        name = name.replace('_', '-')
        filename = '{}-{}.svg'.format(prefix, name)
        dot = get_workflow_graph(workflow)
        dot.attr('graph', bgcolor='transparent')
        with open(filename, 'bw') as file:
            file.write(dot.pipe(format='svg'))
        return name, filename

    svg_files = {name: svg for name, svg in
                 (create_svg(name, workflow)
                  for name, workflow in kwargs.items())}

    markdown_table = \
        '| ' + ' | '.join(svg_files.keys()) + ' |\n' + \
        '| ' + ' | '.join('---' for _ in svg_files) + ' |\n' + \
        '| ' + ' | '.join('![workflow {}]({})'.format(name, svg)
                          for name, svg in svg_files.items()) + ' |'
    display(Markdown(markdown_table))
282288
protected void writeSceneData (SimpleMisoSceneModel model,
                                   DataWriter writer)
        throws SAXException
    {
        writer.dataElement("width", Integer.toString(model.width));
        writer.dataElement("height", Integer.toString(model.height));
        writer.dataElement("viewwidth", Integer.toString(model.vwidth));
        writer.dataElement("viewheight", Integer.toString(model.vheight));
        writer.dataElement("base",
                           StringUtil.toString(model.baseTileIds, "", ""));

        // write our uninteresting object tile information
        writer.startElement("objects");
        for (int ii = 0; ii < model.objectTileIds.length; ii++) {
            AttributesImpl attrs = new AttributesImpl();
            attrs.addAttribute("", "tileId", "", "",
                               String.valueOf(model.objectTileIds[ii]));
            attrs.addAttribute("", "x", "", "",
                               String.valueOf(model.objectXs[ii]));
            attrs.addAttribute("", "y", "", "",
                               String.valueOf(model.objectYs[ii]));
            writer.emptyElement("", "object", "", attrs);
        }

        // write our uninteresting object tile information
        for (ObjectInfo info : model.objectInfo) {
            AttributesImpl attrs = new AttributesImpl();
            attrs.addAttribute("", "tileId", "", "",
                               String.valueOf(info.tileId));
            attrs.addAttribute("", "x", "", "", String.valueOf(info.x));
            attrs.addAttribute("", "y", "", "", String.valueOf(info.y));

            if (!StringUtil.isBlank(info.action)) {
                attrs.addAttribute("", "action", "", "", info.action);
            }

            if (info.priority != 0) {
                attrs.addAttribute("", "priority", "", "",
                                   String.valueOf(info.priority));
            }

            if (info.sx != 0 || info.sy != 0) {
                attrs.addAttribute("", "sx",  "", "",
                                   String.valueOf(info.sx));
                attrs.addAttribute("", "sy",  "", "",
                                   String.valueOf(info.sy));
                attrs.addAttribute("", "sorient",  "", "",
                                   String.valueOf(info.sorient));
            }

            if (info.zations != 0) {
                attrs.addAttribute("", "zations",  "", "",
                                   String.valueOf(info.zations));
            }
            writer.emptyElement("", "object", "", attrs);
        }
        writer.endElement("objects");
    }
604051
def scrobble_data_dir(dataDir, sampleMap, outF, qualF=None, idopt=None,
                      utf16=False):
    
    seqcount = 0
    outfiles = [osp.split(outF.name)[1]]
    if qualF:
        outfiles.append(osp.split(qualF.name)[1])

    for item in os.listdir(dataDir):
        if item in outfiles or not osp.isfile(os.path.join(dataDir, item)):
            continue
        # FASTA files
        if osp.splitext(item)[1] in file_types['fasta']:
            fh = open_enc(os.path.join(dataDir, item), utf16)
            records = SeqIO.parse(fh, 'fasta')
            for record in records:
                if isinstance(idopt, tuple):
                    sep, field = idopt
                    sampleID = record.id.split(sep)[field - 1]
                else:
                    sampleID = osp.splitext(item)[0]
                record.seq = (sampleMap[sampleID].barcode +
                              sampleMap[sampleID].primer +
                              record.seq)
                SeqIO.write(record, outF, 'fasta')
                seqcount += 1
            fh.close()
        # QUAL files
        elif qualF and osp.splitext(item)[1] in file_types['qual']:
            fh = open_enc(os.path.join(dataDir, item), utf16)
            records = SeqIO.parse(fh, 'qual')
            for record in records:
                mi = sampleMap[sampleMap.keys()[0]]
                quals = [40 for _ in range(len(mi.barcode) + len(mi.primer))]
                record.letter_annotations['phred_quality'][0:0] = quals
                SeqIO.write(record, qualF, 'qual')
            fh.close()
    return seqcount
190025
function () {
      var rowCounts = new Uint32Array(nrows);
      var columnCounts = new Uint32Array(ncols);
      for (var i = 0; i < nrows; i++) {
        var obj = matrix[i];
        if (obj.values != null) {
          // trim to size
          var values = new Uint16Array(obj.length);
          var indices = new Uint32Array(obj.length);
          values.set(obj.values.slice(0, obj.length));
          indices.set(obj.indices.slice(0, obj.length));
          matrix[i] = {values: values, indices: indices};
          rowCounts[i] = values.length;
          for (var j = 0; j < obj.length; j++) {
            columnCounts[indices[j]] += 1;
          }
        }
      }
      dataset = new morpheus.Dataset({
        rows: nrows, columns: ncols, name: morpheus.Util.getBaseFileName(morpheus.Util
          .getFileName(fileOrUrl)), array: matrix, dataType: dataType, defaultValue: 0
      });

      dataset.getRowMetadata().add('count>0').array = rowCounts;
      dataset.getColumnMetadata().add('count>0').array = columnCounts;
    }
1198559
def write_xml(self, xmlfile, config=None):
        """"""

        root = ElementTree.Element('source_library')
        root.set('title', 'source_library')

        for s in self._srcs:
            s.write_xml(root)

        if config is not None:
            srcs = self.create_diffuse_srcs(config)
            diffuse_srcs = {s.name: s for s in srcs}
            for s in self._diffuse_srcs:
                src = copy.deepcopy(diffuse_srcs.get(s.name, s))
                src.update_spectral_pars(s.spectral_pars)
                src.write_xml(root)
        else:
            for s in self._diffuse_srcs:
                s.write_xml(root)

        output_file = open(xmlfile, 'w')
        output_file.write(utils.prettify_xml(root))
1160970
public void getDataDTD(Writer output) throws DataTaskException
    {
        try
        {
            output.write("<!ELEMENT dataset (\n");
            for (Iterator it = _preparedModel.getElementNames(); it.hasNext();)
            {
                String elementName = (String)it.next();

                output.write("    ");
                output.write(elementName);
                output.write("*");
                output.write(it.hasNext() ? " |\n" : "\n");
            }
            output.write(")>\n<!ATTLIST dataset\n    name CDATA #REQUIRED\n>\n");
            for (Iterator it = _preparedModel.getElementNames(); it.hasNext();)
            {
                String elementName = (String)it.next();
                List   classDescs  = _preparedModel.getClassDescriptorsMappingTo(elementName);

                if (classDescs == null)
                {
                    output.write("\n<!-- Indirection table");
                }
                else
                {
                    output.write("\n<!-- Mapped to : ");
                    for (Iterator classDescIt = classDescs.iterator(); classDescIt.hasNext();)
                    {
                        ClassDescriptor classDesc = (ClassDescriptor)classDescIt.next();
    
                        output.write(classDesc.getClassNameOfObject());
                        if (classDescIt.hasNext())
                        {
                            output.write("\n                 ");
                        }
                    }
                }
                output.write(" -->\n<!ELEMENT ");
                output.write(elementName);
                output.write(" EMPTY>\n<!ATTLIST ");
                output.write(elementName);
                output.write("\n");

                for (Iterator attrIt = _preparedModel.getAttributeNames(elementName); attrIt.hasNext();)
                {
                    String attrName = (String)attrIt.next();

                    output.write("    ");
                    output.write(attrName);
                    output.write(" CDATA #");
                    output.write(_preparedModel.isRequired(elementName, attrName) ? "REQUIRED" : "IMPLIED");
                    output.write("\n");
                }
                output.write(">\n");
            }
        }
        catch (IOException ex)
        {
            throw new DataTaskException(ex);
        }
    }