Example #1
0
File: dir.go Project: timtadh/sfp
func NewDir(c *config.Config, fmtr lattice.Formatter, showPr bool, dirname string) (*Dir, error) {
	samples := c.OutputFile(dirname)
	err := os.MkdirAll(samples, 0775)
	if err != nil {
		return nil, err
	}
	var prfmtr lattice.PrFormatter
	if showPr {
		prfmtr = fmtr.PrFormatter()
	}
	r := &Dir{
		config: c,
		fmtr:   fmtr,
		prfmtr: prfmtr,
		dir:    samples,
	}
	return r, nil
}
Example #2
0
File: file.go Project: timtadh/sfp
func NewFile(c *config.Config, fmtr lattice.Formatter, showPr bool, patternsFilename, embeddingsFilename, namesFilename, matricesFilename, prsFilename string) (*File, error) {
	patterns, err := os.Create(c.OutputFile(patternsFilename + fmtr.FileExt()))
	if err != nil {
		return nil, err
	}
	embeddings, err := os.Create(c.OutputFile(embeddingsFilename + fmtr.FileExt()))
	if err != nil {
		return nil, err
	}
	names, err := os.Create(c.OutputFile(namesFilename))
	if err != nil {
		return nil, err
	}
	var matrices io.WriteCloser
	var prs io.WriteCloser
	var prfmtr lattice.PrFormatter
	if showPr {
		prfmtr = fmtr.PrFormatter()
		if prfmtr != nil {
			prs, err = os.Create(c.OutputFile(prsFilename))
			if err != nil {
				return nil, err
			}
			matrices, err = os.Create(c.OutputFile(matricesFilename))
			if err != nil {
				return nil, err
			}
		}
	}
	r := &File{
		config:     c,
		fmtr:       fmtr,
		prfmtr:     prfmtr,
		patterns:   patterns,
		embeddings: embeddings,
		names:      names,
		matrices:   matrices,
		prs:        prs,
	}
	return r, nil
}