Search is not available for this dataset
text
stringlengths
75
104k
def get_html_tag_attributes(cls, instance): """ Returns a dictionary of attributes, which shall be added to the current HTML tag. This method normally is called by the models's property method ``html_tag_ attributes``, which enriches the HTML tag with those attributes converted to a list...
def compile_validation_pattern(self, units=None): """ Assure that passed in units are valid size units, or if missing, use all possible units. Return a tuple with a regular expression to be used for validating and an error message in case this validation failed. """ if un...
def get_nodes(self, request): """ This method is used to build the menu tree. """ nodes = [] docsmap_file = os.path.join(settings.SPHINX_DOCS_ROOT, 'docsmap.json') if not os.path.exists(docsmap_file): return nodes with io.open(docsmap_file) as fh: ...
def unset_required_for(cls, sharable_fields): """ Fields borrowed by `SharedGlossaryAdmin` to build its temporary change form, only are required if they are declared in `sharable_fields`. Otherwise just deactivate them. """ if 'link_content' in cls.base_fields and 'link_content' ...
def assure_relation(cls, cms_page): """ Assure that we have a foreign key relation, pointing from CascadePage onto CMSPage. """ try: cms_page.cascadepage except cls.DoesNotExist: cls.objects.create(extended_object=cms_page)
def reduce_breakpoints(plugin, field_name, request=None, obj=None): """ Narrow down the number of breakpoints in the widget of the named glossary_field. This is useful in case the container was defined with a subset of these breakpoints: xs, sm, md, lg. """ if not isinstance(plugin, CascadePluginBas...
def compute_media_queries(element): """ For e given Cascade element, compute the current media queries for each breakpoint, even for nested containers, rows and columns. """ parent_glossary = element.get_parent_glossary() # compute the max width and the required media queries for each chosen bre...
def get_image_tags(context, instance, options): """ Create a context returning the tags to render an <img ...> element: ``sizes``, ``srcset``, a fallback ``src`` and if required inline styles. """ if hasattr(instance, 'image') and hasattr(instance.image, 'exif'): aspect_ratio = compute_aspec...
def get_picture_elements(context, instance): """ Create a context, used to render a <picture> together with all its ``<source>`` elements: It returns a list of HTML elements, each containing the information to render a ``<source>`` element. The purpose of this HTML entity is to display images with a...
def get_child_classes(cls, slot, page, instance=None): """Restrict child classes of Card to one of each: Header, Body and Footer""" child_classes = super(BootstrapCardPlugin, cls).get_child_classes(slot, page, instance) # allow only one child of type Header, Body, Footer for child in ins...
def get_form(self, request, obj=None, **kwargs): """ Build the form used for changing the model. """ kwargs.update(widgets={ 'plugin_type': widgets.Select(choices=self.plugins_for_site), 'css_classes': JSONMultiWidget(self.classname_fields), 'inline_st...
def get_element_ids(self, prefix_id): """ Returns a single or a list of element ids, one for each input widget of this field """ if isinstance(self.widget, widgets.MultiWidget): ids = ['{0}_{1}_{2}'.format(prefix_id, self.name, field_name) for field_name in self.widget] ...
def find_django_migrations_module(module_name): """ Tries to locate <module_name>.migrations_django (without actually importing it). Appends either ".migrations_django" or ".migrations" to module_name. For details why: https://docs.djangoproject.com/en/1.7/topics/migrations/#libraries-third-party-apps...
def get_context_override(self, request): """ Override the request object with an emulated user. """ context_override = super(EmulateUserModelMixin, self).get_context_override(request) try: if request.user.is_staff: user = self.UserModel.objects.get(pk=...
def emulate_users(self, request): """ The list view """ def display_as_link(self, obj): try: identifier = getattr(user_model_admin, list_display_link)(obj) except AttributeError: identifier = admin.utils.lookup_field(list_display_li...
def pre_migrate(cls, sender=None, **kwargs): """ Iterate over contenttypes and remove those not in proxy models """ ContentType = apps.get_model('contenttypes', 'ContentType') try: queryset = ContentType.objects.filter(app_label=sender.label) for ctype in ...
def post_migrate(cls, sender=None, **kwargs): """ Iterate over fake_proxy_models and add contenttypes and permissions for missing proxy models, if this has not been done by Django yet """ ContentType = apps.get_model('contenttypes', 'ContentType') for model_name, proxy_m...
def grant_permissions(self, proxy_model): """ Create the default permissions for the just added proxy model """ ContentType = apps.get_model('contenttypes', 'ContentType') try: Permission = apps.get_model('auth', 'Permission') except LookupError: r...
def revoke_permissions(self, ctype): """ Remove all permissions for the content type to be removed """ ContentType = apps.get_model('contenttypes', 'ContentType') try: Permission = apps.get_model('auth', 'Permission') except LookupError: return ...
def to_file(file, array): """Wrapper around ndarray.tofile to support any file-like object""" try: array.tofile(file) except (TypeError, IOError, UnsupportedOperation): # tostring actually returns bytes file.write(array.tostring())
def write_segment(self, objects): """ Write a segment of data to a TDMS file :param objects: A list of TdmsObject instances to write """ segment = TdmsSegment(objects) segment.write(self._file)
def fromfile(file, dtype, count, *args, **kwargs): """Wrapper around np.fromfile to support any file-like object""" try: return np.fromfile(file, dtype=dtype, count=count, *args, **kwargs) except (TypeError, IOError, UnsupportedOperation): return np.frombuffer( file.read(count *...
def read_property(f, endianness="<"): """ Read a property from a segment's metadata """ prop_name = types.String.read(f, endianness) prop_data_type = types.tds_data_types[types.Uint32.read(f, endianness)] value = prop_data_type.read(f, endianness) log.debug("Property %s: %r", prop_name, value) ...
def read_string_data(file, number_values, endianness): """ Read string raw data This is stored as an array of offsets followed by the contiguous string data. """ offsets = [0] for i in range(number_values): offsets.append(types.Uint32.read(file, endianness)) strings = [] ...
def path_components(path): """Convert a path into group and channel name components""" def yield_components(path): # Iterate over each character and the next character chars = zip_longest(path, path[1:]) try: # Iterate over components while True: ...
def object(self, *path): """Get a TDMS object from the file :param path: The object group and channel. Providing no channel returns a group object, and providing no channel or group will return the root object. :rtype: :class:`TdmsObject` For example, to get the...
def groups(self): """Return the names of groups in the file Note that there is not necessarily a TDMS object associated with each group name. :rtype: List of strings. """ # Split paths into components and take the first (group) component. object_paths = ( ...
def group_channels(self, group): """Returns a list of channel objects for the given group :param group: Name of the group to get channels for. :rtype: List of :class:`TdmsObject` objects. """ path = self._path(group) return [ self.objects[p] for...
def as_dataframe(self, time_index=False, absolute_time=False): """ Converts the TDMS file to a DataFrame :param time_index: Whether to include a time index for the dataframe. :param absolute_time: If time_index is true, whether the time index values are absolute times or rel...
def as_hdf(self, filepath, mode='w', group='/'): """ Converts the TDMS file into an HDF5 file :param filepath: The path of the HDF5 file you want to write to. :param mode: The write mode of the HDF5 file. This can be w, a ... :param group: A group in the HDF5 file that will cont...
def read_metadata(self, f, objects, previous_segment=None): """Read segment metadata section and update object information""" if not self.toc["kTocMetaData"]: try: self.ordered_objects = previous_segment.ordered_objects except AttributeError: rais...
def calculate_chunks(self): """ Work out the number of chunks the data is in, for cases where the meta data doesn't change at all so there is no lead in. Also increments the number of values for objects in this segment, based on the number of chunks. """ ...
def read_raw_data(self, f): """Read signal data from file""" if not self.toc["kTocRawData"]: return f.seek(self.data_position) total_data_size = self.next_segment_offset - self.raw_data_offset log.debug( "Reading %d bytes of data at %d in %d chunks" % ...
def _read_interleaved_numpy(self, f, data_objects): """Read interleaved data where all channels have a numpy type""" log.debug("Reading interleaved data all at once") # Read all data into 1 byte unsigned ints first all_channel_bytes = data_objects[0].raw_data_width if all_channe...
def _read_interleaved(self, f, data_objects): """Read interleaved data that doesn't have a numpy type""" log.debug("Reading interleaved data point by point") object_data = {} points_added = {} for obj in data_objects: object_data[obj.path] = obj._new_segment_data() ...
def time_track(self, absolute_time=False, accuracy='ns'): """Return an array of time or the independent variable for this channel This depends on the object having the wf_increment and wf_start_offset properties defined. Note that wf_start_offset is usually zero for time-series data. ...
def _initialise_data(self, memmap_dir=None): """Initialise data array to zeros""" if self.number_values == 0: pass elif self.data_type.nptype is None: self._data = [] else: if memmap_dir: memmap_file = tempfile.NamedTemporaryFile( ...
def _update_data(self, new_data): """Update the object data with a new array of data""" log.debug("Adding %d data points to data for %s" % (len(new_data), self.path)) if self._data is None: self._data = new_data else: if self.data_type.nptype is...
def as_dataframe(self, absolute_time=False): """ Converts the TDMS object to a DataFrame :param absolute_time: Whether times should be absolute rather than relative to the start time. :return: The TDMS object data. :rtype: pandas.DataFrame """ import...
def data(self): """ NumPy array containing data if there is data for this object, otherwise None. """ if self._data is None: # self._data is None if data segment is empty return np.empty((0, 1)) if self._data_scaled is None: scale = sca...
def _read_metadata(self, f, endianness): """ Read the metadata for a DAQmx raw segment. This is the raw DAQmx-specific portion of the raw data index. """ self.data_type = types.tds_data_types[0xFFFFFFFF] self.dimension = types.Uint32.read(f, endianness) # In TDMS...
def _read_metadata(self, f): """Read object metadata and update object information""" raw_data_index = types.Uint32.read(f, self.endianness) log.debug("Reading metadata for object %s", self.tdms_object.path) # Object has no data in this segment if raw_data_index == 0xFFFFFFFF:...
def _read_value(self, file): """Read a single value from the given file""" if self.data_type.nptype is not None: dtype = (np.dtype(self.data_type.nptype).newbyteorder( self.endianness)) return fromfile(file, dtype=dtype, count=1) return self.data_type.rea...
def _read_values(self, file, number_values): """Read all values for this object from a contiguous segment""" if self.data_type.nptype is not None: dtype = (np.dtype(self.data_type.nptype).newbyteorder( self.endianness)) return fromfile(file, dtype=dtype, count=nu...
def _new_segment_data(self): """Return a new array to read the data of the current section into""" if self.data_type.nptype is not None: return np.zeros(self.number_values, dtype=self.data_type.nptype) else: return [None] * self.number_values
def detect_build(snps): """ Detect build of SNPs. Use the coordinates of common SNPs to identify the build / assembly of a genotype file that is being loaded. Notes ----- rs3094315 : plus strand in 36, 37, and 38 rs11928389 : plus strand in 36, minus strand in 37 and 38 rs2500347 : plu...
def get_chromosomes(snps): """ Get the chromosomes of SNPs. Parameters ---------- snps : pandas.DataFrame Returns ------- list list of str chromosomes (e.g., ['1', '2', '3', 'MT'], empty list if no chromosomes """ if isinstance(snps, pd.DataFrame): return list(pd.u...
def get_chromosomes_summary(snps): """ Summary of the chromosomes of SNPs. Parameters ---------- snps : pandas.DataFrame Returns ------- str human-readable listing of chromosomes (e.g., '1-3, MT'), empty str if no chromosomes """ if isinstance(snps, pd.DataFrame): ...
def determine_sex( snps, y_snps_not_null_threshold=0.1, heterozygous_x_snps_threshold=0.01 ): """ Determine sex from SNPs using thresholds. Parameters ---------- snps : pandas.DataFrame y_snps_not_null_threshold : float percentage Y SNPs that are not null; above this threshold, Male is ...
def sort_snps(snps): """ Sort SNPs based on ordered chromosome list and position. """ sorted_list = sorted(snps["chrom"].unique(), key=_natural_sort_key) # move PAR and MT to the end of the dataframe if "PAR" in sorted_list: sorted_list.remove("PAR") sorted_list.append("PAR") if "...
def get_summary(self): """ Get summary of ``SNPs``. Returns ------- dict summary info, else None if ``SNPs`` is not valid """ if not self.is_valid(): return None else: return { "source": self.source, ...
def _read_23andme(file): """ Read and parse 23andMe file. https://www.23andme.com Parameters ---------- file : str path to file Returns ------- pandas.DataFrame individual's genetic data normalized for use with `lineage` ...
def _read_ftdna(file): """ Read and parse Family Tree DNA (FTDNA) file. https://www.familytreedna.com Parameters ---------- file : str path to file Returns ------- pandas.DataFrame individual's genetic data normalized for use wit...
def _read_ftdna_famfinder(file): """ Read and parse Family Tree DNA (FTDNA) "famfinder" file. https://www.familytreedna.com Parameters ---------- file : str path to file Returns ------- pandas.DataFrame individual's genetic data ...
def _read_ancestry(file): """ Read and parse Ancestry.com file. http://www.ancestry.com Parameters ---------- file : str path to file Returns ------- pandas.DataFrame individual's genetic data normalized for use with `lineage` ...
def _read_lineage_csv(file, comments): """ Read and parse CSV file generated by lineage. Parameters ---------- file : str path to file comments : str comments at beginning of file Returns ------- pandas.DataFrame indiv...
def _read_generic_csv(file): """ Read and parse generic CSV file. Notes ----- Assumes columns are 'rsid', 'chrom' / 'chromosome', 'pos' / 'position', and 'genotype'; values are comma separated; unreported genotypes are indicated by '--'; and one header row precedes data....
def _assign_par_snps(self): """ Assign PAR SNPs to the X or Y chromosome using SNP position. References ----- ..[1] National Center for Biotechnology Information, Variation Services, RefSNP, https://api.ncbi.nlm.nih.gov/variation/v0/ ..[2] Yates et. al. (doi:10.1093/bi...
def plot_chromosomes(one_chrom_match, two_chrom_match, cytobands, path, title, build): """ Plots chromosomes with designated markers. Parameters ---------- one_chrom_match : list of dicts segments to highlight on the chromosomes representing one shared chromosome two_chrom_match : list of d...
def _patch_chromosomal_features(cytobands, one_chrom_match, two_chrom_match): """ Highlight positions for each chromosome segment / feature. Parameters ---------- cytobands : pandas.DataFrame cytoband table from UCSC one_chrom_match : list of dicts segments to highlight on the chrom...
def create_dir(path): """ Create directory specified by `path` if it doesn't already exist. Parameters ---------- path : str path to directory Returns ------- bool True if `path` exists """ # https://stackoverflow.com/a/5032238 try: os.makedirs(path, exi...
def save_df_as_csv(df, path, filename, comment=None, **kwargs): """ Save dataframe to a CSV file. Parameters ---------- df : pandas.DataFrame dataframe to save path : str path to directory where to save CSV file filename : str filename of CSV file comment : str ...
def remap_snps(self, individual, target_assembly, complement_bases=True): """ Remap the SNP coordinates of an individual from one assembly to another. This method uses the assembly map endpoint of the Ensembl REST API service (via ``Resources``'s ``EnsemblRestClient``) to convert SNP coordinate...
def find_discordant_snps( self, individual1, individual2, individual3=None, save_output=False ): """ Find discordant SNPs between two or three individuals. Parameters ---------- individual1 : Individual reference individual (child if `individual2` and `individual...
def find_shared_dna( self, individual1, individual2, cM_threshold=0.75, snp_threshold=1100, shared_genes=False, save_output=True, ): """ Find the shared DNA between two individuals. Computes the genetic distance in centiMorgans (cMs) between S...
def get_genetic_map_HapMapII_GRCh37(self): """ Get International HapMap Consortium HapMap Phase II genetic map for Build 37. Returns ------- dict dict of pandas.DataFrame HapMapII genetic maps if loading was successful, else None """ if self._genetic_map_HapM...
def get_cytoBand_hg19(self): """ Get UCSC cytoBand table for Build 37. Returns ------- pandas.DataFrame cytoBand table if loading was successful, else None """ if self._cytoBand_hg19 is None: self._cytoBand_hg19 = self._load_cytoBand(self._get_pat...
def get_knownGene_hg19(self): """ Get UCSC knownGene table for Build 37. Returns ------- pandas.DataFrame knownGene table if loading was successful, else None """ if self._knownGene_hg19 is None: self._knownGene_hg19 = self._load_knownGene(self._g...
def get_kgXref_hg19(self): """ Get UCSC kgXref table for Build 37. Returns ------- pandas.DataFrame kgXref table if loading was successful, else None """ if self._kgXref_hg19 is None: self._kgXref_hg19 = self._load_kgXref(self._get_path_kgXref_hg1...
def get_assembly_mapping_data(self, source_assembly, target_assembly): """ Get assembly mapping data. Parameters ---------- source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'} assembly to remap from target_assembly : {'NCBI36', 'GRCh37', 'GRCh38'} assembly t...
def download_example_datasets(self): """ Download example datasets from `openSNP <https://opensnp.org>`_. Per openSNP, "the data is donated into the public domain using `CC0 1.0 <http://creativecommons.org/publicdomain/zero/1.0/>`_." Returns ------- paths : list of str ...
def get_all_resources(self): """ Get / download all resources used throughout `lineage`. Returns ------- dict dict of resources """ resources = {} resources[ "genetic_map_HapMapII_GRCh37" ] = self.get_genetic_map_HapMapII_GRCh37() ...
def _load_genetic_map(filename): """ Load genetic map (e.g. HapMapII). Parameters ---------- filename : str path to compressed archive with genetic map data Returns ------- genetic_map : dict dict of pandas.DataFrame genetic maps if loadi...
def _load_assembly_mapping_data(filename): """ Load assembly mapping data. Parameters ---------- filename : str path to compressed archive with assembly mapping data Returns ------- assembly_mapping_data : dict dict of assembly maps if lo...
def _load_cytoBand(filename): """ Load UCSC cytoBand table. Parameters ---------- filename : str path to cytoBand file Returns ------- df : pandas.DataFrame cytoBand table if loading was successful, else None References -...
def _load_knownGene(filename): """ Load UCSC knownGene table. Parameters ---------- filename : str path to knownGene file Returns ------- df : pandas.DataFrame knownGene table if loading was successful, else None """ try: ...
def _load_kgXref(filename): """ Load UCSC kgXref table. Parameters ---------- filename : str path to kgXref file Returns ------- df : pandas.DataFrame kgXref table if loading was successful, else None """ try: ...
def _get_path_assembly_mapping_data( self, source_assembly, target_assembly, retries=10 ): """ Get local path to assembly mapping data, downloading if necessary. Parameters ---------- source_assembly : {'NCBI36', 'GRCh37', 'GRCh38'} assembly to remap from ...
def _download_file(self, url, filename, compress=False, timeout=30): """ Download a file to the resources folder. Download data from `url`, save as `filename`, and optionally compress with gzip. Parameters ---------- url : str URL to download data from filen...
def discrepant_snps(self): """ SNPs with discrepant positions and / or genotypes discovered while loading SNPs. Returns ------- pandas.DataFrame """ df = self._discrepant_positions.append(self._discrepant_genotypes) if len(df) > 1: df = df.drop_duplic...
def load_snps( self, raw_data, discrepant_snp_positions_threshold=100, discrepant_genotypes_threshold=500, save_output=False, ): """ Load raw genotype data. Parameters ---------- raw_data : list or str path(s) to file(s) with raw g...
def save_snps(self, filename=None): """ Save SNPs to file. Parameters ---------- filename : str filename for file to save Returns ------- str path to file in output directory if SNPs were saved, else empty str """ comment ...
def remap_snps(self, target_assembly, complement_bases=True): """ Remap the SNP coordinates of this ``Individual`` from one assembly to another. This method is a wrapper for `remap_snps` in the ``Lineage`` class. This method uses the assembly map endpoint of the Ensembl REST API service to con...
def _set_snps(self, snps, build=37): """ Set `_snps` and `_build` properties of this ``Individual``. Notes ----- Intended to be used internally to `lineage`. Parameters ---------- snps : pandas.DataFrame individual's genetic data normalized for use w...
def _add_snps( self, snps, discrepant_snp_positions_threshold, discrepant_genotypes_threshold, save_output, ): """ Add SNPs to this Individual. Parameters ---------- snps : SNPs SNPs to add discrepant_snp_positions_threshol...
def _double_single_alleles(df, chrom): """ Double any single alleles in the specified chromosome. Parameters ---------- df : pandas.DataFrame SNPs chrom : str chromosome of alleles to double Returns ------- df : pandas.DataFrame ...
def seperate_symbols(func): """ Seperate the symbols in symbolic function func. Return them in alphabetical order. :param func: scipy symbolic function. :return: (vars, params), a tuple of all variables and parameters, each sorted in alphabetical order. :raises TypeError: only symfit V...
def sympy_to_py(func, args): """ Turn a symbolic expression into a Python lambda function, which has the names of the variables and parameters as it's argument names. :param func: sympy expression :param args: variables and parameters in this model :return: lambda function to be used for numeri...
def sympy_to_scipy(func, vars, params): """ Convert a symbolic expression to one scipy digs. Not used by ``symfit`` any more. :param func: sympy expression :param vars: variables :param params: parameters :return: Scipy-style function to be used for numerical evaluation of the model. """ ...
def variables(names, **kwargs): """ Convenience function for the creation of multiple variables. For more control, consider using ``symbols(names, cls=Variable, **kwargs)`` directly. :param names: string of variable names. Example: x, y = variables('x, y') :param kwargs: kwargs to be passed...
def parameters(names, **kwargs): """ Convenience function for the creation of multiple parameters. For more control, consider using ``symbols(names, cls=Parameter, **kwargs)`` directly. The `Parameter` attributes `value`, `min`, `max` and `fixed` can also be provided directly. If given as a single ...
def jacobian(expr, symbols): """ Derive a symbolic expr w.r.t. each symbol in symbols. This returns a symbolic jacobian vector. :param expr: A sympy Expr. :param symbols: The symbols w.r.t. which to derive. """ jac = [] for symbol in symbols: # Differentiate to every param f...
def key2str(target): """ In ``symfit`` there are many dicts with symbol: value pairs. These can not be used immediately as \*\*kwargs, even though this would make a lot of sense from the context. This function wraps such dict to make them usable as \*\*kwargs immediately. :param target: `Mappin...
def name(self): """ Save name which can be used for alphabetic sorting and can be turned into a kwarg. """ base_str = 'd{}{}_'.format(self.derivative_count if self.derivative_count > 1 else '', self.expr) for var, count in self.variable_count: base_str += '...
def _baseobjective_from_callable(self, func, objective_type=MinimizeModel): """ symfit works with BaseObjective subclasses internally. If a custom objective is provided, we wrap it into a BaseObjective, MinimizeModel by default. :param func: Callable. If already an instance of B...
def resize_jac(self, func): """ Removes values with identical indices to fixed parameters from the output of func. func has to return the jacobian of a scalar function. :param func: Jacobian function to be wrapped. Is assumed to be the jacobian of a scalar function. ...
def resize_hess(self, func): """ Removes values with identical indices to fixed parameters from the output of func. func has to return the Hessian of a scalar function. :param func: Hessian function to be wrapped. Is assumed to be the Hessian of a scalar function. :r...
def execute(self, **minimizer_kwargs): """ Execute the chained-minimization. In order to pass options to the seperate minimizers, they can be passed by using the names of the minimizers as keywords. For example:: fit = Fit(self.model, self.xx, self.yy, self.ydata, ...
def _make_signature(self): """ Create a signature for `execute` based on the minimizers this `ChainedMinimizer` was initiated with. For the format, see the docstring of :meth:`ChainedMinimizer.execute`. :return: :class:`inspect.Signature` instance. """ # Create K...
def execute(self, bounds=None, jacobian=None, hessian=None, constraints=None, **minimize_options): """ Calls the wrapped algorithm. :param bounds: The bounds for the parameters. Usually filled by :class:`~symfit.core.minimizers.BoundedMinimizer`. :param jacobian: The Jacobia...