Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hail] LoadPlink ptype #6421

Merged
merged 8 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion hail/src/main/scala/is/hail/expr/types/TableType.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package is.hail.expr.types

import is.hail.expr.ir._
import is.hail.expr.types.physical.{PStruct, PType}
import is.hail.expr.types.virtual.{TStruct, Type}
import is.hail.rvd.RVDType
import is.hail.utils._
Expand All @@ -12,7 +13,9 @@ class TableTypeSerializer extends CustomSerializer[TableType](format => (
{ case tt: TableType => JString(tt.toString) }))

case class TableType(rowType: TStruct, key: IndexedSeq[String], globalType: TStruct) extends BaseType {
lazy val canonicalRVDType = RVDType(rowType.physicalType, key)
lazy val canonicalPType = PType.canonical(rowType).asInstanceOf[PStruct]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lazy since derived from constructor arg, which is immutable

lazy val canonicalRVDType = RVDType(canonicalPType, key)

key.foreach {k =>
if (!rowType.hasField(k))
throw new RuntimeException(s"key field $k not in row type: $rowType")
Expand Down
17 changes: 9 additions & 8 deletions hail/src/main/scala/is/hail/io/plink/LoadPlink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import is.hail.HailContext
import is.hail.annotations._
import is.hail.expr.ir.{LowerMatrixIR, MatrixHybridReader, MatrixRead, MatrixReader, MatrixValue, PruneDeadFields, TableRead, TableValue}
import is.hail.expr.types._
import is.hail.expr.types.physical.{PBoolean, PFloat64, PString, PStruct}
import is.hail.expr.types.virtual._
import is.hail.io.vcf.LoadVCF
import is.hail.rvd.{RVD, RVDContext, RVDType}
Expand Down Expand Up @@ -44,14 +45,14 @@ object LoadPlink {
"""^-?(?:\d+|\d*\.\d+)(?:[eE]-?\d+)?$""".r

def parseFam(filename: String, ffConfig: FamFileConfig,
fs: FS): (IndexedSeq[Row], TStruct) = {
fs: FS): (IndexedSeq[Row], PStruct) = {

val delimiter = unescapeString(ffConfig.delimiter)

val phenoSig = if (ffConfig.isQuantPheno) ("quant_pheno", TFloat64()) else ("is_case", TBoolean())
val phenoSig = if (ffConfig.isQuantPheno) ("quant_pheno", PFloat64()) else ("is_case", PBoolean())

val signature = TStruct(("id", TString()), ("fam_id", TString()), ("pat_id", TString()),
("mat_id", TString()), ("is_female", TBoolean()), phenoSig)
val signature = PStruct(("id", PString()), ("fam_id", PString()), ("pat_id", PString()),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not certain this change is worthwhile, because it's only used in Table, and immediately converted back to virtualType.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates the no-ptypes-if-no-offheap-data principle, but I think this is probably right -- we'll want to make some of these fields required, when we start doing that everywhere, and we won't be able to do that on virtual types.

("mat_id", PString()), ("is_female", PBoolean()), phenoSig)

val idBuilder = new ArrayBuilder[String]
val structBuilder = new ArrayBuilder[Row]
Expand Down Expand Up @@ -181,7 +182,7 @@ case class MatrixPLINKReader(
val fullMatrixType: MatrixType = MatrixType(
globalType = TStruct.empty(),
colKey = Array("s"),
colType = saSignature,
colType = saSignature.virtualType,
rowType = TStruct(
"locus" -> TLocus.schemaFromRG(referenceGenome),
"alleles" -> TArray(TString()),
Expand Down Expand Up @@ -210,7 +211,7 @@ case class MatrixPLINKReader(
nPartitions.getOrElse(sc.defaultMinPartitions)))

val kType = requestedType.canonicalRVDType.kType
val rvRowType = requestedType.rowType
val rvRowType = requestedType.canonicalPType

val hasRsid = requestedType.rowType.hasField("rsid")
val hasCmPos = requestedType.rowType.hasField("cm_position")
Expand Down Expand Up @@ -260,15 +261,15 @@ case class MatrixPLINKReader(
if (skipInvalidLociLocal && !rgLocal.forall(_.isValidLocus(contig, pos)))
None
else {
rvb.start(rvRowType.physicalType)
rvb.start(rvRowType)
rvb.startStruct()
rvb.addAnnotation(kType.types(0).virtualType, Locus.annotation(contig, pos, rgLocal))
rvb.startArray(2)
rvb.addString(ref)
rvb.addString(alt)
rvb.endArray()
if (hasRsid)
rvb.addAnnotation(rvRowType.types(2), rsid)
rvb.addAnnotation(rvRowType.types(2).virtualType, rsid)
if (hasCmPos)
rvb.addDouble(cmPos)
if (!dropSamples)
Expand Down
6 changes: 3 additions & 3 deletions hail/src/main/scala/is/hail/table/Table.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ object Table {
delimiter: String = "\\t",
missingValue: String = "NA"): String = {
val ffConfig = FamFileConfig(isQuantPheno, delimiter, missingValue)
val (data, typ) = LoadPlink.parseFam(path, ffConfig, HailContext.sFS)
val (data, ptyp) = LoadPlink.parseFam(path, ffConfig, HailContext.sFS)
val jv = JSONAnnotationImpex.exportAnnotation(
Row(typ.toString, data),
TStruct("type" -> TString(), "data" -> TArray(typ)))
Row(ptyp.toString, data),
TStruct("type" -> TString(), "data" -> TArray(ptyp.virtualType)))
JsonMethods.compact(jv)
}

Expand Down