Exemple #1
0
def reference_remove_sequence():
    try:
        data = flask.request.json
        scala_object(Env.hail().variant,
                     'ReferenceGenome').removeSequence(data['name'])
        return '', 204
    except FatalError as e:
        return flask.jsonify({'message': e.args[0]}), 400
Exemple #2
0
 def _convert_to_j(self, annotation):
     if annotation is not None:
         return scala_object(Env.hail().annotations, 'Annotation').fromSeq(
             Env.jutils().arrayListToISeq(
                 [t._convert_to_j(annotation.get(f)) for f, t in self.items()]))
     else:
         return None
Exemple #3
0
def create_backward_compatibility_files():
    import os

    all_values_table, all_values_matrix_table = create_all_values_datasets()

    file_version = Env.hail().expr.ir.FileFormat.version().toString()
    supported_codecs = scala_object(Env.hail().io, 'BufferSpec').specs()

    table_dir = resource(
        os.path.join('backward_compatability', str(file_version), 'table'))
    if not os.path.exists(table_dir):
        os.makedirs(table_dir)

    matrix_table_dir = resource(
        os.path.join('backward_compatability', str(file_version),
                     'matrix_table'))
    if not os.path.exists(matrix_table_dir):
        os.makedirs(matrix_table_dir)

    i = 0
    for codec in supported_codecs:
        all_values_table.write(os.path.join(table_dir, f'{i}.ht'),
                               overwrite=True,
                               _codec_spec=codec.toString())
        all_values_matrix_table.write(os.path.join(matrix_table_dir,
                                                   f'{i}.hmt'),
                                      overwrite=True,
                                      _codec_spec=codec.toString())
        i += 1
Exemple #4
0
 def __init__(self, key_type, value_type, required=False):
     jtype = scala_object(Env.hail().expr,
                          'TDict').apply(key_type._jtype, value_type._jtype,
                                         required)
     self.key_type = key_type
     self.value_type = value_type
     super(TDict, self).__init__(jtype)
Exemple #5
0
 def _convert_to_j(self, annotation):
     if annotation is not None:
         return scala_object(Env.hail().annotations, 'Annotation').fromSeq(
             Env.jutils().arrayListToISeq(
                 [t._convert_to_j(annotation.get(f)) for f, t in self.items()]))
     else:
         return None
Exemple #6
0
 def random(rows, cols, block_size):
     hc = Env.hc()
     return BlockMatrix(
         hc,
         scala_object(Env.hail().distributedmatrix,
                      'BlockMatrix').random(hc._jhc, rows, cols,
                                            block_size))
Exemple #7
0
 def __init__(self, element_type, required=False):
     """
     :param :class:`.Type` element_type: Hail type of set element
     """
     jtype = scala_object(Env.hail().expr,
                          'TSet').apply(element_type._jtype, required)
     self.element_type = element_type
     super(TSet, self).__init__(jtype)
Exemple #8
0
 def _convert_to_j(self, annotation):
     if annotation is not None:
         return scala_object(Env.hail().annotations, 'Annotation').fromSeq(
             Env.jutils().arrayListToISeq([
                 f.typ._convert_to_j(annotation.get(f.name))
                 for f in self.fields
             ]))
     else:
         return None
Exemple #9
0
 def test_codecs_table(self):
     from hail.utils.java import Env, scala_object
     codecs = scala_object(Env.hail().io, 'CodecSpec').codecSpecs()
     rt = self.get_vds().rows()
     temp = new_temp_file(suffix='ht')
     for codec in codecs:
         rt.write(temp, overwrite=True, _codec_spec=codec.toString())
         rt2 = hl.read_table(temp)
         self.assertTrue(rt._same(rt2))
Exemple #10
0
 def test_codecs_table(self):
     from hail.utils.java import scala_object
     codecs = scala_object(Env.hail().io, 'CodecSpec').codecSpecs()
     rt = self.get_vds().rows()
     temp = new_temp_file(suffix='ht')
     for codec in codecs:
         rt.write(temp, overwrite=True, _codec_spec=codec.toString())
         rt2 = hl.read_table(temp)
         self.assertTrue(rt._same(rt2))
Exemple #11
0
 def test_codecs_matrix(self):
     from hail.utils.java import Env, scala_object
     codecs = scala_object(Env.hail().io, 'CodecSpec').codecSpecs()
     ds = self.get_vds()
     temp = new_temp_file(suffix='hmt')
     for codec in codecs:
         ds.write(temp, overwrite=True, _codec_spec=codec.toString())
         ds2 = hl.read_matrix_table(temp)
         self.assertTrue(ds._same(ds2))
