code
stringlengths
1
18.2k
> 1 else "", "were" if nb_all_hetero > 1 else "was") ) print >>o_file, latex_template.wrap_lines(text, 80) except IOError: msg = "{}: cannot write LaTeX summary".format(latex_file) raise ProgramError(msg) # Writing the summary results with open(os.path.join(base_dir, "results_summary.txt"), "a") as o_file: print >>o_fi...
def run_sample_missingness(in_prefix, in_type, out_prefix, base_dir, options): """Runs step4 (clean mind). :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: the options needed. :type ...
Creating the output directory os.mkdir(out_prefix) # We are looking at what we have required_type = "tfile" if in_type == "bfile": required_type = "bfile" check_input_files(in_prefix, in_type, required_type) # We need to inject the name of the input file and the name of the output # prefix script_prefix = os.path.join(...
desc[:-1] + r" (${}={}$).".format(latex_template.texttt("mind"), mind_value) long_description = sample_missingness.long_desc.format( success_rate="{:.1f}".format((1-float(mind_value)) * 100), ) # We want to save in a file the samples that were removed # There is one file to look at, which contains only one row, the nam...
{} ({} keeping only samples with " r"a missing rate $\leq {}$), {:,d} sample{} {} excluded " "from the dataset.".format( latex_template.texttt("mind"), mind_value, latex_template.textit("i.e."), mind_value, nb_samples, "s" if nb_samples > 1 else "", "were" if nb_samples > 1 else "was", )) print >>o_file, latex_template...
def run_contamination(in_prefix, in_type, out_prefix, base_dir, options): """Runs the contamination check for samples. :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: the options ne...
["--{}".format(required_type), in_prefix, "--out", script_prefix] # We run the script try: contamination.main(options) except contamination.ProgramError as e: msg = "contamination: {}".format(e) raise ProgramError(msg) # Counting the number of markers used for contamination nb_autosomal = 0 with open(script_prefix + "....
# Reading the data estimate = float(row[header["estimate"]]) if estimate > 0.01: # This might be a contaminated samples contaminated_table.append(( latex_template.sanitize_tex(row[header["sample"]]), "{:.4f}".format(float(row[header["estimate"]])), "{:.4f}".format(float(row[header["stderr"]])), "{:.4f}".format(float(ro...
"was", bafRegress="{bafRegress}", )) print >>o_file, latex_template.wrap_lines(text) if nb_contaminated_samples > 0: label = re.sub(r"[/\\]", "_", script_prefix) text = ( r"Table~\ref{" + label + "} list all the samples that " r"were estimated to be contaminated (\textit{i.e.} with " r"an estimate $>0.01$)." ) print >>...
print >>o_file, "# {}".format(script_prefix) print >>o_file, ("Number of possibly contaminated " "samples\t{:,d}".format(nb_contaminated_samples)) print >>o_file, "---" # We know this step doesn't produce an new data set, so we return the old # prefix and the old in_type return _StepResult( next_file=in_prefix, next_fi...
def run_sex_check(in_prefix, in_type, out_prefix, base_dir, options): """Runs step6 (sexcheck). :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: the options needed. :type in_prefix: ...
output files. Hence, this function returns the input file prefix and its type. """ # Creating the output directory os.mkdir(out_prefix) # We know we need a bfile required_type = "bfile" check_input_files(in_prefix, in_type, required_type) # We need to inject the name of the input file and the name of the output # prefi...
{}".format( script_prefix + ".chr23_recodeA.raw.hetero", required_col, ) raise ProgramError(msg) # Reading the data for line in i_file: row = line.rstrip("\r\n").split("\t") famid = row[header["PED"]] indid = row[header["ID"]] # Formatting the hetero value het = None try: het = "{:.4f}".format(float(row[header["HETERO"...
row[header["nbGeno"]] nb_nocall = row[header["nbNoCall"]] percent = None try: percent = "{:.4f}".format( float(nb_nocall) / float(nb_geno), ) except: percent = "N/A" nb_no_call[(famid, indid)] = percent # Reading the problem file to gather statistics. Note that dataset without # problem will only have the header line (...
1 # Creating the row row = line.rstrip("\r\n").split("\t") # Counting if row[header["SNPSEX"]] == "0": nb_no_genetic += 1 else: nb_discordant += 1 table.append([ latex_template.sanitize_tex(row[header[name]]) for name in ("FID", "IID", "PEDSEX", "SNPSEX", "STATUS", "F") ]) table[-1].append( hetero.get((row[header["FID"...
according to Plink.".format( male_f=male_f, female_f=female_f, nb_problems=nb_problems, plural="s" if nb_problems > 1 else "", ) ) print >>o_file, latex_template.wrap_lines(text) # The float template float_template = latex_template.jinja2_env.get_template( "float_template.tex", ) if nb_problems > 0: # The label and tex...
item: item[1]), ) # Getting the templates graphic_template = latex_template.jinja2_env.get_template( "graphics_template.tex", ) # If there is a figure, we add it here if os.path.isfile(script_prefix + ".png"): # Adding the figure figure_label = re.sub(r"[/\\]", "_", script_prefix) text = ( r"Figure~\ref{" + figure_labe...
gray.", float_label=figure_label, float_content=graphic_template.render( width=r"0.8\textwidth", path=latex_template.sanitize_fig_name(path), ), ) # Adding the path where the graphic is graphics_paths.add(graphics_path) # If there is a 'sexcheck.LRR_BAF' directory, then there are LRR # and BAF plots. if os.path.isdir(s...
= "" if len(figures) > 1: fig_2 = labels[-1] text = ( "Figure" + ("s" if len(figures) > 1 else "") + r"~\ref{" + fig_1 + "} " + (r"to \ref{" + fig_2 + "} " if fig_2 else "") + "show" + (" " if len(figures) > 1 else "s ") + "the " "log R ratio and the B allele frequency versus the " "position on chromosome X and Y for t...
for chromosome X and Y (on the left " "and right, respectively) for sample " "{}.".format(sample_id) ) print >>o_file, float_template.render( float_type="figure", float_placement="H", float_caption=caption, float_label=label, float_content=graphic_template.render( width=r"\textwidth", path=latex_template.sanitize_fig_n...
def run_plate_bias(in_prefix, in_type, out_prefix, base_dir, options): """Runs step7 (plate bias). :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: the options needed. :type in_prefi...
usable output files. Hence, this function returns the input file prefix and its type. """ # Creating the output directory os.mkdir(out_prefix) # We know we need bfile required_type = "bfile" check_input_files(in_prefix, in_type, required_type) # We need to inject the name of the input file and the name of the output # ...
in header: msg = "{}: missing column plate".format(filename) raise ProgramError(msg) # Counting the number of markers for each plate plate_counter = Counter( line.rstrip("\r\n").split("\t")[header["plate"]] for line in i_file ) # Creating the table table = [["plate name", "number of markers"]] for plate_name, number in...
unique marker{} had a significant result " "({} a value less than {}).".format( nb_markers, "s" if nb_markers > 1 else "", r"\textit{i.e.}", latex_template.format_numbers(p_threshold), ) ) print >>o_file, latex_template.wrap_lines(text) if nb_markers > 0: table_label = re.sub( r"[/\\]", "_", script_prefix, ) + "_plate_...
col_alignments="lr", text_size="normalsize", header_data=zip(table[0], [1 for i in table[0]]), tabular_data=table[1:], ) except IOError: msg = "{}: cannot write LaTeX summary".format(latex_file) raise ProgramError(msg) # Writing the summary results with open(os.path.join(base_dir, "results_summary.txt"), "a") as o_file...
def run_remove_heterozygous_haploid(in_prefix, in_type, out_prefix, base_dir, options): """Runs step8 (remove heterozygous haploid). :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: ...
os.mkdir(out_prefix) # We know we need bfile required_type = "bfile" check_input_files(in_prefix, in_type, required_type) # We need to inject the name of the input file and the name of the output # prefix script_prefix = os.path.join(out_prefix, "without_hh_genotypes") options += ["--{}".format(required_type), in_prefi...
Plink's heterozygous haploid analysis, a total of " "{:,d} genotype{} were set to missing.".format( nb_hh_missing, "s" if nb_hh_missing > 1 else "", ) ) print >>o_file, latex_template.wrap_lines(text) except IOError: msg = "{}: cannot write LaTeX summary".format(latex_file) raise ProgramError(msg) # Writing the summary...
def run_find_related_samples(in_prefix, in_type, out_prefix, base_dir, options): """Runs step9 (find related samples). :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: the options ne...
return usable output files. Hence, this function returns the input file prefix and its type. """ # Creating the output directory os.mkdir(out_prefix) # We know we need bfile required_type = "bfile" check_input_files(in_prefix, in_type, required_type) # We need to inject the name of the input file and the name of the ou...
with open(script_prefix + ".related_individuals", "r") as i_file: header = { name: i for i, name in enumerate(createRowFromPlinkSpacedOutput(i_file.readline())) } for required_col in ["FID1", "IID1", "FID2", "IID2"]: if required_col not in header: msg = "{}: missing column {}".format( script_prefix + ".related_individu...
= [] with open(script_prefix + ".merged_related_individuals", "r") as i_file: for line in i_file: table.append([ latex_template.sanitize_tex(item) for item in line.rstrip("\r\n").split("\t") ]) # We write a LaTeX summary latex_file = os.path.join(script_prefix + ".summary.tex") graphics_paths = set() try: with open(lat...
Adding the first figure (if present) fig_1 = script_prefix + ".related_individuals_z1.png" fig_1_label = re.sub(r"[/\\]", "_", script_prefix) + "_z1" if os.path.isfile(fig_1): text = ( r"Figure~\ref{" + fig_1_label + "} shows $Z_1$ versus " r"$IBS2_{ratio}^\ast$ for all related samples found by " r"Plink." ) print >>o_...
>>o_file, latex_template.wrap_lines(text) # Getting the required template float_template = latex_template.jinja2_env.get_template( "float_template.tex", ) graphic_template = latex_template.jinja2_env.get_template( "graphics_template.tex", ) figures = (fig_1, fig_2) labels = (fig_1_label, fig_2_label) graph_types = ("$Z...
"Sample pairs are grouped according to their estimated " "family (the index column)." ) print >>o_file, longtable_template.render( table_caption=table_caption, table_label=table_label, nb_col=len(table[1]), col_alignments="rlllll", text_size="scriptsize", header_data=zip(table[0], [1 for i in table[0]]), tabular_data=t...
def run_check_ethnicity(in_prefix, in_type, out_prefix, base_dir, options): """Runs step10 (check ethnicity). :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: the options needed. :ty...
usable output files. Hence, this function returns the input file prefix and its type. """ # Creating the output directory os.mkdir(out_prefix) # We know we need bfile required_type = "bfile" check_input_files(in_prefix, in_type, required_type) # We need to inject the name of the input file and the name of the output # ...
in options # Computing the number of outliers outliers = None if not skip_ref_pops: with open(script_prefix + ".outliers", "r") as i_file: outliers = { tuple(line.rstrip("\r\n").split("\t")) for line in i_file } # Computing the number of markers used nb_markers_mds = 0 with open(script_prefix + ".ibs.pruned_data.bim", ...
{:,d} marker{} and a multiplier of {}, there was a " "total of {:,d} outlier{} of the {} population.".format( nb_markers_mds, "s" if nb_markers_mds > 1 else "", multiplier, len(outliers), "s" if len(outliers) > 1 else "", outliers_of, ) ) print >>o_file, latex_template.wrap_lines(text) # Adding the figure if it exists ...
print >>o_file, latex_template.wrap_lines(text) # Printing caption = ( "MDS plots showing the first two principal components of " "the source dataset with the reference panels. The " "outliers of the {} population are shown in grey, while " "samples of the source dataset that resemble the {} " "population are shown in ...
required template float_template = latex_template.jinja2_env.get_template( "float_template.tex", ) graphic_template = latex_template.jinja2_env.get_template( "graphics_template.tex", ) # The label label = re.sub(r"[/\\]", "_", script_prefix) + "_screeplot" text = ( r"Figure~\ref{" + label + "} shows the scree plot for ...
{} outliers\t" "{:,d}".format(outliers_of, len(outliers))) print >>o_file, "---" # We know this step doesn't produce an new data set, so we return the old # prefix and the old in_type return _StepResult( next_file=in_prefix, next_file_type=required_type, latex_summary=latex_file, description=check_ethnicity.desc, long_...
def run_flag_maf_zero(in_prefix, in_type, out_prefix, base_dir, options): """Runs step11 (flag MAF zero). :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: the options needed. :type i...
return usable output files. Hence, this function returns the input file prefix and its type. """ # Creating the output directory os.mkdir(out_prefix) # We know we need bfile required_type = "bfile" check_input_files(in_prefix, in_type, required_type) # We need to inject the name of the input file and the name of the ou...
) safe_fn = latex_template.sanitize_tex(os.path.basename(flagged_fn)) text = ( "After computing minor allele frequencies (MAF) of all " "markers using Plink, a total of {:,d} marker{} had a MAF " "of zero and were flagged ({}).".format( nb_flagged, "s" if nb_flagged - 1 > 1 else "", "see file " + latex_template.texttt(...
graph_path=None, )
def run_flag_hw(in_prefix, in_type, out_prefix, base_dir, options): """Runs step12 (flag HW). :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: the options needed. :type in_prefix: st...
usable output files. Hence, this function returns the input file prefix and its type. """ # Creating the output directory os.mkdir(out_prefix) # We know we need bfile required_type = "bfile" check_input_files(in_prefix, in_type, required_type) # We need to inject the name of the input file and the name of the output # ...
with open(filename, "r") as i_file: nb_markers = len(i_file.read().splitlines()) # Saving the values thresholds[threshold] = (nb_markers, filename) # We create the LaTeX summary latex_file = os.path.join(script_prefix + ".summary.tex") try: with open(latex_file, "w") as o_file: print >>o_file, latex_template.subsection...
) ) print >>o_file, latex_template.wrap_lines(text) except IOError: msg = "{}: cannot write LaTeX summary".format(latex_file) raise ProgramError(msg) # Writing the summary results with open(os.path.join(base_dir, "results_summary.txt"), "a") as o_file: print >>o_file, "# {}".format(script_prefix) print >>o_file, "Numbe...
def run_compare_gold_standard(in_prefix, in_type, out_prefix, base_dir, options): """Compares with a gold standard data set (compare_gold_standard. :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :...
:py:mod:`pyGenClean.Misc.compare_gold_standard` module doesn't return usable output files. Hence, this function returns the input file prefix and its type. """ # Creating the output directory os.mkdir(out_prefix) # We know we need bfile required_type = "bfile" check_input_files(in_prefix, in_type, required_type) # We n...
we return the old # prefix and the old in_type return _StepResult( next_file=in_prefix, next_file_type=required_type, latex_summary=latex_file, description=compare_gold_standard.desc, long_description=compare_gold_standard.long_desc, graph_path=None, )
def run_subset_data(in_prefix, in_type, out_prefix, base_dir, options): """Subsets the data. :param in_prefix: the prefix of the input files. :param in_type: the type of the input files. :param out_prefix: the output prefix. :param base_dir: the output directory. :param options: the options needed. :type in_prefix: str...
same as the input file type. """ # Creating the output directory os.mkdir(out_prefix) # The prefix of the script script_prefix = os.path.join(out_prefix, "subset") # The extension of the marker and sample file markers_ext = None samples_ext = None # Looking at what we have required_type = None if in_type == "bfile": re...
we have a reason for markers m_subset_reason = None if "--reason-marker" in options: m_subset_reason = latex_template.sanitize_tex( options.pop(options.index("--reason-marker")+1), ) options.pop(options.index("--reason-marker")) if (not is_extract) and (not is_exclude): # There was a reason for marker exclusion, but no...
required_type == "bfile": options.append("--is-bfile") elif required_type == "tfile": options.append("--is-tfile") else: options.append("--is-file") # We run the script try: subset_data.main(options) except subset_data.ProgramError as e: msg = "subset_data: {}".format(e) raise ProgramError(msg) # The files before the s...
markers that were extracted marker_subset_fn = options[options.index("--extract") + 1] with open(marker_subset_fn, "r") as i_file: nb_extract = sum(1 for line in i_file) # Markers were excluded nb_exclude = None if is_exclude: marker_subset_fn = options[options.index("--exclude") + 1] with open(marker_subset_fn, "r") a...
Samples were kept nb_keep = None if is_keep: sample_subset_fn = options[options.index("--keep") + 1] with open(sample_subset_fn, "r") as i_file: nb_keep = sum(1 for line in i_file) # Samples were removed nb_remove = None if is_remove: sample_subset_fn = options[options.index("--remove") + 1] with open(sample_subset_fn,...
to gather what is left log_file = None with open(script_prefix + ".log", "r") as i_file: log_file = i_file.read() # Checking the number of markers at the beginning nb_marker_start = re.search( r"(\d+) (\(of \d+\) )?markers to be included " "from \[ {}".format(in_prefix), log_file, ) if nb_marker_start: nb_marker_start ...
file)") # Checking the number of samples at the beginning nb_sample_start = re.search( r"(\d+) individuals read from \[ {}".format(in_prefix), log_file, ) if nb_sample_start: nb_sample_start = int(nb_sample_start.group(1)) # Checking the number of samples at the end nb_sample_end = re.search( r"(\d+) founders and (\d+)...
write a LaTeX summary latex_file = os.path.join(script_prefix + ".summary.tex") try: with open(latex_file, "w") as o_file: section_name = subset_data.pretty_name if len(reasons) > 0: section_name += " ({})".format(", ".join(reasons)) print >>o_file, latex_template.subsection(section_name) text = "" if is_extract: text ...
) ) if is_keep: text += ( "The file containing samples to keep contained {:,d} " "sample{}. Out of a total of {:,d} sample{}, {:,d} " "remained ({:,d} removed). ".format( nb_keep, "s" if nb_keep > 1 else "", nb_sample_start, "s" if nb_sample_start > 1 else "", nb_sample_end, nb_sample_start - nb_sample_end, ) ) if is_r...
as o_file: for value in removed_samples.items(): print >>o_file, "\t".join(value) # Writing the excluded markers to file o_filename = os.path.join(base_dir, "excluded_markers.txt") with open(o_filename, "a") as o_file: for value in removed_markers.items(): print >>o_file, "\t".join(value) # Writing the summary results ...
> 0: description += " ({})".format(", ".join(reasons)) # We know this step does produce a new data set (bfile), so we return it return _StepResult( next_file=os.path.join(out_prefix, "subset"), next_file_type=required_type, latex_summary=latex_file, description=description, long_description=subset_data.long_desc, graph...
def run_command(command): """Run a command using subprocesses. :param command: the command to run. :type command: list Tries to run a command. If it fails, raise a :py:class:`ProgramError`. .. warning:: The variable ``command`` should be a list of strings (no other type). """ output = None try: output = subprocess.chec...
def count_markers_samples(prefix, file_type): """Counts the number of markers and samples in plink file. :param prefix: the prefix of the files. :param file_type: the file type. :type prefix: str :type file_type: str :returns: the number of markers and samples (in a tuple). """ # The files that will need counting sampl...
as f: for line in f: nb_samples += 1 nb_markers = 0 with open(marker_file, "r") as f: for line in f: nb_markers += 1 return nb_markers, nb_samples
def check_input_files(prefix, the_type, required_type): """Check that the file is of a certain file type. :param prefix: the prefix of the input files. :param the_type: the type of the input files (bfile, tfile or file). :param required_type: the required type of the input files (bfile, tfile or file). :type prefix: st...
need bfile plink_command += ["--make-bed"] if the_type == "bfile": return True elif the_type == "tfile": # We have tfile, we need to create bfile from tfile plink_command += ["--tfile", prefix] elif the_type == "file": # We have file, we need to create bfile from file plink_command += ["--file", prefix] else: msg = "{}...
# We have bfile, we need to create tfile from bfile plink_command += ["--bfile", prefix] elif the_type == "file": # We have file, we need to create tfile from file plink_command += ["--file", prefix] else: msg = "{}: no suitable input format...".format(prefix) raise ProgramError(msg) # We create the required files if o...
the_type == "tfile": # We have tfile, we need to create file from tfile plink_command += ["--tfile", prefix] else: msg = "{}: no suitable input format...".format(prefix) raise ProgramError(msg) # We create the required files if os.path.isfile(prefix + ".log"): # There is a log file... we need to copy it shutil.copyfile...
def all_files_exist(file_list): """Check if all files exist. :param file_list: the names of files to check. :type file_list: list :returns: ``True`` if all files exist, ``False`` otherwise. """ all_exist = True for filename in file_list: all_exist = all_exist and os.path.isfile(filename) return all_exist
def read_config_file(filename): """Reads the configuration file. :param filename: the name of the file containing the configuration. :type filename: str :returns: A tuple where the first element is a list of sections, and the second element is a map containing the configuration (options and values). The structure of th...
Hardy Weinberg script = flag_hw [8] # Subset the dataset (excludes markers and remove samples) script = subset exclude = .../filename rempove = .../filename Sections are in square brackets and must be ``integer``. The section number represent the step at which the script will be run (*i.e.* from the smallest number to ...
``check_ethnicity`` (:py:func:`run_check_ethnicity`) * ``flag_maf_zero`` (:py:func:`run_flag_maf_zero`) * ``flag_hw`` (:py:func:`run_flag_hw`) * ``subset`` (:py:func:`run_subset_data`) * ``compare_gold_standard`` (:py:func:`run_compare_gold_standard`) """ # Creating the config parser config = ConfigParser.RawConfigPars...
called 'script'".format( filename, section, )) raise ProgramError(msg) if script_name not in available_modules: msg = ("{}: section {}: script {}: invalid script name".format( filename, section, script_name, )) raise ProgramError(msg) # Getting the variables options = [] for variable_name, variable_value in config.item...
def check_args(args): """Checks the arguments and options. :param args: an object containing the options and arguments of the program. :type args: :py:class:`argparse.Namespace` :returns: ``True`` if everything was OK. If there is a problem with an option, an exception is raised using the :py:class:`ProgramError` class...
[".bed", ".bim", ".fam"]]: if not os.path.isfile(fileName): msg = "{}: no such file".format(fileName) raise ProgramError(msg) elif args.tfile is not None and args.bfile is None and args.file is None: for fileName in [args.tfile + i for i in [".tped", ".tfam"]]: if not os.path.isfile(fileName): msg = "{}: no such file"....
def instance(cls, public_keys_dir): '''Please avoid create multi instance''' if public_keys_dir in cls._authenticators: return cls._authenticators[public_keys_dir] new_instance = cls(public_keys_dir) cls._authenticators[public_keys_dir] = new_instance return new_instance
def set_server_key(self, zmq_socket, server_secret_key_path): '''must call before bind''' load_and_set_key(zmq_socket, server_secret_key_path) zmq_socket.curve_server = True
def set_client_key(self, zmq_socket, client_secret_key_path, server_public_key_path): '''must call before bind''' load_and_set_key(zmq_socket, client_secret_key_path) server_public, _ = zmq.auth.load_certificate(server_public_key_path) zmq_socket.curve_serverkey = server_public
def _register_nested_router(self, router): """ NestedSimpleRouter.__init__ calls this method """ assert issubclass(router.__class__, NestedSimpleRouter), "You can only register NestedSimpleRouters" self.nested_routers.append(router)
def get_urls(self): """ Returns a list of urls including all NestedSimpleRouter urls """ ret = super(SimpleRouter, self).get_urls() for router in self.nested_routers: ret.extend(router.get_urls()) return ret
def get_weld_obj_id(weld_obj, data): """Helper method to update WeldObject with some data. Parameters ---------- weld_obj : WeldObject WeldObject to update. data : numpy.ndarray or WeldObject or str Data for which to get an id. If str, it is a placeholder or 'str' literal. Returns ------- str The id of the data, e.g. _...
def create_weld_object(data): """Helper method to create a WeldObject and update with data. Parameters ---------- data : numpy.ndarray or WeldObject or str Data to include in newly created object. If str, it is a placeholder or 'str' literal. Returns ------- (str, WeldObject) Object id for the data to use in the Weld c...
def create_placeholder_weld_object(data): """Helper method that creates a WeldObject that evaluates to itself. Parameters ---------- data : numpy.ndarray or WeldObject or str Data to wrap around. If str, it is a placeholder or 'str' literal. Returns ------- WeldObject WeldObject wrapped around data. """ obj_id, weld_ob...
def _extract_placeholder_weld_objects_at_index(dependency_name, length, readable_text, index): """Helper method that creates a WeldObject for each component of dependency. Parameters ---------- dependency_name : str The name of the dependency evaluating to a tuple. length : int Number of components to create WeldObject...
def to_weld_literal(scalar, weld_type): """Return scalar formatted for Weld. Parameters ---------- scalar : {int, float, str, bool} Scalar data to convert to weld literal. weld_type : WeldType Desired Weld type. Returns ------- str String of the scalar to use in Weld code. Examples -------- >>> to_weld_literal(4, WeldL...
to type:{}'.format(scalar, weld_type))
def weld_combine_scalars(scalars, weld_type): """Combine column-wise aggregations (so resulting scalars) into a single array. Parameters ---------- scalars : tuple of WeldObjects WeldObjects to combine. weld_type : WeldType The Weld type of the result. Currently expecting scalars to be of the same type. Returns -------...
def weld_cast_scalar(scalar, to_weld_type): """Returns the scalar casted to the request Weld type. Parameters ---------- scalar : {int, float, WeldObject} Input array. to_weld_type : WeldType Type of each element in the input array. Returns ------- WeldObject Representation of this computation. """ if _not_possible_to_...
def weld_cast_array(array, weld_type, to_weld_type): """Cast array to a different type. Parameters ---------- array : numpy.ndarray or WeldObject Input data. weld_type : WeldType Type of each element in the input array. to_weld_type : WeldType Desired type. Returns ------- WeldObject Representation of this computation....
def weld_arrays_to_vec_of_struct(arrays, weld_types): """Create a vector of structs from multiple vectors. Parameters ---------- arrays : list of (numpy.ndarray or WeldObject) Arrays to put in a struct. weld_types : list of WeldType The Weld types of the arrays in the same order. Returns ------- WeldObject Representati...
def weld_vec_of_struct_to_struct_of_vec(vec_of_structs, weld_types): """Create a struct of vectors. Parameters ---------- vec_of_structs : WeldObject Encoding a vector of structs. weld_types : list of WeldType The Weld types of the arrays in the same order. Returns ------- WeldObject Representation of this computation....
def weld_select_from_struct(struct_of_vec, index_to_select): """Select a single vector from the struct of vectors. Parameters ---------- struct_of_vec : WeldObject Encoding a struct of vectors. index_to_select : int Which vec to select from the struct. Returns ------- WeldObject Representation of this computation. """ ...
def weld_data_to_dict(keys, keys_weld_types, values, values_weld_types): """Adds the key-value pairs in a dictionary. Overlapping keys are max-ed. Note this cannot be evaluated! Parameters ---------- keys : list of (numpy.ndarray or WeldObject) keys_weld_types : list of WeldType values : numpy.ndarray or WeldObject val...
def set( self, params ): """Set the parameters for the experiment, returning the now-configured experiment. Be sure to call this base method when overriding. :param params: the parameters :returns: The experiment""" if self._parameters is not None: self.deconfigure() self.configure(params) return self
def report( self, params, meta, res ): """Return a properly-structured dict of results. The default returns a dict with results keyed by :attr:`Experiment.RESULTS`, the data point in the parameter space keyed by :attr:`Experiment.PARAMETERS`, and timing and other metadata keyed by :attr:`Experiment.METADATA`. Overridin...
def run( self ): """Run the experiment, using the parameters set using :meth:`set`. A "run" consists of calling :meth:`setUp`, :meth:`do`, and :meth:`tearDown`, followed by collecting and storing (and returning) the experiment's results. If running the experiment raises an exception, that will be returned in the metada...