예제 #1
0
파일: context.py 프로젝트: Fedja/hail
    def import_keytable(self,
                        path,
                        npartitions=None,
                        config=TextTableConfig()):
        """Import delimited text file (text table) as key table.

        The resulting key table will have no key columns, use :py:meth:`.KeyTable.key_by`
        to specify keys.

        :param path: files to import.
        :type path: str or list of str

        :param npartitions: Number of partitions.
        :type npartitions: int or None

        :param config: Configuration options for importing text files
        :type config: :class:`.TextTableConfig`

        :return: Key table constructed from text table.
        :rtype: :class:`.KeyTable`
        """

        if not config:
            config = TextTableConfig()

        jkt = self._jhc.importKeyTable(jindexed_seq_args(path),
                                       joption(npartitions), config._to_java())
        return KeyTable(self, jkt)
예제 #2
0
    def import_keytable(self,
                        path,
                        key_names=[],
                        npartitions=None,
                        config=TextTableConfig()):
        """Import delimited text file (text table) as KeyTable.

        :param path: files to import.
        :type path: str or list of str

        :param key_names: The name(s) of fields to be considered keys
        :type key_names: str or list of str

        :param npartitions: Number of partitions.
        :type npartitions: int or None

        :param config: Configuration options for importing text files
        :type config: :class:`.TextTableConfig`

        :rtype: :class:`.KeyTable`
        """

        if not config:
            config = TextTableConfig()

        jkt = self._jhc.importKeyTable(jindexed_seq_args(path),
                                       jindexed_seq_args(key_names),
                                       joption(npartitions), config._to_java())
        return KeyTable(self, jkt)
예제 #3
0
    def import_annotations_table(self,
                                 path,
                                 variant_expr,
                                 code=None,
                                 npartitions=None,
                                 config=TextTableConfig()):
        """Import variants and variant annotations from a delimited text file
        (text table) as a sites-only VariantDataset.

        :param path: The files to import.
        :type path: str or list of str

        :param str variant_expr: Expression to construct a variant
            from a row of the text table.  Must have type Variant.

        :param code: Expression to build the variant annotations.
        :type code: str or None

        :param npartitions: Number of partitions.
        :type npartitions: int or None

        :param config: Configuration options for importing text files
        :type config: :class:`.TextTableConfig`

        :rtype: :class:`.VariantDataset`
        """

        jvds = self._jhc.importAnnotationsTables(jindexed_seq_args(path),
                                                 variant_expr, joption(code),
                                                 joption(npartitions),
                                                 config._to_java())
        return VariantDataset(self, jvds)
예제 #4
0
    def import_annotations_table(self,
                                 path,
                                 variant_expr,
                                 code=None,
                                 npartitions=None,
                                 config=None):
        """Import variants and variant annotations from a delimited text file
        (text table) as a sites-only VariantDataset.

        :param path: The files to import.
        :type path: str or list of str

        :param str variant_expr: Expression to construct a variant
            from a row of the text table.  Must have type Variant.

        :param code: Expression to build the variant annotations.
        :type code: str or None

        :param npartitions: Number of partitions.
        :type npartitions: int or None

        :param config: Configuration options for importing text files
        :type config: :class:`.TextTableConfig` or None

        :rtype: :class:`.VariantDataset`
        """

        pargs = ['importannotations', 'table']
        if isinstance(path, str):
            pargs.append(path)
        else:
            for p in path:
                pargs.append(p)

        pargs.append('--variant-expr')
        pargs.append(variant_expr)

        if code:
            pargs.append('--code')
            pargs.append(code)

        if npartitions:
            pargs.append('--npartition')
            pargs.append(npartitions)

        if not config:
            config = TextTableConfig()

        pargs.extend(config._as_pargs())

        return self._run_command(None, pargs)
예제 #5
0
    def import_keytable(self, path, key_names, npartitions=None, config=None):
        """Import delimited text file (text table) as KeyTable.

        :param path: files to import.
        :type path: str or list of str

        :param key_names: The name(s) of fields to be considered keys
        :type key_names: str or list of str

        :param npartitions: Number of partitions.
        :type npartitions: int or None

        :param config: Configuration options for importing text files
        :type config: :class:`.TextTableConfig` or None

        :rtype: :class:`.KeyTable`
        """

        path_args = []
        if isinstance(path, str):
            path_args.append(path)
        else:
            for p in path:
                path_args.append(p)

        if not isinstance(key_names, str):
            key_names = ','.join(key_names)

        if not npartitions:
            npartitions = self.sc.defaultMinPartitions

        if not config:
            config = TextTableConfig()

        return KeyTable(
            self,
            self._hail.keytable.KeyTable.importTextTable(
                self._jsc, jarray(self._jvm.java.lang.String, path_args),
                key_names, npartitions, config._to_java()))