Exemple #12
0
    def __init__(self, **field_types):
        self._field_types = field_types
        self._fields = tuple(field_types)

        self._get_jtype = lambda: scala_object(Env.hail().expr.types.virtual, 'TStruct').apply(
            list(self._fields),
            [t._jtype for f, t in self._field_types.items()],
            False)

        super(tstruct, self).__init__()
Exemple #13
0
    def __init__(self, **field_types):
        self._field_types = field_types
        self._fields = tuple(field_types)

        self._get_jtype = lambda: scala_object(Env.hail(
        ).expr.types, 'TStruct').apply(list(
            self._fields), [t._jtype
                            for f, t in self._field_types.items()], False)

        super(tstruct, self).__init__()
Exemple #14
0
 def __init__(self, contig, position, reference_genome=None):
     if isinstance(contig, int):
         contig = str(contig)
     jrep = scala_object(Env.hail().variant,
                         'Locus').apply(contig, position)
     self._init_from_java(jrep)
     self._contig = contig
     self._position = position
     self._rg = reference_genome if reference_genome else Env.hc(
     ).default_reference
Exemple #15
0
    def __init__(self, contig, position, reference_genome='default'):
        if isinstance(contig, int):
            contig = str(contig)

        self._rg = reference_genome

        jrep = scala_object(Env.hail().variant, 'Locus').apply(contig, position, self._rg._jrep)
        self._init_from_java(jrep)
        self._contig = contig
        self._position = position
Exemple #16
0
 def __init__(self, contig, start, ref, alts, reference_genome=None):
     if isinstance(contig, int):
         contig = str(contig)
     jrep = scala_object(Env.hail().variant,
                         'Variant').apply(contig, start, ref, alts)
     self._init_from_java(jrep)
     self._contig = contig
     self._start = start
     self._ref = ref
     self._rg = reference_genome if reference_genome else Env.hc(
     ).default_reference
Exemple #17
0
    def __init__(self, contig, position, reference_genome='default'):
        if isinstance(contig, int):
            contig = str(contig)

        self._rg = reference_genome

        jrep = scala_object(Env.hail().variant,
                            'Locus').apply(contig, position, self._rg._jrep)
        self._init_from_java(jrep)
        self._contig = contig
        self._position = position
Exemple #18
0
    def __init__(self, names, types, required=False):

        if len(names) != len(types):
            raise ValueError('length of names and types not equal: %d and %d' %
                             (len(names), len(types)))
        jtype = scala_object(Env.hail().expr,
                             'TStruct').apply(names,
                                              map(lambda t: t._jtype, types),
                                              required)
        self.fields = [Field(names[i], types[i]) for i in range(len(names))]

        super(TStruct, self).__init__(jtype)
Exemple #19
0
    def from_fields(cls, fields, required=False):
        """Creates a new TStruct from field objects.

        :param fields: The TStruct fields.
        :type fields: list of :class:`.Field`

        :param bool required: Flag for whether the struct can be missing.

        :return: TStruct from input fields
        :rtype: :class:`.TStruct`
        """

        struct = TStruct.__new__(cls)
        struct.fields = fields
        jfields = [
            scala_object(Env.hail().expr,
                         'Field').apply(f.name, f.typ._jtype, i)
            for i, f in enumerate(fields)
        ]
        jtype = scala_object(Env.hail().expr,
                             'TStruct').apply(jindexed_seq(jfields), required)
        return TStruct._from_java(jtype)
Exemple #20
0
    def parse(cls, string, reference_genome='default'):
        """Parses a locus object from a CHR:POS string.

        **Examples**

        >>> l1 = hl.Locus.parse('1:101230')
        >>> l2 = hl.Locus.parse('X:4201230')

        :param str string: String to parse.
        :param reference_genome: Reference genome to use. Default is :func:`~hail.default_reference`.
        :type reference_genome: :obj:`str` or :class:`.ReferenceGenome`

        :rtype: :class:`.Locus`
        """

        return Locus._from_java(scala_object(Env.hail().variant, 'Locus').parse(string, reference_genome._jrep), reference_genome)
