예제 #1
0
파일: config.go 프로젝트: cgravill/antha
// Transfer fields from conf to params instantiating certain fields from a
// factory. conf is like the type of params but with wtype.FromFactory entries
// for certain fields/elements. Assign values of conf to params. Use
// factory.GetComponentByType to instantiate FromFactory instances and assign
// them to the appropriate entry in params.
//
// Assumes that params is a nil instance and conf is like type of params but
// with some values as FromFactory rather than the appropriate interface type
func (p *Config) transfer(cv reflect.Value, pv reflect.Value) error {
	factoryType := reflect.TypeOf(wtype.FromFactory{})
	ct := cv.Type()
	pt := pv.Type()
	switch {
	case ct.AssignableTo(pt):
		pv.Set(cv)
	case ct == factoryType:
		v := cv.Interface().(wtype.FromFactory)
		terms := strings.Split(v.String, ":")
		if len(terms) != 2 {
			return fmt.Errorf("cannot parse factory string: %s", v.String)
		}
		var newV interface{}
		switch terms[0] {
		case "component":
			newV = factory.GetComponentByType(terms[1])
		case "tipbox":
			newV = factory.GetTipboxByType(terms[1])
		case "plate":
			newV = factory.GetPlateByType(terms[1])
		default:
			return fmt.Errorf("cannot parse factory string: %s", v.String)
		}
		nv := reflect.ValueOf(newV)
		nt := nv.Type()
		if !nt.AssignableTo(pt) {
			return fmt.Errorf("cannot convert %v to %v", nt, pt)
		}
		pv.Set(nv)
	default:
		pk := pt.Kind()
		ck := ct.Kind()

		if pk != ck {
			return fmt.Errorf("cannot convert %v to %v", ct, pt)
		}
		switch ck {
		case reflect.Slice:
			cvl := cv.Len()
			newSlice := reflect.MakeSlice(pt, cvl, cvl)
			pv.Set(newSlice)
			for i := 0; i < cvl; i += 1 {
				if err := p.transfer(cv.Index(i), pv.Index(i)); err != nil {
					return err
				}
			}
		case reflect.Map:
			newMap := reflect.MakeMap(pt)
			pv.Set(newMap)
			for _, key := range cv.MapKeys() {
				if err := p.transfer(pv.MapIndex(key), pv.MapIndex(key)); err != nil {
					return err
				}
			}
		case reflect.Struct:
			ctn := ct.NumField()
			for i := 0; i < ctn; i += 1 {
				if err := p.transfer(cv.Field(i), pv.Field(i)); err != nil {
					return err
				}
			}
		case reflect.Ptr:
			if err := p.transfer(cv.Elem(), pv.Elem()); err != nil {
				return err
			}
		default:
			return fmt.Errorf("cannot convert %v to %v", ct, pt)
		}
	}

	return nil
}
예제 #2
0
파일: Assembly.go 프로젝트: cgravill/antha
func main() {
	eid, _ := uuid.NewV4()
	em := equipmentManager.NewAnthaEquipmentManager(eid.String())
	defer em.Shutdown()
	eem := equipmentManager.EquipmentManager(em)
	equipmentManager.SetEquipmentManager(&eem)
	//manual driver equipment
	mid, _ := uuid.NewV4()
	var mde equipment.Equipment
	var amd manual.AnthaManual
	amd = *manual.NewAnthaManual(mid.String())
	mde = amd
	em.RegisterEquipment(&mde)

	//cui logger middleware
	cmw := middleware.NewLogToCui(&amd.Cui)
	log_id, _ := uuid.NewV4()
	l := logger.NewAnthaFileLogger(log_id.String())
	l.RegisterMiddleware(cmw)
	var params Parameters
	var inputs Inputs

	// give this thing an arbitrary ID for testing

	id := execute.ThreadID(fmt.Sprintf("EXPERIMENT_1_%s", string(eid.String()[1:5])))

	fmt.Println(id)

	// set up parameters and inputs

	params.Reactionvolume = wunit.NewVolume(20, "ul")
	params.Partconc = wunit.NewConcentration(0.0001, "g/l")
	params.Vectorconc = wunit.NewConcentration(0.001, "g/l")
	params.Atpvol = wunit.NewVolume(1, "ul")
	params.Revol = wunit.NewVolume(1, "ul")
	params.Ligvol = wunit.NewVolume(1, "ul")
	params.Reactiontemp = wunit.NewTemperature(25, "C")
	params.Reactiontime = wunit.NewTime(1800, "s")
	params.Inactivationtemp = wunit.NewTemperature(40, "C")
	params.Inactivationtime = wunit.NewTime(60, "s")
	params.BlockID = id

	inputs.Parts = make([]*wtype.LHComponent, 4)

	for i := 0; i < 4; i++ {
		inputs.Parts[i] = factory.GetComponentByType("dna_part")
		inputs.Parts[i].CName = inputs.Parts[i].CName + "_" + strconv.Itoa(i+1)
	}

	inputs.Vector = factory.GetComponentByType("standard_cloning_vector_mark_1")
	inputs.RestrictionEnzyme = factory.GetComponentByType("SapI")
	inputs.Ligase = factory.GetComponentByType("T4Ligase")
	inputs.Buffer = factory.GetComponentByType("CutsmartBuffer")
	inputs.ATP = factory.GetComponentByType("ATP")
	inputs.Outplate = factory.GetPlateByType("pcrplate")
	inputs.TipType = factory.GetTipboxByType("Gilson50")

	ctx := execution.GetContext()
	conf := make(map[string]interface{})
	conf["MAX_N_PLATES"] = 1.5
	conf["MAX_N_WELLS"] = 12.0
	conf["RESIDUAL_VOLUME_WEIGHT"] = 1.0
	conf["SQLITE_FILE_IN"] = "/Users/msadowski/synthace/protocol_language/checkout/synthace-antha/anthalib/driver/liquidhandling/pm_driver/default.sqlite"
	conf["SQLITE_FILE_OUT"] = "/tmp/output_file.sqlite"
	ctx.ConfigService.SetConfig(id, conf)
	outputs := Steps(params, inputs)
	fmt.Println(outputs.Reaction)
}