func ParseRebase(file []byte) map[string]Enzyme {
	// Setup some variables
	var enzyme Enzyme
	enzymeMap := make(map[string]Enzyme)
	commercialSupplierMap := make(map[rune]string)

	// Get rebase as a large string
	rebase := string(file)

	// Split those strings into individual lines for parsing
	lines := strings.Split(rebase, "\n")

	commercialParsingLine := 0
	startCommercialParsing := false
	for _, line := range lines {
		// Parse commercial sources map
		if line == "REBASE codes for commercial sources of enzymes" {
			startCommercialParsing = true
		}
		// If startCommercialParsing is true, start building the commercial supplier map
		if startCommercialParsing {
			// if we start enzyme parsing, break the commercial supplier parsing
			if strings.Contains(line, "<1>") {
				commercialParsingLine = 0
				startCommercialParsing = false
			}

			// Skip two lines
			commercialParsingLine++
			if (commercialParsingLine > 3) && (len(strings.TrimLeft(line, "\t")) > 0) {
				// Trim indentation
				trimmedString := strings.TrimLeft(line, "\t")

				// The first letter of the trimmedString is the single letter code
				singleLetterCommercialCode := rune(trimmedString[0])

				// There are 8 spaces until the commercial companies's name. We are keeping the dates
				// attached, since it is additional information that could be useful for users down
				// the line
				commercialName := trimmedString[9:]

				// Add both to commercialSuppliermap
				commercialSupplierMap[singleLetterCommercialCode] = commercialName
			}
		}

		// Normal enzyme parsing
		switch {
		case strings.Contains(line, "<1>"):
			enzyme.Name = line[3:]
		case strings.Contains(line, "<2>"):
			enzyme.Isoschizomers = strings.Split(line[3:], ",")
		case strings.Contains(line, "<3>"):
			enzyme.RecognitionSequence = line[3:]
		case strings.Contains(line, "<4>"):
			enzyme.MethylationSite = line[3:]
		case strings.Contains(line, "<5>"):
			enzyme.MicroOrganism = line[3:]
		case strings.Contains(line, "<6>"):
			enzyme.Source = line[3:]
		case strings.Contains(line, "<7>"):
			// We need to get a list of specific commercial suppliers from the commercialSupplierMap we previously made
			var commercialSuppliers []string
			for _, commercialLetter := range line[3:] {
				commercialSuppliers = append(commercialSuppliers, commercialSupplierMap[commercialLetter])
			}
			enzyme.CommercialAvailability = commercialSuppliers
		case strings.Contains(line, "<8>"):
			enzyme.References = line[3:]
			// After every <8> a new enzyme will start. So here, we put the current enzyme into the enzymeMap and setup a new enzyme to be filled
			enzymeMap[enzyme.Name] = enzyme
			enzyme = Enzyme{}
		}
	}
	return enzymeMap
}
// ParseRebase parses the Rebase database into a map of enzymes
ParseRebase parses the Rebase database into a map of enzymes
// ParseRebase parses the Rebase database into a map of enzymes
func ParseRebase(file []byte) map[string]Enzyme {
	var enzyme Enzyme
	enzymeMap := make(map[string]Enzyme)
	commercialSupplierMap := make(map[rune]string)
	rebase := string(file)
	lines := strings.Split(rebase, "\n")
	commercialParsingLine := 0
	startCommercialParsing := false
	for _, line := range lines {
		if line == "REBASE codes for commercial sources of enzymes" {
			startCommercialParsing = true
		}
		if startCommercialParsing {
			if strings.Contains(line, "<1>") {
				commercialParsingLine = 0
				startCommercialParsing = false
			}
			commercialParsingLine++
			if (commercialParsingLine > 3) && (len(strings.TrimLeft(line, "\t")) > 0) {
				trimmedString := strings.TrimLeft(line, "\t")
				singleLetterCommercialCode := rune(trimmedString[0])
				commercialName := trimmedString[9:]
				commercialSupplierMap[singleLetterCommercialCode] = commercialName
			}
		}
		switch {
		case strings.Contains(line, "<1>"):
			enzyme.Name = line[3:]
		case strings.Contains(line, "<2>"):
			enzyme.Isoschizomers = strings.Split(line[3:], ",")
		case strings.Contains(line, "<3>"):
			enzyme.RecognitionSequence = line[3:]
		case strings.Contains(line, "<4>"):
			enzyme.MethylationSite = line[3:]
		case strings.Contains(line, "<5>"):
			enzyme.MicroOrganism = line[3:]
		case strings.Contains(line, "<6>"):
			enzyme.Source = line[3:]
		case strings.Contains(line, "<7>"):
			var commercialSuppliers []string
			for _, commercialLetter := range line[3:] {
				commercialSuppliers = append(commercialSuppliers, commercialSupplierMap[commercialLetter])
			}
			enzyme.CommercialAvailability = commercialSuppliers
		case strings.Contains(line, "<8>"):
			enzyme.References = line[3:]
			enzymeMap[enzyme.Name] = enzyme
			enzyme = Enzyme{}
		}
	}
	return enzymeMap
}
func ParseRebase ( file [ ] byte ) map [ string ] Enzyme { var enzyme Enzyme enzymeMap := make ( map [ string ] Enzyme ) commercialSupplierMap := make ( map [ rune ] string ) rebase := string ( file ) lines := strings . Split ( rebase , " \n " ) commercialParsingLine := 0 startCommercialParsing := false for _ , line := range lines { if line == " " { startCommercialParsing = true } if startCommercialParsing { if strings . Contains ( line , " " ) { commercialParsingLine = 0 startCommercialParsing = false } commercialParsingLine ++ if ( commercialParsingLine > 3 ) && ( len ( strings . TrimLeft ( line , " \t " ) ) > 0 ) { trimmedString := strings . TrimLeft ( line , " \t " ) singleLetterCommercialCode := rune ( trimmedString [ 0 ] ) commercialName := trimmedString [ 9 : ] commercialSupplierMap [ singleLetterCommercialCode ] = commercialName } } switch { case strings . Contains ( line , " " ) : enzyme . Name = line [ 3 : ] case strings . Contains ( line , " " ) : enzyme . Isoschizomers = strings . Split ( line [ 3 : ] , " " ) case strings . Contains ( line , " " ) : enzyme . RecognitionSequence = line [ 3 : ] case strings . Contains ( line , " " ) : enzyme . MethylationSite = line [ 3 : ] case strings . Contains ( line , " " ) : enzyme . MicroOrganism = line [ 3 : ] case strings . Contains ( line , " " ) : enzyme . Source = line [ 3 : ] case strings . Contains ( line , " " ) : var commercialSuppliers [ ] string for _ , commercialLetter := range line [ 3 : ] { commercialSuppliers = append ( commercialSuppliers , commercialSupplierMap [ commercialLetter ] ) } enzyme . CommercialAvailability = commercialSuppliers case strings . Contains ( line , " " ) : enzyme . References = line [ 3 : ] enzymeMap [ enzyme . Name ] = enzyme enzyme = Enzyme { } } } return enzymeMap }
ParseRebase parses the Rebase database into a map of enzymes
ParseRebase parses the Rebase database into a map of enzymes
// Setup some variables // Get rebase as a large string // Split those strings into individual lines for parsing // Parse commercial sources map // If startCommercialParsing is true, start building the commercial supplier map // if we start enzyme parsing, break the commercial supplier parsing // Skip two lines // Trim indentation // The first letter of the trimmedString is the single letter code // There are 8 spaces until the commercial companies's name. We are keeping the dates // attached, since it is additional information that could be useful for users down // the line // Add both to commercialSuppliermap // Normal enzyme parsing // We need to get a list of specific commercial suppliers from the commercialSupplierMap we previously made // After every <8> a new enzyme will start. So here, we put the current enzyme into the enzymeMap and setup a new enzyme to be filled