Skip to content

Commit

Permalink
small race condition fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nvnieuwk committed Nov 13, 2023
1 parent fa87738 commit 034e549
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 30 deletions.
21 changes: 11 additions & 10 deletions convert/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,23 @@ type HeaderLine struct {

// The struct for one variant
type Variant struct {
Chrom string // The chromosome
Pos string // The position
Id string // The ID
Ref string // The reference allele
Alt string // The alternative allele
Qual string // The quality
Filter string // The filter
Info MapVariantInfoFormat // The info fields
Format MapVariantInfoFormat // The format fields
Chrom string // The chromosome
Pos string // The position
Id string // The ID
Ref string // The reference allele
Alt string // The alternative allele
Qual string // The quality
Filter string // The filter
Info SliceVariantInfoFormat // The info fields
Format SliceVariantInfoFormat // The format fields
}

// The map for the info and format fields
type MapVariantInfoFormat map[string]VariantInfoFormat
type SliceVariantInfoFormat []VariantInfoFormat

// The struct for one info or format field
type VariantInfoFormat struct {
Name string // The name of the current INFO or FORMAT field
Number string // The number of values that can be included in the INFO field (e.g. 1, 2, A, R)
Type string // The type of the header field (e.g. Integer, Float, Character, Flag)
Value string // The value of the field
Expand Down
21 changes: 11 additions & 10 deletions convert/vcf.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,19 @@ func (v *Vcf) AddVariants(cCtx *cli.Context, config Config) error {
}

// Get the values of all info fields and transform them to a map
func (mcifs *SliceConfigInfoFormatStruct) getValues(values []string, header []string) (error, MapVariantInfoFormat) {
infoMap := MapVariantInfoFormat{}
func (mcifs *SliceConfigInfoFormatStruct) getValues(values []string, header []string) (error, SliceVariantInfoFormat) {
infoMap := SliceVariantInfoFormat{}
for _, v := range *mcifs {
err, value := v.getValue(values, header)
if err != nil {
return err, nil
}
infoMap[v.Name] = VariantInfoFormat{
infoMap = append(infoMap, VariantInfoFormat{
Name: v.Name,
Number: v.Number,
Type: v.Type,
Value: value,
}
})
}
return nil, infoMap
}
Expand Down Expand Up @@ -312,10 +313,10 @@ func (v Variant) String(count int) string {
}

// Convert the info map to a string
func (mvif MapVariantInfoFormat) infoString() string {
func (mvif SliceVariantInfoFormat) infoString() string {
var infoSlice []string
for k, v := range mvif {
upperInfo := strings.ToUpper(k)
for _, v := range mvif {
upperInfo := strings.ToUpper(v.Name)
switch infoType := strings.ToLower(v.Type); infoType {
case "flag":
infoSlice = append(infoSlice, upperInfo)
Expand All @@ -328,11 +329,11 @@ func (mvif MapVariantInfoFormat) infoString() string {
}

// Convert the format map to a string
func (mcifs MapVariantInfoFormat) formatString() string {
func (mvif SliceVariantInfoFormat) formatString() string {
var formatField []string
var formatValues []string
for k, v := range mcifs {
upperFormat := strings.ToUpper(k)
for _, v := range mvif {
upperFormat := strings.ToUpper(v.Name)
formatField = append(formatField, upperFormat)
formatValues = append(formatValues, v.Value)
}
Expand Down
26 changes: 16 additions & 10 deletions convert/vcf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,17 @@ func TestVariantString(t *testing.T) {
Alt: "C",
Qual: "100",
Filter: "PASS",
Info: MapVariantInfoFormat{
"SVLEN": VariantInfoFormat{
Info: SliceVariantInfoFormat{
{
Name: "SVLEN",
Number: "1",
Type: "Integer",
Value: "100",
},
},
Format: MapVariantInfoFormat{
"GT": VariantInfoFormat{
Format: SliceVariantInfoFormat{
{
Name: "GT",
Number: "1",
Type: "String",
Value: "0/1",
Expand All @@ -241,25 +243,29 @@ func TestVariantString(t *testing.T) {
Alt: "C",
Qual: "100",
Filter: "PASS",
Info: MapVariantInfoFormat{
"SVLEN": VariantInfoFormat{
Info: SliceVariantInfoFormat{
{
Name: "SVLEN",
Number: "1",
Type: "Integer",
Value: "100",
},
"SVTYPE": VariantInfoFormat{
{
Name: "SVTYPE",
Number: "1",
Type: "String",
Value: "DEL",
},
},
Format: MapVariantInfoFormat{
"GT": VariantInfoFormat{
Format: SliceVariantInfoFormat{
{
Name: "GT",
Number: "1",
Type: "String",
Value: "0/1",
},
"CN": VariantInfoFormat{
{
Name: "CN",
Number: "1",
Type: "Integer",
Value: "2",
Expand Down

0 comments on commit 034e549

Please sign in to comment.