chi2PValue float64
minCoverage int
cgnames []string
+ includeVariant1 bool
}
func (cmd *sliceNumpy) RunCommand(prog string, args []string, stdin io.Reader, stdout, stderr io.Writer) int {
flags.StringVar(&cmd.chi2CaseControlFile, "chi2-case-control-file", "", "tsv file or directory indicating cases and controls for Χ² test (if directory, all .tsv files will be read)")
flags.StringVar(&cmd.chi2CaseControlColumn, "chi2-case-control-column", "", "name of case/control column in case-control files for Χ² test (value must be 0 for control, 1 for case)")
flags.Float64Var(&cmd.chi2PValue, "chi2-p-value", 1, "do Χ² test and omit columns with p-value above this threshold")
+ flags.BoolVar(&cmd.includeVariant1, "include-variant-1", false, "include most common variant when building one-hot matrix")
cmd.filter.Flags(flags)
err = flags.Parse(args)
if err == flag.ErrHelp {
for seqname, cseq := range refseq {
pos := 0
for _, libref := range cseq {
- if libref.Tag > tagID(cmd.filter.MaxTag) {
+ if cmd.filter.MaxTag >= 0 && libref.Tag > tagID(cmd.filter.MaxTag) {
continue
}
tiledata := reftiledata[libref]
toMerge = make([][]int16, len(infiles))
}
var onehotIndirect [][2][]uint32 // [chunkIndex][axis][index]
+ var onehotChunkSize []uint32
var onehotXrefs [][]onehotXref
if *onehotSingle {
onehotIndirect = make([][2][]uint32, len(infiles))
+ onehotChunkSize = make([]uint32, len(infiles))
onehotXrefs = make([][]onehotXref, len(infiles))
}
annow := bufio.NewWriterSize(annof, 1<<20)
outcol := 0
for tag := tagstart; tag < tagend; tag++ {
- rt, ok := reftile[tag]
- if !ok {
- if mask == nil {
- outcol++
- }
- // Excluded by specified
- // regions, or reference does
- // not use any variant of this
- // tile. (TODO: log this?
- // mention it in annotations?)
+ rt := reftile[tag]
+ if rt == nil && mask != nil {
+ // Excluded by specified regions
+ continue
+ }
+ if cmd.filter.MaxTag >= 0 && tag > tagID(cmd.filter.MaxTag) {
continue
}
remap := variantRemap[tag-tagstart]
onehotChunk = append(onehotChunk, onehot...)
onehotXref = append(onehotXref, xrefs...)
}
+ if rt == nil {
+ // Reference does not use any
+ // variant of this tile
+ outcol++
+ continue
+ }
fmt.Fprintf(annow, "%d,%d,%d,=,%s,%d,,,\n", tag, outcol, rt.variant, rt.seqname, rt.pos)
variants := seq[tag]
reftilestr := strings.ToUpper(string(rt.tiledata))
}
if *onehotSingle {
onehotIndirect[infileIdx] = onehotChunk2Indirect(onehotChunk)
+ onehotChunkSize[infileIdx] = uint32(len(onehotChunk))
onehotXrefs[infileIdx] = onehotXref
n := len(onehotIndirect[infileIdx][0])
- log.Infof("%04d: keeping onehot coordinates in memory (n=%d, mem=%d)", infileIdx, n, n*8)
+ log.Infof("%04d: keeping onehot coordinates in memory (n=%d, mem=%d)", infileIdx, n, n*8*2)
}
if !(*onehotSingle || *onehotChunked) || *mergeOutput || *hgvsSingle {
- log.Infof("%04d: preparing numpy", infileIdx)
+ log.Infof("%04d: preparing numpy (rows=%d, cols=%d)", infileIdx, len(cmd.cgnames), 2*outcol)
throttleNumpyMem.Acquire()
rows := len(cmd.cgnames)
cols := 2 * outcol
outcol := 0
for col, v := range cgs[name].Variants {
tag := tagstart + tagID(col/2)
- if mask != nil && reftile[tag] == nil {
+ if mask != nil && reftile[tag] == nil || tag > tagID(cmd.filter.MaxTag) {
continue
}
if variants, ok := seq[tag]; ok && len(variants) > int(v) && len(variants[v].Sequence) > 0 {
}
onehot := make([]uint32, nzCount*2) // [r,r,r,...,c,c,c,...]
var xrefs []onehotXref
+ chunkOffset := uint32(0)
outcol := 0
for i, part := range onehotIndirect {
for i := range part[1] {
- part[1][i] += uint32(outcol)
+ part[1][i] += chunkOffset
}
copy(onehot[outcol:], part[0])
copy(onehot[outcol+nzCount:], part[1])
- outcol += len(part[0])
xrefs = append(xrefs, onehotXrefs[i]...)
+ outcol += len(part[0])
+ chunkOffset += onehotChunkSize[i]
+
part[0] = nil
part[1] = nil
onehotXrefs[i] = nil
}
var onehot [][]int8
var xref []onehotXref
- for homcol := 4; homcol < len(obs); homcol += 2 {
+ for homcol := 2; homcol < len(obs); homcol += 2 {
+ // homcol 0,1 correspond to tile variant 0, i.e.,
+ // no-call; homcol 2,3 correspond to the most common
+ // variant; so we (normally) start at homcol 4.
+ if homcol < 4 && !cmd.includeVariant1 {
+ continue
+ }
for het := 0; het < 2; het++ {
p := pvalue(obs[homcol+het], cmd.chi2Cases)
if cmd.chi2PValue < 1 && !(p < cmd.chi2PValue) {