Esempio n. 1
0
func TestGroup(t *testing.T) {
	eatError := func(m ingest.Metadata, err error) ingest.Metadata {
		if err != nil {
			t.Fatal(err)
		}
		return m
	}
	format, err := ingest.ParseFormatString("$(slide) $(sample) $(region) $(stain).tif")
	if err != nil {
		t.Fatal(err)
	}
	images := []*ingest.Image{
		{"path/a", eatError(format.Parse([]byte("slide-1 sample-1 L1 FFa.tif")))},
		{"path/b", eatError(format.Parse([]byte("slide-2 sample-1 L2 FFa.tif")))},
		{"path/c", eatError(format.Parse([]byte("slide-1 sample-1 L3 FFa.tif")))},
		{"path/d", eatError(format.Parse([]byte("slide-2 sample-1 L1 FFb.tif")))},
		{"path/e", eatError(format.Parse([]byte("slide-1 sample-1 L2 FFb.tif")))},
		{"path/f", eatError(format.Parse([]byte("slide-2 sample-1 L3 FFb.tif")))},
		{"path/g", eatError(format.Parse([]byte("slide-1 sample-1 L1 FFc.tif")))},
		{"path/h", eatError(format.Parse([]byte("slide-2 sample-1 L2 FFc.tif")))},
		{"path/i", eatError(format.Parse([]byte("slide-1 sample-1 L3 FFc.tif")))},
	}
	rows := MakeRows(images, []string{"slide", "region"}, []string{})
	for _, row := range rows {
		t.Log("row", row.Meta())
		for _, img := range row.Images() {
			t.Log(img)
		}
		t.Log()
	}
	paths := []string{
		"path/a",
		"path/g",
		"path/e",
		"path/c",
		"path/i",
		"path/d",
		"path/b",
		"path/h",
		"path/f",
	}
	c := &Chart{rows: rows}
	for i, img := range c.Images() {
		if img.Path != paths[i] {
			t.Fatal("img != paths[i]", img, paths[i])
		}
	}
}
Esempio n. 2
0
func TestMakeCharts(t *testing.T) {
	eatError := func(m ingest.Metadata, err error) ingest.Metadata {
		if err != nil {
			t.Fatal(err)
		}
		return m
	}
	format, err := ingest.ParseFormatString("$(slide) $(sample) $(region) $(stain).tif")
	if err != nil {
		t.Fatal(err)
	}
	images := []*ingest.Image{
		{"path/a-1", eatError(format.Parse([]byte("slide-1 sample-1 L1 FFa.tif")))},
		{"path/b-1", eatError(format.Parse([]byte("slide-1 sample-1 L2 FFa.tif")))},
		{"path/c-1", eatError(format.Parse([]byte("slide-1 sample-1 L3 FFa.tif")))},
		{"path/d-1", eatError(format.Parse([]byte("slide-1 sample-1 L1 FFb.tif")))},
		{"path/e-1", eatError(format.Parse([]byte("slide-1 sample-1 L2 FFb.tif")))},
		{"path/f-1", eatError(format.Parse([]byte("slide-1 sample-1 L3 FFb.tif")))},
		{"path/g-1", eatError(format.Parse([]byte("slide-1 sample-1 L1 FFc.tif")))},
		{"path/h-1", eatError(format.Parse([]byte("slide-1 sample-1 L2 FFc.tif")))},
		{"path/i-1", eatError(format.Parse([]byte("slide-1 sample-1 L3 FFc.tif")))},
		{"path/a-2", eatError(format.Parse([]byte("slide-2 sample-1 L1 FFa.tif")))},
		{"path/b-2", eatError(format.Parse([]byte("slide-2 sample-1 L2 FFa.tif")))},
		{"path/c-2", eatError(format.Parse([]byte("slide-2 sample-1 L3 FFa.tif")))},
		{"path/d-2", eatError(format.Parse([]byte("slide-2 sample-1 L1 FFb.tif")))},
		{"path/e-2", eatError(format.Parse([]byte("slide-2 sample-1 L2 FFb.tif")))},
		{"path/f-2", eatError(format.Parse([]byte("slide-2 sample-1 L3 FFb.tif")))},
		{"path/g-2", eatError(format.Parse([]byte("slide-2 sample-1 L1 FFc.tif")))},
		{"path/h-2", eatError(format.Parse([]byte("slide-2 sample-1 L2 FFc.tif")))},
		{"path/i-2", eatError(format.Parse([]byte("slide-2 sample-1 L3 FFc.tif")))},
		{"path/a-3", eatError(format.Parse([]byte("slide-1 sample-2 L1 FFa.tif")))},
		{"path/b-3", eatError(format.Parse([]byte("slide-1 sample-2 L2 FFa.tif")))},
		{"path/c-3", eatError(format.Parse([]byte("slide-1 sample-2 L3 FFa.tif")))},
		{"path/d-3", eatError(format.Parse([]byte("slide-1 sample-2 L1 FFb.tif")))},
		{"path/e-3", eatError(format.Parse([]byte("slide-1 sample-2 L2 FFb.tif")))},
		{"path/f-3", eatError(format.Parse([]byte("slide-1 sample-2 L3 FFb.tif")))},
		{"path/g-3", eatError(format.Parse([]byte("slide-1 sample-2 L1 FFc.tif")))},
		{"path/h-3", eatError(format.Parse([]byte("slide-1 sample-2 L2 FFc.tif")))},
		{"path/i-3", eatError(format.Parse([]byte("slide-1 sample-2 L3 FFc.tif")))},
		{"path/a-4", eatError(format.Parse([]byte("slide-2 sample-2 L1 FFa.tif")))},
		{"path/b-4", eatError(format.Parse([]byte("slide-2 sample-2 L2 FFa.tif")))},
		{"path/c-4", eatError(format.Parse([]byte("slide-2 sample-2 L3 FFa.tif")))},
		{"path/d-4", eatError(format.Parse([]byte("slide-2 sample-2 L1 FFb.tif")))},
		{"path/e-4", eatError(format.Parse([]byte("slide-2 sample-2 L2 FFb.tif")))},
		{"path/f-4", eatError(format.Parse([]byte("slide-2 sample-2 L3 FFb.tif")))},
		{"path/g-4", eatError(format.Parse([]byte("slide-2 sample-2 L1 FFc.tif")))},
		{"path/h-4", eatError(format.Parse([]byte("slide-2 sample-2 L2 FFc.tif")))},
		{"path/i-4", eatError(format.Parse([]byte("slide-2 sample-2 L3 FFc.tif")))},
	}
	charts := MakeCharts(images, []string{"sample", "slide"}, []string{"region"}, []string{"stain"})
	for _, chart := range charts {
		t.Log("chart", chart.Meta())
		for _, row := range chart.rows {
			t.Log("row", row.Meta())
			for _, img := range row.Images() {
				t.Log(img)
			}
			t.Log()
		}
		t.Log()
	}
}
Esempio n. 3
0
func main() {
	args, optargs, err := getopt.GetOpt(
		os.Args[1:],
		"hl:d:o:f:s:r:c:",
		[]string{"help", "directory=", "output=", "format=",
			"column-sort=", "row-group=", "chart-group=",
			"overlap-columns="},
	)
	if err != nil {
		fmt.Fprintln(os.Stderr, "error parsing command line flags", err)
		Usage(1)
	}
	if len(args) > 0 {
		fmt.Fprintf(os.Stderr, "unexpected trailing args `%v`\n", strings.Join(args, " "))
		Usage(1)
	}

	format, err := ingest.ParseFormatString("$(slide) $(subject) $(region) $(stain).tif")
	if err != nil {
		log.Fatal(err)
	}
	directory := ""
	rowGroup := Vars("region")
	chartGroup := Vars("subject,slide")
	columnSort := Vars("stain")
	overlapCols := Vars("")
	for _, oa := range optargs {
		switch oa.Opt() {
		case "-h", "--help":
			Usage(0)
			os.Exit(0)
		case "-f", "--format":
			format, err = ingest.ParseFormatString(oa.Arg())
			if err != nil {
				fmt.Fprintf(os.Stderr, "Invalid format string (%v) '%v'\n", oa.Opt(), oa.Arg())
				fmt.Fprintln(os.Stderr, err)
				Usage(1)
			}
		case "-d", "--directory":
			directory, err = filepath.Abs(oa.Arg())
			if err != nil {
				fmt.Fprintf(os.Stderr, "Bad directory (%v) '%v' supplied\n", oa.Opt(), oa.Arg())
				Usage(1)
			}
			if _, err := os.Stat(directory); err != nil && os.IsNotExist(err) {
				fmt.Fprintf(os.Stderr, "Bad directory (%v) '%v' supplied\n", oa.Opt(), oa.Arg())
				Usage(1)
			} else if err != nil {
				fmt.Fprintln(os.Stderr, err)
				fmt.Fprintf(os.Stderr, "Bad directory (%v) '%v' supplied\n", oa.Opt(), oa.Arg())
				Usage(1)
			}
		case "-s", "--column-sort":
			columnSort = Vars(oa.Arg())
		case "-r", "--row-group":
			rowGroup = Vars(oa.Arg())
		case "-c", "--chart-group":
			chartGroup = Vars(oa.Arg())
		case "--overlap-columns":
			overlapCols = Vars(oa.Arg())
		default:
			fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
			Usage(1)
		}
	}

	log.Println(directory)

	files, err := ingest.Ingest(directory, format)
	if err != nil {
		log.Fatal(err)
	}
	log.Println(files)
	for _, img := range files {
		log.Println(img)
	}

	C := charts.MakeCharts(files, chartGroup, rowGroup, columnSort, overlapCols)
	for _, chart := range C {
		log.Println("chart", chart.Meta())
		for _, row := range chart.Rows() {
			log.Println("row", row.Meta())
			for _, img := range row.Images() {
				log.Println(img)
			}
			log.Println()
		}
		log.Println()
	}

	log.Println("done")
	fmt.Println(charts.ChartsHTML(C))
}