func BuildGbk(sequence Sequence) []byte {
	var gbkString bytes.Buffer
	locus := sequence.Meta.Locus
	var shape string

	if locus.Circular {
		shape = "circular"
	} else if locus.Linear {
		shape = "linear"
	}

	fivespace := generateWhiteSpace(subMetaIndex)

	// building locus
	locusData := locus.Name + fivespace + locus.SequenceLength + " bp" + fivespace + locus.MoleculeType + fivespace + shape + fivespace + locus.GenbankDivision + fivespace + locus.ModificationDate
	locusString := "LOCUS       " + locusData + "\n"
	gbkString.WriteString(locusString)

	// building other standard meta features
	definitionString := buildMetaString("DEFINITION", sequence.Meta.Definition)
	gbkString.WriteString(definitionString)

	accessionString := buildMetaString("ACCESSION", sequence.Meta.Accession)
	gbkString.WriteString(accessionString)

	versionString := buildMetaString("VERSION", sequence.Meta.Version)
	gbkString.WriteString(versionString)

	keywordsString := buildMetaString("KEYWORDS", sequence.Meta.Keywords)
	gbkString.WriteString(keywordsString)

	sourceString := buildMetaString("SOURCE", sequence.Meta.Source)
	gbkString.WriteString(sourceString)

	organismString := buildMetaString("  ORGANISM", sequence.Meta.Organism)
	gbkString.WriteString(organismString)

	// building references
	// TODO: could use reflection to get keys and make more general.
	for referenceIndex, reference := range sequence.Meta.References {
		referenceData := strconv.Itoa(referenceIndex+1) + "  " + reference.Range
		referenceString := buildMetaString("REFERENCE", referenceData)
		gbkString.WriteString(referenceString)

		if reference.Authors != "" {
			authorsString := buildMetaString("  AUTHORS", reference.Authors)
			gbkString.WriteString(authorsString)
		}

		if reference.Title != "" {
			titleString := buildMetaString("  TITLE", reference.Title)
			gbkString.WriteString(titleString)
		}

		if reference.Journal != "" {
			journalString := buildMetaString("  JOURNAL", reference.Journal)
			gbkString.WriteString(journalString)
		}

		if reference.PubMed != "" {
			pubMedString := buildMetaString("  PUBMED", reference.PubMed)
			gbkString.WriteString(pubMedString)
		}

	}

	// building other meta fields that are catch all
	otherKeys := make([]string, 0, len(sequence.Meta.Other))
	for key := range sequence.Meta.Other {
		otherKeys = append(otherKeys, key)
	}

	for _, otherKey := range otherKeys {
		otherString := buildMetaString(otherKey, sequence.Meta.Other[otherKey])
		gbkString.WriteString(otherString)
	}

	// start writing features section.
	gbkString.WriteString("FEATURES             Location/Qualifiers\n")
	for _, feature := range sequence.Features {
		gbkString.WriteString(buildGbkFeatureString(feature))
	}

	// start writing sequence section.
	gbkString.WriteString("ORIGIN\n")

	// iterate over every character in sequence range.
	for index, base := range sequence.Sequence {
		// if 60th character add newline then whitespace and index number and space before adding next base.
		if index%60 == 0 {
			if index != 0 {
				gbkString.WriteString("\n")
			}
			lineNumberString := strconv.Itoa(index + 1)          // genbank indexes at 1 for some reason
			leadingWhiteSpaceLength := 9 - len(lineNumberString) // <- I wish I was kidding
			for i := 0; i < leadingWhiteSpaceLength; i++ {
				gbkString.WriteString(" ")
			}
			gbkString.WriteString(lineNumberString + " ")
			gbkString.WriteRune(base)
			// if base index is divisible by ten add a space (genbank convention)
		} else if index%10 == 0 {
			gbkString.WriteString(" ")
			gbkString.WriteRune(base)
			// else just add the base.
		} else {
			gbkString.WriteRune(base)
		}
	}
	// finish genbank file with "//" on newline (again a genbank convention)
	gbkString.WriteString("\n//")

	return gbkString.Bytes()
}
// BuildGbk builds a GBK string to be written out to db or file.
BuildGbk builds a GBK string to be written out to db or file.
// BuildGbk builds a GBK string to be written out to db or file .
func BuildGbk(sequence Sequence) []byte {
	var gbkString bytes.Buffer
	locus := sequence.Meta.Locus
	var shape string
	if locus.Circular {
		shape = "circular"
	} else if locus.Linear {
		shape = "linear"
	}
	fivespace := generateWhiteSpace(subMetaIndex)
	locusData := locus.Name + fivespace + locus.SequenceLength + " bp" + fivespace + locus.MoleculeType + fivespace + shape + fivespace + locus.GenbankDivision + fivespace + locus.ModificationDate
	locusString := "LOCUS       " + locusData + "\n"
	gbkString.WriteString(locusString)
	definitionString := buildMetaString("DEFINITION", sequence.Meta.Definition)
	gbkString.WriteString(definitionString)
	accessionString := buildMetaString("ACCESSION", sequence.Meta.Accession)
	gbkString.WriteString(accessionString)
	versionString := buildMetaString("VERSION", sequence.Meta.Version)
	gbkString.WriteString(versionString)
	keywordsString := buildMetaString("KEYWORDS", sequence.Meta.Keywords)
	gbkString.WriteString(keywordsString)
	sourceString := buildMetaString("SOURCE", sequence.Meta.Source)
	gbkString.WriteString(sourceString)
	organismString := buildMetaString("  ORGANISM", sequence.Meta.Organism)
	gbkString.WriteString(organismString)
	for referenceIndex, reference := range sequence.Meta.References {
		referenceData := strconv.Itoa(referenceIndex+1) + "  " + reference.Range
		referenceString := buildMetaString("REFERENCE", referenceData)
		gbkString.WriteString(referenceString)
		if reference.Authors != "" {
			authorsString := buildMetaString("  AUTHORS", reference.Authors)
			gbkString.WriteString(authorsString)
		}
		if reference.Title != "" {
			titleString := buildMetaString("  TITLE", reference.Title)
			gbkString.WriteString(titleString)
		}
		if reference.Journal != "" {
			journalString := buildMetaString("  JOURNAL", reference.Journal)
			gbkString.WriteString(journalString)
		}
		if reference.PubMed != "" {
			pubMedString := buildMetaString("  PUBMED", reference.PubMed)
			gbkString.WriteString(pubMedString)
		}
	}
	otherKeys := make([]string, 0, len(sequence.Meta.Other))
	for key := range sequence.Meta.Other {
		otherKeys = append(otherKeys, key)
	}
	for _, otherKey := range otherKeys {
		otherString := buildMetaString(otherKey, sequence.Meta.Other[otherKey])
		gbkString.WriteString(otherString)
	}
	gbkString.WriteString("FEATURES             Location/Qualifiers\n")
	for _, feature := range sequence.Features {
		gbkString.WriteString(buildGbkFeatureString(feature))
	}
	gbkString.WriteString("ORIGIN\n")
	for index, base := range sequence.Sequence {
		if index%60 == 0 {
			if index != 0 {
				gbkString.WriteString("\n")
			}
			lineNumberString := strconv.Itoa(index + 1)          
			leadingWhiteSpaceLength := 9 - len(lineNumberString) 
			for i := 0; i < leadingWhiteSpaceLength; i++ {
				gbkString.WriteString(" ")
			}
			gbkString.WriteString(lineNumberString + " ")
			gbkString.WriteRune(base)
		} else if index%10 == 0 {
			gbkString.WriteString(" ")
			gbkString.WriteRune(base)
		} else {
			gbkString.WriteRune(base)
		}
	}
	gbkString.WriteString("\n//")
	return gbkString.Bytes()
}
func BuildGbk ( sequence Sequence ) [ ] byte { var gbkString bytes . Buffer locus := sequence . Meta . Locus var shape string if locus . Circular { shape = " " } else if locus . Linear { shape = " " } fivespace := generateWhiteSpace ( subMetaIndex ) locusData := locus . Name + fivespace + locus . SequenceLength + " " + fivespace + locus . MoleculeType + fivespace + shape + fivespace + locus . GenbankDivision + fivespace + locus . ModificationDate locusString := " " + locusData + " \n " gbkString . WriteString ( locusString ) definitionString := buildMetaString ( " " , sequence . Meta . Definition ) gbkString . WriteString ( definitionString ) accessionString := buildMetaString ( " " , sequence . Meta . Accession ) gbkString . WriteString ( accessionString ) versionString := buildMetaString ( " " , sequence . Meta . Version ) gbkString . WriteString ( versionString ) keywordsString := buildMetaString ( " " , sequence . Meta . Keywords ) gbkString . WriteString ( keywordsString ) sourceString := buildMetaString ( " " , sequence . Meta . Source ) gbkString . WriteString ( sourceString ) organismString := buildMetaString ( " " , sequence . Meta . Organism ) gbkString . WriteString ( organismString ) for referenceIndex , reference := range sequence . Meta . References { referenceData := strconv . Itoa ( referenceIndex + 1 ) + " " + reference . Range referenceString := buildMetaString ( " " , referenceData ) gbkString . WriteString ( referenceString ) if reference . Authors != " " { authorsString := buildMetaString ( " " , reference . Authors ) gbkString . WriteString ( authorsString ) } if reference . Title != " " { titleString := buildMetaString ( " " , reference . Title ) gbkString . WriteString ( titleString ) } if reference . Journal != " " { journalString := buildMetaString ( " " , reference . Journal ) gbkString . WriteString ( journalString ) } if reference . PubMed != " " { pubMedString := buildMetaString ( " " , reference . PubMed ) gbkString . WriteString ( pubMedString ) } } otherKeys := make ( [ ] string , 0 , len ( sequence . Meta . Other ) ) for key := range sequence . Meta . Other { otherKeys = append ( otherKeys , key ) } for _ , otherKey := range otherKeys { otherString := buildMetaString ( otherKey , sequence . Meta . Other [ otherKey ] ) gbkString . WriteString ( otherString ) } gbkString . WriteString ( " \n " ) for _ , feature := range sequence . Features { gbkString . WriteString ( buildGbkFeatureString ( feature ) ) } gbkString . WriteString ( " \n " ) for index , base := range sequence . Sequence { if index % 60 == 0 { if index != 0 { gbkString . WriteString ( " \n " ) } lineNumberString := strconv . Itoa ( index + 1 ) leadingWhiteSpaceLength := 9 - len ( lineNumberString ) for i := 0 ; i < leadingWhiteSpaceLength ; i ++ { gbkString . WriteString ( " " ) } gbkString . WriteString ( lineNumberString + " " ) gbkString . WriteRune ( base ) } else if index % 10 == 0 { gbkString . WriteString ( " " ) gbkString . WriteRune ( base ) } else { gbkString . WriteRune ( base ) } } gbkString . WriteString ( " \n " ) return gbkString . Bytes ( ) }
BuildGbk builds a GBK string to be written out to db or file.
BuildGbk builds a GBK string to be written out to db or file .
// building locus // building other standard meta features // building references // TODO: could use reflection to get keys and make more general. // building other meta fields that are catch all // start writing features section. // start writing sequence section. // iterate over every character in sequence range. // if 60th character add newline then whitespace and index number and space before adding next base. // genbank indexes at 1 for some reason // <- I wish I was kidding // if base index is divisible by ten add a space (genbank convention) // else just add the base. // finish genbank file with "//" on newline (again a genbank convention)