Esempio n. 1
0
File: db.go Progetto: js-arias/jdh
// parses keyValue argument. It returns the key and the value.
func parseKeyValArg(arg string) (jdh.Key, string) {
	arg = strings.Join(strings.Fields(arg), " ")
	if len(arg) == 0 {
		return "", ""
	}
	p := strings.Split(arg, "=")
	key := p[0]
	if len(key) == 0 {
		return "", ""
	}
	p = p[1:]
	var val string
	if len(p) > 1 {
		val = strings.Join(p, "=")
	} else {
		val = p[0]
	}
	return jdh.Key(key), val
}
Esempio n. 2
0
func dsInfoRun(c *cmdapp.Command, args []string) {
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong dataset id"))
		c.Usage()
	}
	var db jdh.DB
	if len(extDBFlag) != 0 {
		openExt(c, extDBFlag, "")
		db = extDB
	} else {
		openLocal(c)
		db = localDB
	}
	set := dataset(c, db, idFlag)
	if len(set.Id) == 0 {
		return
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataTitle, set.Title)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataCitation, set.Citation)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataLicense, set.License)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataUrl, set.Url)
			for _, e := range set.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, set.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.DataTitle:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataTitle, set.Title)
		case jdh.DataCitation:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataCitation, set.Citation)
		case jdh.DataLicense:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataLicense, set.License)
		case jdh.DataUrl:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.DataUrl, set.Url)
		case jdh.KeyExtern:
			for _, e := range set.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, set.Comment)
		}
		return
	}
	if len(keyFlag) == 0 {
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", set.Id)
		fmt.Fprintf(os.Stdout, "Title:\n%s\n", set.Title)
		if len(set.Url) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Url:", set.Url)
		}
		if len(set.Citation) > 0 {
			fmt.Fprintf(os.Stdout, "Citation:\n%s\n", set.Citation)
		}
		if len(set.License) > 0 {
			fmt.Fprintf(os.Stdout, "License:\n%s\n", set.License)
		}
		if len(set.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range set.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(set.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", set.Comment)
		}
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.DataTitle:
		fmt.Fprintf(os.Stdout, "%s\n", set.Title)
	case jdh.DataCitation:
		fmt.Fprintf(os.Stdout, "%s\n", set.Citation)
	case jdh.DataLicense:
		fmt.Fprintf(os.Stdout, "%s\n", set.License)
	case jdh.DataUrl:
		fmt.Fprintf(os.Stdout, "%s\n", set.Url)
	case jdh.KeyExtern:
		for _, e := range set.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", set.Comment)
	}
}
Esempio n. 3
0
func spInfoRun(c *cmdapp.Command, args []string) {
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong specimen id"))
		c.Usage()
	}
	var db jdh.DB
	if len(extDBFlag) != 0 {
		openExt(c, extDBFlag, "")
		db = extDB
	} else {
		openLocal(c)
		db = localDB
	}
	spe := specimen(c, db, idFlag)
	if len(spe.Id) == 0 {
		return
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeTaxon, spe.Taxon)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeBasis, spe.Basis)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyReference, spe.Reference)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDataset, spe.Dataset)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeCatalog, spe.Catalog)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDeterminer, spe.Determiner)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeCollector, spe.Collector)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDate, spe.Date.Format(jdh.Iso8601))
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoCountry, spe.Geography.Country)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoState, spe.Geography.State)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoCounty, spe.Geography.County)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeLocality, spe.Locality)
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%.8f,%.8f\n", jdh.GeoLonLat, spe.Georef.Point.Lon, spe.Georef.Point.Lat)
				fmt.Fprintf(os.Stdout, "%s=%d\n", jdh.GeoUncertainty, spe.Georef.Uncertainty)
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoSource, spe.Georef.Source)
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoValidation, spe.Georef.Validation)
			} else {
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoLonLat)
				fmt.Fprintf(os.Stdout, "%s=0\n", jdh.GeoUncertainty)
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoSource)
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoValidation)
			}
			for _, e := range spe.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, spe.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.SpeTaxon:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeTaxon, spe.Taxon)
		case jdh.SpeBasis:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeBasis, spe.Basis)
		case jdh.SpeDataset:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDataset, spe.Dataset)
		case jdh.SpeCatalog:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeCatalog, spe.Catalog)
		case jdh.SpeDeterminer:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDeterminer, spe.Determiner)
		case jdh.SpeCollector:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeCollector, spe.Collector)
		case jdh.SpeDate:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeDate, spe.Date.Format(jdh.Iso8601))
		case jdh.GeoCountry:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoCountry, spe.Geography.Country)
		case jdh.GeoState:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoState, spe.Geography.State)
		case jdh.GeoCounty:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoCounty, spe.Geography.County)
		case jdh.SpeLocality:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.SpeLocality, spe.Locality)
		case jdh.GeoLonLat:
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%.8f,%.8f\n", jdh.GeoLonLat, spe.Georef.Point.Lon, spe.Georef.Point.Lat)
			} else {
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoLonLat)
			}
		case jdh.GeoUncertainty:
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%d\n", jdh.GeoUncertainty, spe.Georef.Uncertainty)
			} else {
				fmt.Fprintf(os.Stdout, "%s=0\n", jdh.GeoUncertainty)
			}
		case jdh.GeoSource:
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoSource, spe.Georef.Source)
			} else {
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoSource)
			}
		case jdh.GeoValidation:
			if spe.Georef.IsValid() {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.GeoValidation, spe.Georef.Validation)
			} else {
				fmt.Fprintf(os.Stdout, "%s=\n", jdh.GeoValidation)
			}
		case jdh.KeyExtern:
			for _, e := range spe.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, spe.Comment)
		case jdh.KeyReference:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyReference, spe.Reference)
		}
		return
	}
	if len(keyFlag) == 0 {
		tax := taxon(c, db, spe.Taxon)
		var set *jdh.Dataset
		if len(spe.Dataset) > 0 {
			set = dataset(c, db, spe.Dataset)
		}
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", spe.Id)
		fmt.Fprintf(os.Stdout, "%-16s %s %s [id: %s]\n", "Taxon:", tax.Name, tax.Authority, spe.Taxon)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Basis:", spe.Basis)
		if len(spe.Reference) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Reference:", spe.Reference)
		}
		if set != nil {
			fmt.Fprintf(os.Stdout, "%-16s [id: %s]\n%s\n", "Dataset:", set.Id, set.Title)
		}
		if len(spe.Catalog) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Catalog:", spe.Catalog)
		}
		if len(spe.Determiner) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Determiner:", spe.Determiner)
		}
		if len(spe.Collector) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Collector:", spe.Collector)
		}
		if !spe.Date.IsZero() {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Date:", spe.Date.Format(jdh.Iso8601))
		}
		if len(spe.Geography.Country) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Country:", spe.Geography.Country.Name())
		}
		if len(spe.Geography.State) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "State:", spe.Geography.State)
		}
		if len(spe.Geography.County) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "County:", spe.Geography.County)
		}
		if len(spe.Locality) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Locality:", spe.Locality)
		}
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%-16s %.8f, %.8f\n", "LonLat:", spe.Georef.Point.Lon, spe.Georef.Point.Lat)
			if spe.Georef.Uncertainty != 0 {
				fmt.Fprintf(os.Stdout, "%-16s %d\n", "Uncertainty:", spe.Georef.Uncertainty)
			}
			if len(spe.Georef.Source) > 0 {
				fmt.Fprintf(os.Stdout, "%-16s %s\n", "Source:", spe.Georef.Source)
			}
			if len(spe.Georef.Validation) > 0 {
				fmt.Fprintf(os.Stdout, "%-16s %s\n", "Validation:", spe.Georef.Validation)
			}
		}
		if len(spe.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range spe.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(spe.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", spe.Comment)
		}
		if set != nil {
			if len(set.Citation) > 0 {
				fmt.Fprintf(os.Stdout, "Citation:\n%s\n", set.Citation)
			}
			if len(set.License) > 0 {
				fmt.Fprintf(os.Stdout, "License:\n%s\n", set.License)
			}
		}
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.SpeTaxon:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Taxon)
	case jdh.SpeBasis:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Basis)
	case jdh.SpeDataset:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Dataset)
	case jdh.SpeCatalog:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Catalog)
	case jdh.SpeDeterminer:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Determiner)
	case jdh.SpeCollector:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Collector)
	case jdh.SpeDate:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Date.Format(jdh.Iso8601))
	case jdh.GeoCountry:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Geography.Country)
	case jdh.GeoState:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Geography.State)
	case jdh.GeoCounty:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Geography.County)
	case jdh.SpeLocality:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Locality)
	case jdh.GeoLonLat:
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%.8f\t%.8f\n", spe.Georef.Point.Lon, spe.Georef.Point.Lat)
		} else {
			fmt.Fprintf(os.Stdout, "\n")
		}
	case jdh.GeoUncertainty:
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%d\n", spe.Georef.Uncertainty)
		} else {
			fmt.Fprintf(os.Stdout, "\n")
		}
	case jdh.GeoSource:
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%s\n", spe.Georef.Source)
		} else {
			fmt.Fprintf(os.Stdout, "\n")
		}
	case jdh.GeoValidation:
		if spe.Georef.IsValid() {
			fmt.Fprintf(os.Stdout, "%s\n", spe.Georef.Validation)
		} else {
			fmt.Fprintf(os.Stdout, "\n")
		}
	case jdh.KeyExtern:
		for _, e := range spe.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Comment)
	case jdh.KeyReference:
		fmt.Fprintf(os.Stdout, "%s\n", spe.Reference)
	}
}
Esempio n. 4
0
func raInfoRun(c *cmdapp.Command, args []string) {
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong raster id"))
		c.Usage()
	}
	openLocal(c)
	ras := raster(c, localDB, idFlag)
	if len(ras.Id) == 0 {
		return
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisTaxon, ras.Taxon)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisSource, ras.Source)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyReference, ras.Reference)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisCols, ras.Cols)
			for _, e := range ras.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, ras.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.RDisTaxon:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisTaxon, ras.Taxon)
		case jdh.RDisSource:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisSource, ras.Source)
		case jdh.RDisCols:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.RDisCols, ras.Cols)
		case jdh.KeyExtern:
			for _, e := range ras.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, ras.Comment)
		case jdh.KeyReference:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyReference, ras.Reference)
		}
		return
	}
	if len(keyFlag) == 0 {
		tax := taxon(c, localDB, ras.Taxon)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", ras.Id)
		fmt.Fprintf(os.Stdout, "%-16s %s %s [id: %s]\n", "Taxon:", tax.Name, tax.Authority, ras.Taxon)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Source:", ras.Source)
		fmt.Fprintf(os.Stdout, "%-16s %dx%d\n", "Dimensions:", ras.Cols, ras.Cols/2)
		if len(ras.Reference) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Reference:", ras.Reference)
		}
		if len(ras.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range ras.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(ras.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", ras.Comment)
		}
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.RDisTaxon:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Taxon)
	case jdh.RDisSource:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Source)
	case jdh.RDisCols:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Cols)
	case jdh.KeyExtern:
		for _, e := range ras.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Comment)
	case jdh.KeyReference:
		fmt.Fprintf(os.Stdout, "%s\n", ras.Reference)
	}
}
Esempio n. 5
0
func txInfoRun(c *cmdapp.Command, args []string) {
	var db jdh.DB
	if len(extDBFlag) != 0 {
		openExt(c, extDBFlag, "")
		db = extDB
	} else {
		openLocal(c)
		db = localDB
	}
	var tax *jdh.Taxon
	if len(idFlag) > 0 {
		tax = taxon(c, db, idFlag)
		if len(tax.Id) == 0 {
			return
		}
	} else if len(args) > 0 {
		if len(args) > 2 {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("too many arguments"))
			os.Exit(1)
		}
		pName := ""
		if len(args) > 1 {
			pName = args[1]
		}
		tax = pickTaxName(c, db, args[0], pName)
		if len(tax.Id) == 0 {
			return
		}
	} else {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong taxon name or id"))
		c.Usage()
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxName, tax.Name)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxAuthority, tax.Authority)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxRank, tax.Rank)
			if tax.IsValid {
				fmt.Fprintf(os.Stdout, "%s=true\n", jdh.TaxValid)
			} else {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxSynonym, tax.Parent)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxParent, tax.Parent)
			for _, e := range tax.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, tax.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.TaxName:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxName, tax.Name)
		case jdh.TaxAuthority:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxAuthority, tax.Authority)
		case jdh.TaxRank:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxRank, tax.Rank)
		case jdh.TaxValid, jdh.TaxSynonym:
			if tax.IsValid {
				fmt.Fprintf(os.Stdout, "%s=true\n", jdh.TaxValid)
			} else {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxSynonym, tax.Parent)
			}
		case jdh.TaxParent:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TaxParent, tax.Parent)
		case jdh.KeyExtern:
			for _, e := range tax.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, tax.Comment)
		}
		return
	}
	if len(keyFlag) == 0 {
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", tax.Id)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Name:", tax.Name)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Authority:", tax.Authority)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Rank:", tax.Rank)
		if tax.IsValid {
			fmt.Fprintf(os.Stdout, "%-16s true\n", "Valid:")
		} else {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Synonym of:", tax.Parent)
		}
		if len(tax.Parent) > 0 {
			p := taxon(c, db, tax.Parent)
			fmt.Fprintf(os.Stdout, "%-16s %s %s [id: %s]\n", "Parent:", p.Name, p.Authority, p.Id)
		}
		if len(tax.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range tax.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(tax.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", tax.Comment)
		}
		txInfoList(c, db, tax.Id, true)
		txInfoList(c, db, tax.Id, false)
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.TaxName:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Name)
	case jdh.TaxAuthority:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Authority)
	case jdh.TaxRank:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Rank)
	case jdh.TaxValid, jdh.TaxSynonym:
		if tax.IsValid {
			fmt.Fprintf(os.Stdout, "true\n")
		} else {
			fmt.Fprintf(os.Stdout, "synonym of %s\n", tax.Parent)
		}
	case jdh.TaxParent:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Parent)
	case jdh.KeyExtern:
		for _, e := range tax.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", tax.Comment)
	}
}
Esempio n. 6
0
func trInfoRun(c *cmdapp.Command, args []string) {
	openLocal(c)
	if len(nodeFlag) > 0 {
		trInfoNode(c)
		return
	}
	if len(idFlag) == 0 {
		fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr("expectiong tree or node id"))
		c.Usage()
	}
	phy := phylogeny(c, localDB, idFlag)
	if len(phy.Id) == 0 {
		return
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TreName, phy.Name)
			for _, e := range phy.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, phy.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.TreName:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.TreName, phy.Name)
		case jdh.KeyExtern:
			for _, e := range phy.Extern {
				fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyExtern, e)
			}
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, phy.Comment)
		}
		return
	}
	if len(keyFlag) == 0 {
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", phy.Id)
		if len(phy.Name) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Name:", phy.Name)
		}
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Root:", phy.Root)
		if len(phy.Extern) > 0 {
			fmt.Fprintf(os.Stdout, "Extern ids:\n")
			for _, e := range phy.Extern {
				fmt.Fprintf(os.Stdout, "\t%s\n", e)
			}
		}
		if len(phy.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", phy.Comment)
		}
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.TreName:
		fmt.Fprintf(os.Stdout, "%s\n", phy.Name)
	case jdh.KeyExtern:
		for _, e := range phy.Extern {
			fmt.Fprintf(os.Stdout, "%s\n", e)
		}
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", phy.Comment)
	}
}
Esempio n. 7
0
func trInfoNode(c *cmdapp.Command) {
	nod := phyloNode(c, localDB, nodeFlag)
	if len(nod.Id) == 0 {
		return
	}
	if machineFlag {
		if len(keyFlag) == 0 {
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.NodTaxon, nod.Taxon)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.NodLength, nod.Len)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.NodAge, nod.Age)
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, nod.Comment)
			return
		}
		switch jdh.Key(keyFlag) {
		case jdh.NodTaxon:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.NodTaxon, nod.Taxon)
		case jdh.NodLength:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.NodLength, nod.Len)
		case jdh.NodAge:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.NodAge, nod.Age)
		case jdh.KeyComment:
			fmt.Fprintf(os.Stdout, "%s=%s\n", jdh.KeyComment, nod.Comment)
		}
		return
	}
	if len(keyFlag) == 0 {
		var tax *jdh.Taxon
		if len(nod.Taxon) > 0 {
			tax = taxon(c, localDB, nod.Taxon)
		}
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Id:", nod.Id)
		fmt.Fprintf(os.Stdout, "%-16s %s\n", "Tree:", nod.Tree)
		if tax != nil {
			fmt.Fprintf(os.Stdout, "%-16s %s %s [id: %s]\n", "Taxon:", tax.Name, tax.Authority, tax.Id)
		}
		if len(nod.Parent) > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %s\n", "Parent:", nod.Parent)
		} else {
			fmt.Fprintf(os.Stdout, "Root node\n")
		}
		if nod.Len > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %d\n", "Length:", nod.Len)
		}
		if nod.Age > 0 {
			fmt.Fprintf(os.Stdout, "%-16s %d\n", "Age:", nod.Age)
		}
		if len(nod.Comment) > 0 {
			fmt.Fprintf(os.Stdout, "Comments:\n%s\n", nod.Comment)
		}
		vals := new(jdh.Values)
		vals.Add(jdh.NodChildren, nod.Id)
		l, err := localDB.List(jdh.Nodes, vals)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
			os.Exit(1)
		}
		first := true
		for {
			desc := &jdh.Node{}
			if err := l.Scan(desc); err != nil {
				if err == io.EOF {
					break
				}
				fmt.Fprintf(os.Stderr, "%s\n", c.ErrStr(err))
				os.Exit(1)
			}
			if first {
				fmt.Fprintf(os.Stdout, "Children nodes:\n")
				first = false
			}
			fmt.Fprintf(os.Stdout, "\t%s", desc.Id)
			if len(desc.Taxon) > 0 {
				tax := taxon(c, localDB, desc.Taxon)
				fmt.Fprintf(os.Stdout, "\t[%s [id: %s]]", tax.Name, tax.Id)
			}
			fmt.Fprintf(os.Stdout, "\n")
		}
		return
	}
	switch jdh.Key(keyFlag) {
	case jdh.NodTaxon:
		fmt.Fprintf(os.Stdout, "%s\n", nod.Taxon)
	case jdh.NodLength:
		fmt.Fprintf(os.Stdout, "%s\n", nod.Len)
	case jdh.NodAge:
		fmt.Fprintf(os.Stdout, "%s\n", nod.Age)
	case jdh.KeyComment:
		fmt.Fprintf(os.Stdout, "%s\n", nod.Comment)
	}
}