Exemple #21
0
    def parse(cls, string, reference_genome=None):
        """Parses a locus object from a CHR:POS string.

        **Examples**

        >>> l1 = Locus.parse('1:101230')
        >>> l2 = Locus.parse('X:4201230')

        :param str string: String to parse.
        :param reference_genome: Reference genome to use. Default is :py:meth:`hail.api1.HailContext.default_reference`.
        :type reference_genome: :class:`.GenomeReference`

        :rtype: :class:`.Locus`
        """
        rg = reference_genome if reference_genome else Env.hc(
        ).default_reference
        return Locus._from_java(
            scala_object(Env.hail().variant, 'Locus').parse(string), rg)
Exemple #22
0
    def parse(cls, string, reference_genome='default'):
        """Parses a locus object from a CHR:POS string.

        **Examples**

        >>> l1 = hl.Locus.parse('1:101230')
        >>> l2 = hl.Locus.parse('X:4201230')

        :param str string: String to parse.
        :param reference_genome: Reference genome to use. Default is :func:`~hail.default_reference`.
        :type reference_genome: :obj:`str` or :class:`.ReferenceGenome`

        :rtype: :class:`.Locus`
        """

        return Locus._from_java(
            scala_object(Env.hail().variant,
                         'Locus').parse(string, reference_genome._jrep),
            reference_genome)
Exemple #23
0
    def parse(cls, string, reference_genome=None):
        """Parses a variant object from a string.

        There are two acceptable formats: CHR:POS:REF:ALT, and
        CHR:POS:REF:ALT1,ALT2,...ALTN.  Below is an example of
        each:

        >>> v_biallelic = Variant.parse('16:20012:A:TT')
        >>> v_multiallelic = Variant.parse('16:12311:T:C,TTT,A')

        :param str string: String to parse.
        :param reference_genome: Reference genome to use. Default is :py:meth:`hail.api1.HailContext.default_reference`.
        :type reference_genome: :class:`.GenomeReference`

        :rtype: :class:`.Variant`
        """
        rg = reference_genome if reference_genome else Env.hc(
        ).default_reference
        jrep = scala_object(Env.hail().variant, 'Variant').parse(string)
        return Variant._from_java(jrep, rg)
Exemple #24
0
def create_backward_compatibility_files():
    import os

    all_values_table, all_values_matrix_table = create_all_values_datasets()

    file_version = Env.hail().variant.FileFormat.version().toString()
    supported_codecs = scala_object(Env.hail().io, 'CodecSpec').supportedCodecSpecs()

    table_dir = 'backward_compatability/{}/table'.format(file_version)
    if not os.path.exists(table_dir):
        os.makedirs(table_dir)

    matrix_table_dir = 'backward_compatability/{}/matrix_table'.format(file_version)
    if not os.path.exists(matrix_table_dir):
        os.makedirs(matrix_table_dir)

    i = 0
    for codec in supported_codecs:
        all_values_table.write('{}/{}.ht'.format(table_dir, i), overwrite=True, _codec_spec=codec.toString())
        all_values_matrix_table.write('{}/{}.hmt'.format(matrix_table_dir, i), overwrite=True, _codec_spec=codec.toString())
        i += 1
Exemple #25
0
def create_backward_compatibility_files():
    import os

    all_values_table, all_values_matrix_table = create_all_values_datasets()

    file_version = Env.hail().variant.FileFormat.version().toString()
    supported_codecs = scala_object(Env.hail().io, 'CodecSpec').supportedCodecSpecs()

    table_dir = resource(os.path.join('backward_compatability', str(file_version), 'table'))
    if not os.path.exists(table_dir):
        os.makedirs(table_dir)

    matrix_table_dir = resource(os.path.join('backward_compatability', str(file_version), 'matrix_table'))
    if not os.path.exists(matrix_table_dir):
        os.makedirs(matrix_table_dir)

    i = 0
    for codec in supported_codecs:
        all_values_table.write(os.path.join(table_dir, f'{i}.ht'), overwrite=True, _codec_spec=codec.toString())
        all_values_matrix_table.write(os.path.join(matrix_table_dir, f'{i}.hmt'), overwrite=True,
                                      _codec_spec=codec.toString())
        i += 1
Exemple #26
0
 def __init__(self, reference_genome=None, required=False):
     self._rg = reference_genome if reference_genome else Env.hc(
     ).default_reference
     jtype = scala_object(Env.hail().expr,
                          'TInterval').apply(self._rg._jrep, required)
     super(TInterval, self).__init__(jtype)
Exemple #27
0
 def __init__(self, ref, alt):
     jaa = scala_object(Env.hail().variant, 'AltAllele').apply(ref, alt)
     self._init_from_java(jaa)
     self._ref = ref
     self._alt = alt
Exemple #28
0
 def __init__(self, required=False):
     super(TCall, self).__init__(
         scala_object(Env.hail().expr, 'TCall').apply(required))
Exemple #29
0
 def remove_sequence(self, name):
     scala_object(Env.hail().variant,
                  'ReferenceGenome').removeSequence(name)
Exemple #30
0
 def __init__(self):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types, 'TInt32Optional')
     super(_tint32, self).__init__()
Exemple #31
0
 def __init__(self, element_type):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types, 'TArray').apply(element_type._jtype, False)
     self._element_type = element_type
     super(tarray, self).__init__()
Exemple #32
0
 def __init__(self):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types, 'TStringOptional')
     super(_tstr, self).__init__()
Exemple #33
0
 def __init__(self, required=False):
     super(TInt64, self).__init__(
         scala_object(Env.hail().expr, 'TInt64').apply(required))
     self.required = required
Exemple #34
0
 def __init__(self, key_type, value_type):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types.virtual, 'TDict').apply(
         key_type._jtype, value_type._jtype, False)
     self._key_type = key_type
     self._value_type = value_type
     super(tdict, self).__init__()
Exemple #35
0
 def __init__(self):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types.virtual, 'TCallOptional')
     super(_tcall, self).__init__()
Exemple #36
0
 def __init__(self, *types):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types.virtual, 'TTuple').apply(map(lambda t: t._jtype, types),
                                                                                   False)
     self._types = types
     super(ttuple, self).__init__()
Exemple #37
0
 def __init__(self, key_type, value_type):
     self._get_jtype = lambda: scala_object(Env.hail(
     ).expr.types, 'TDict').apply(key_type._jtype, value_type._jtype, False)
     self._key_type = key_type
     self._value_type = value_type
     super(tdict, self).__init__()
Exemple #38
0
 def __init__(self, *types):
     self._get_jtype = lambda: scala_object(Env.hail(
     ).expr.types, 'TTuple').apply(map(lambda t: t._jtype, types), False)
     self._types = types
     super(ttuple, self).__init__()
Exemple #39
0
 def __init__(self):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types,
                                            'TCallOptional')
     super(_tcall, self).__init__()
 def remove_sequence(self, name):
     scala_object(self._hail_package.variant,
                  'ReferenceGenome').removeSequence(name)
Exemple #41
0
 def __init__(self, element_type):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types.virtual, 'TSet').apply(element_type._jtype, False)
     self._element_type = element_type
     super(tset, self).__init__()
 def remove_liftover(self, name, dest_reference_genome):
     scala_object(self._hail_package.variant,
                  'ReferenceGenome').referenceRemoveLiftover(
                      name, dest_reference_genome)
Exemple #43
0
 def __init__(self):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types, 'TVoid')
     super(_tvoid, self).__init__()
Exemple #44
0
 def __init__(self):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types, 'TBooleanOptional')
     super(_tbool, self).__init__()
Exemple #45
0
 def __init__(self, point_type):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types.virtual, 'TInterval').apply(self.point_type._jtype, False)
     self._point_type = point_type
     super(tinterval, self).__init__()
Exemple #46
0
 def __init__(self):
     self._get_jtype = lambda: scala_object(Env.hail().expr.types, 'TFloat64Optional')
     super(_tfloat64, self).__init__()
Exemple #47
0
 def __init__(self, reference_genome='default'):
     self._rg = reference_genome
     self._get_jtype = lambda: scala_object(Env.hail().expr.types.virtual, 'TLocus').apply(self._rg._jrep,
                                                                                   False)
     super(tlocus, self).__init__()
Exemple #48
0
 def remove_liftover(self, name, dest_reference_genome):
     scala_object(Env.hail().variant,
                  'ReferenceGenome').referenceRemoveLiftover(
                      name, dest_reference_genome)
Exemple #49
0
 def __init__(self, required=False):
     super(TAltAllele, self).__init__(
         scala_object(Env.hail().expr, 'TAltAllele').apply(required))
Exemple #50
0
def blocking_reference_add_sequence(data):
    scala_object(Env.hail().variant, 'ReferenceGenome').addSequence(
        data['name'], data['fasta_file'], data['index_file'])
Exemple #51
0
def blocking_reference_remove_sequence(data):
    scala_object(
        Env.hail().variant, 'ReferenceGenome').removeSequence(data['name'])