From 8f9438c8a0216596ada77e9913d1954ed8b84951 Mon Sep 17 00:00:00 2001 From: Felipe da Veiga Leprevost Date: Tue, 19 May 2020 11:06:30 -0400 Subject: [PATCH] updating and fixing the test library --- Changelog | 3 +- lib/bio/bio_test.go | 3 - lib/fil/fdr_test.go | 234 +++++++++++++++++++++----------------------- lib/fil/fil_test.go | 161 +++++++++++------------------- lib/id/pro_test.go | 1 - lib/spc/spc_test.go | 4 - lib/tes/tes.go | 7 +- lib/uti/uti_test.go | 2 - lib/wrk/wrk_test.go | 2 - 9 files changed, 177 insertions(+), 240 deletions(-) diff --git a/Changelog b/Changelog index 7f50ce3b..2b714c2b 100644 --- a/Changelog +++ b/Changelog @@ -7,4 +7,5 @@ - The number of tryptic ternmini is now determined by ProteinProphet. ### Fixed -- Error preventing iTRAQ quantification. \ No newline at end of file +- Error preventing iTRAQ quantification. +- Several formatting, typoes and Go-Vet issues were fixed. \ No newline at end of file diff --git a/lib/bio/bio_test.go b/lib/bio/bio_test.go index fce75640..45d92f9d 100644 --- a/lib/bio/bio_test.go +++ b/lib/bio/bio_test.go @@ -110,7 +110,6 @@ func TestAminoAcids(t *testing.T) { t.Errorf("Aminoacid name is incorrect, got %s, want %s", a.Name, "Valine") } - tes.ShutDowTestEnv() } // func TestProtonMass(t *testing.T) { @@ -145,6 +144,4 @@ func TestEnzymes(t *testing.T) { if e.Name != "glu_c" { t.Errorf("Enzyme is incorrect, got %s, want %s", e.Name, "glu_c") } - - tes.ShutDowTestEnv() } diff --git a/lib/fil/fdr_test.go b/lib/fil/fdr_test.go index 4c339dc5..fd65a367 100644 --- a/lib/fil/fdr_test.go +++ b/lib/fil/fdr_test.go @@ -1,123 +1,115 @@ package fil -import ( - "philosopher/lib/id" - "philosopher/lib/sys" - "philosopher/lib/tes" - "reflect" - "testing" -) - -func TestPepXMLFDRFilter(t *testing.T) { - - tes.SetupTestEnv() - - pepID, _ := readPepXMLInput("interact.pep.xml", "rev_", sys.GetTemp(), false, 0) - - type args struct { - input map[string]id.PepIDList - targetFDR float64 - level string - decoyTag string - } - tests := []struct { - name string - args args - want int - want1 float64 - }{ - { - name: "Testing PSM Filtering, 1st pass", - args: args{input: GetUniquePSMs(pepID), targetFDR: 0.01, level: "psm", decoyTag: "rev_"}, - want: 63387, - want1: 0.1914, - }, - { - name: "Testing Peptide Filtering, 1st pass", - args: args{input: GetUniquePeptides(pepID), targetFDR: 0.01, level: "peptide", decoyTag: "rev_"}, - want: 28284, - want1: 0.723, - }, - { - name: "Testing Ion Filtering, 1st pass", - args: args{input: getUniquePeptideIons(pepID), targetFDR: 0.01, level: "ion", decoyTag: "rev_"}, - want: 38151, - want1: 0.5155, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, got1 := PepXMLFDRFilter(tt.args.input, tt.args.targetFDR, tt.args.level, tt.args.decoyTag) - if !reflect.DeepEqual(len(got), tt.want) { - t.Errorf("PepXMLFDRFilter() got = %v, want %v", len(got), tt.want) - } - if got1 != tt.want1 { - t.Errorf("PepXMLFDRFilter() got1 = %v, want %v", got1, tt.want1) - } - }) - } - - //tes.ShutDowTestEnv() -} - -func TestPickedFDR(t *testing.T) { - - tes.SetupTestEnv() - - proXML := readProtXMLInput("interact.prot.xml", "rev_", 1.00) - - type args struct { - p id.ProtXML - } - tests := []struct { - name string - args args - want int - }{ - { - name: "Testing PickedFDR Filter", - args: args{p: proXML}, - want: 7926, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := PickedFDR(tt.args.p); !reflect.DeepEqual(len(got.Groups), tt.want) { - t.Errorf("PickedFDR() = %v, want %v", len(got.Groups), tt.want) - } - }) - } - - //tes.ShutDowTestEnv() -} - -func TestRazorFilter(t *testing.T) { - - tes.SetupTestEnv() - - proXML := readProtXMLInput("interact.prot.xml", "rev_", 1.00) - - type args struct { - p id.ProtXML - } - tests := []struct { - name string - args args - want int - }{ - { - name: "Testing Razor Filter", - args: args{p: proXML}, - want: 7926, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := RazorFilter(tt.args.p); !reflect.DeepEqual(len(got.Groups), tt.want) { - t.Errorf("RazorFilter() = %v, want %v", len(got.Groups), tt.want) - } - }) - } - - //tes.ShutDowTestEnv() -} +// func TestPepXMLFDRFilter(t *testing.T) { + +// tes.SetupTestEnv() + +// pepID, _ := readPepXMLInput("interact.pep.xml", "rev_", sys.GetTemp(), false, 0) + +// type args struct { +// input map[string]id.PepIDList +// targetFDR float64 +// level string +// decoyTag string +// } +// tests := []struct { +// name string +// args args +// want int +// want1 float64 +// }{ +// { +// name: "Testing PSM Filtering, 1st pass", +// args: args{input: GetUniquePSMs(pepID), targetFDR: 0.01, level: "psm", decoyTag: "rev_"}, +// want: 63387, +// want1: 0.1914, +// }, +// { +// name: "Testing Peptide Filtering, 1st pass", +// args: args{input: GetUniquePeptides(pepID), targetFDR: 0.01, level: "peptide", decoyTag: "rev_"}, +// want: 28284, +// want1: 0.723, +// }, +// { +// name: "Testing Ion Filtering, 1st pass", +// args: args{input: getUniquePeptideIons(pepID), targetFDR: 0.01, level: "ion", decoyTag: "rev_"}, +// want: 38151, +// want1: 0.5155, +// }, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// got, got1 := PepXMLFDRFilter(tt.args.input, tt.args.targetFDR, tt.args.level, tt.args.decoyTag) +// if !reflect.DeepEqual(len(got), tt.want) { +// t.Errorf("PepXMLFDRFilter() got = %v, want %v", len(got), tt.want) +// } +// if got1 != tt.want1 { +// t.Errorf("PepXMLFDRFilter() got1 = %v, want %v", got1, tt.want1) +// } +// }) +// } + +// //tes.ShutDowTestEnv() +// } + +// func TestPickedFDR(t *testing.T) { + +// tes.SetupTestEnv() + +// proXML := readProtXMLInput("interact.prot.xml", "rev_", 1.00) + +// type args struct { +// p id.ProtXML +// } +// tests := []struct { +// name string +// args args +// want int +// }{ +// { +// name: "Testing PickedFDR Filter", +// args: args{p: proXML}, +// want: 7926, +// }, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// if got := PickedFDR(tt.args.p); !reflect.DeepEqual(len(got.Groups), tt.want) { +// t.Errorf("PickedFDR() = %v, want %v", len(got.Groups), tt.want) +// } +// }) +// } + +// //tes.ShutDowTestEnv() +// } + +// func TestRazorFilter(t *testing.T) { + +// tes.SetupTestEnv() + +// proXML := readProtXMLInput("interact.prot.xml", "rev_", 1.00) + +// type args struct { +// p id.ProtXML +// } +// tests := []struct { +// name string +// args args +// want int +// }{ +// { +// name: "Testing Razor Filter", +// args: args{p: proXML}, +// want: 7926, +// }, +// } +// for _, tt := range tests { +// t.Run(tt.name, func(t *testing.T) { +// if got := RazorFilter(tt.args.p); !reflect.DeepEqual(len(got.Groups), tt.want) { +// t.Errorf("RazorFilter() = %v, want %v", len(got.Groups), tt.want) +// } +// }) +// } + +// //tes.ShutDowTestEnv() +// } diff --git a/lib/fil/fil_test.go b/lib/fil/fil_test.go index a61a0a19..34a8c363 100644 --- a/lib/fil/fil_test.go +++ b/lib/fil/fil_test.go @@ -9,41 +9,38 @@ import ( "testing" ) -var pepID id.PepIDList -var proID id.ProtIDList -var proXML id.ProtXML - func Test_readPepXMLInput(t *testing.T) { tes.SetupTestEnv() + var pepIDList id.PepIDList - type args struct { + type args1 struct { xmlFile string decoyTag string temp string models bool calibratedMass int } - tests := []struct { + test1 := []struct { name string - args args + args args1 want int want1 string }{ { name: "Testting pepXML reading and formating for the filter", - args: args{xmlFile: "interact.pep.xml", decoyTag: "rev_", temp: sys.GetTemp(), models: false, calibratedMass: 0}, + args: args1{xmlFile: "interact.pep.xml", decoyTag: "rev_", temp: sys.GetTemp(), models: false, calibratedMass: 0}, want: 64406, want1: "MSFragger", }, } - for _, tt := range tests { + for _, tt := range test1 { t.Run(tt.name, func(t *testing.T) { got, got1 := readPepXMLInput(tt.args.xmlFile, tt.args.decoyTag, tt.args.temp, tt.args.models, tt.args.calibratedMass) - pepID = got + pepIDList = got if !reflect.DeepEqual(len(got), tt.want) { t.Errorf("readPepXMLInput() got = %v, want %v", len(got), tt.want) @@ -103,40 +100,32 @@ func Test_readPepXMLInput(t *testing.T) { }) } - tes.ShutDowTestEnv() -} - -func Test_processPeptideIdentifications(t *testing.T) { - - tes.SetupTestEnv() - - type args struct { - p id.PepIDList + type args2 struct { decoyTag string psm float64 peptide float64 ion float64 } - tests := []struct { + test2 := []struct { name string - args args + args args2 want float64 want1 float64 want2 float64 }{ { name: "Testting pepXML reading and formating for the filter", - args: args{p: pepID, decoyTag: "rev_", psm: 0.01, peptide: 0.01, ion: 0.01}, + args: args2{decoyTag: "rev_", psm: 0.01, peptide: 0.01, ion: 0.01}, want: 0.1914, want1: 0.723, want2: 0.5155, }, } - for _, tt := range tests { + for _, tt := range test2 { t.Run(tt.name, func(t *testing.T) { - got, got1, got2 := processPeptideIdentifications(tt.args.p, tt.args.decoyTag, "", tt.args.psm, tt.args.peptide, tt.args.ion) + got, got1, got2 := processPeptideIdentifications(pepIDList, tt.args.decoyTag, "", tt.args.psm, tt.args.peptide, tt.args.ion) if got != tt.want { t.Errorf("processPeptideIdentifications(psm) got = %v, want %v", got, tt.want) } @@ -149,56 +138,51 @@ func Test_processPeptideIdentifications(t *testing.T) { }) } - tes.ShutDowTestEnv() -} - -func Test_chargeProfile(t *testing.T) { - type args struct { - p id.PepIDList + type args3 struct { charge uint8 decoyTag string } - tests := []struct { + test3 := []struct { name string - args args + args args3 wantT int wantD int }{ { name: "Testing charge state 1 profile", - args: args{p: pepID, charge: uint8(1), decoyTag: "rev_"}, + args: args3{charge: uint8(1), decoyTag: "rev_"}, wantT: 0, wantD: 0, }, { name: "Testing charge state 2 profile", - args: args{p: pepID, charge: uint8(2), decoyTag: "rev_"}, + args: args3{charge: uint8(2), decoyTag: "rev_"}, wantT: 36174, wantD: 457, }, { name: "Testing charge state 3 profile", - args: args{p: pepID, charge: uint8(3), decoyTag: "rev_"}, + args: args3{charge: uint8(3), decoyTag: "rev_"}, wantT: 22656, wantD: 317, }, { name: "Testing charge state 4 profile", - args: args{p: pepID, charge: uint8(4), decoyTag: "rev_"}, + args: args3{charge: uint8(4), decoyTag: "rev_"}, wantT: 4272, wantD: 88, }, { name: "Testing charge state 5 profile", - args: args{p: pepID, charge: uint8(5), decoyTag: "rev_"}, + args: args3{charge: uint8(5), decoyTag: "rev_"}, wantT: 432, wantD: 10, }, } - for _, tt := range tests { + for _, tt := range test3 { t.Run(tt.name, func(t *testing.T) { - gotT, gotD := chargeProfile(tt.args.p, tt.args.charge, tt.args.decoyTag) + gotT, gotD := chargeProfile(pepIDList, tt.args.charge, tt.args.decoyTag) if gotT != tt.wantT { t.Errorf("chargeProfile() gotT = %v, want %v", gotT, tt.wantT) } @@ -207,130 +191,106 @@ func Test_chargeProfile(t *testing.T) { } }) } -} -func TestGetUniquePSMs(t *testing.T) { - type args struct { - p id.PepIDList - } - tests := []struct { + test4 := []struct { name string - args args want int }{ { name: "Testing the generation of Unique PSMs", - args: args{pepID}, want: 64406, }, } - for _, tt := range tests { + for _, tt := range test4 { t.Run(tt.name, func(t *testing.T) { - if got := GetUniquePSMs(tt.args.p); !reflect.DeepEqual(len(got), tt.want) { + if got := GetUniquePSMs(pepIDList); !reflect.DeepEqual(len(got), tt.want) { t.Errorf("GetUniquePSMs() = %v, want %v", len(got), tt.want) } }) } -} -func Test_getUniquePeptideIons(t *testing.T) { - type args struct { - p id.PepIDList - } - tests := []struct { + test5 := []struct { name string - args args want int }{ { name: "Testing the generation of Unique Ions", - args: args{pepID}, want: 39716, }, } - for _, tt := range tests { + for _, tt := range test5 { t.Run(tt.name, func(t *testing.T) { - if got := getUniquePeptideIons(tt.args.p); !reflect.DeepEqual(len(got), tt.want) { + if got := getUniquePeptideIons(pepIDList); !reflect.DeepEqual(len(got), tt.want) { t.Errorf("getUniquePeptideIons() = %v, want %v", len(got), tt.want) } }) } -} -func TestGetUniquePeptides(t *testing.T) { - type args struct { - p id.PepIDList - } - tests := []struct { + test6 := []struct { name string - args args want int }{ { name: "Testing the generation of Unique Peptides", - args: args{pepID}, want: 30092, }, } - for _, tt := range tests { + for _, tt := range test6 { t.Run(tt.name, func(t *testing.T) { - if got := GetUniquePeptides(tt.args.p); !reflect.DeepEqual(len(got), tt.want) { + if got := GetUniquePeptides(pepIDList); !reflect.DeepEqual(len(got), tt.want) { t.Errorf("GetUniquePeptides() = %v, want %v", len(got), tt.want) } }) } -} -func TestExtractIonsFromPSMs(t *testing.T) { - type args struct { - p id.PepIDList - } - tests := []struct { + test7 := []struct { name string - args args want int }{ { name: "Testing the Ion extraction from PSM", - args: args{pepID}, want: 39716, }, } - for _, tt := range tests { + for _, tt := range test7 { t.Run(tt.name, func(t *testing.T) { - if got := ExtractIonsFromPSMs(tt.args.p); !reflect.DeepEqual(len(got), tt.want) { + if got := ExtractIonsFromPSMs(pepIDList); !reflect.DeepEqual(len(got), tt.want) { t.Errorf("ExtractIonsFromPSMs() = %v, want %v", len(got), tt.want) } }) } + + //tes.ShutDowTestEnv() } func Test_readProtXMLInput(t *testing.T) { tes.SetupTestEnv() + var proXML id.ProtXML - type args struct { + type args1 struct { meta string xmlFile string decoyTag string weight float64 } - tests := []struct { + test1 := []struct { name string - args args + args args1 want int }{ { name: "Testting protXML reading and formating for the filter", - args: args{xmlFile: "interact.prot.xml", decoyTag: "rev_", weight: 1.00}, + args: args1{xmlFile: "interact.prot.xml", decoyTag: "rev_", weight: 1.00}, want: 7926, }, } - for _, tt := range tests { + + for _, tt := range test1 { t.Run(tt.name, func(t *testing.T) { got := readProtXMLInput(tt.args.xmlFile, tt.args.decoyTag, tt.args.weight) @@ -342,29 +302,20 @@ func Test_readProtXMLInput(t *testing.T) { }) } - //tes.ShutDowTestEnv() -} - -func Test_proteinProfile(t *testing.T) { - type args struct { - p id.ProtXML - } - tests := []struct { + test2 := []struct { name string - args args wantT int wantD int }{ { name: "Testing Protein Profile", - args: args{p: proXML}, wantT: 8018, wantD: 949, }, } - for _, tt := range tests { + for _, tt := range test2 { t.Run(tt.name, func(t *testing.T) { - gotT, gotD := proteinProfile(tt.args.p) + gotT, gotD := proteinProfile(proXML) if gotT != tt.wantT { t.Errorf("proteinProfile() gotT = %v, want %v", gotT, tt.wantT) } @@ -373,11 +324,8 @@ func Test_proteinProfile(t *testing.T) { } }) } -} -func Test_processProteinIdentifications(t *testing.T) { - type args struct { - p id.ProtXML + type args3 struct { ptFDR float64 pepProb float64 protProb float64 @@ -386,15 +334,18 @@ func Test_processProteinIdentifications(t *testing.T) { fo bool decoyTag string } - tests := []struct { + test3 := []struct { name string - args args + args args3 }{ - // TODO: Add test cases. + { + name: "Testing Protein Identifications", + args: args3{ptFDR: 0.01, pepProb: 0.7, protProb: 0.5, isPicked: false, isRazor: true, fo: false, decoyTag: "rev_"}, + }, } - for _, tt := range tests { + for _, tt := range test3 { t.Run(tt.name, func(t *testing.T) { - processProteinIdentifications(tt.args.p, tt.args.ptFDR, tt.args.pepProb, tt.args.protProb, tt.args.isPicked, tt.args.isRazor, tt.args.fo, tt.args.decoyTag) + processProteinIdentifications(proXML, tt.args.ptFDR, tt.args.pepProb, tt.args.protProb, tt.args.isPicked, tt.args.isRazor, tt.args.fo, tt.args.decoyTag) }) } } diff --git a/lib/id/pro_test.go b/lib/id/pro_test.go index 6e903171..3f99b40d 100644 --- a/lib/id/pro_test.go +++ b/lib/id/pro_test.go @@ -77,5 +77,4 @@ func TestProtXML_MarkUniquePeptides(t *testing.T) { }) } - tes.ShutDowTestEnv() } diff --git a/lib/spc/spc_test.go b/lib/spc/spc_test.go index d8f16d73..693717a6 100644 --- a/lib/spc/spc_test.go +++ b/lib/spc/spc_test.go @@ -198,8 +198,6 @@ func TestPepXML_Parse(t *testing.T) { // } }) } - - tes.ShutDowTestEnv() } func TestProtXML_Parse(t *testing.T) { @@ -263,6 +261,4 @@ func TestProtXML_Parse(t *testing.T) { }) } - tes.ShutDowTestEnv() - } diff --git a/lib/tes/tes.go b/lib/tes/tes.go index 1c999906..f5c4046e 100644 --- a/lib/tes/tes.go +++ b/lib/tes/tes.go @@ -9,7 +9,12 @@ import ( func SetupTestEnv() { os.Chdir("../../test/wrksp/") - wrk.Init("0000", "0000") + + if _, err := os.Stat(".meta"); err != nil { + if os.IsNotExist(err) { + wrk.Init("0000", "0000") + } + } return } diff --git a/lib/uti/uti_test.go b/lib/uti/uti_test.go index 02fa762f..41b8e287 100644 --- a/lib/uti/uti_test.go +++ b/lib/uti/uti_test.go @@ -20,6 +20,4 @@ func TestUti(t *testing.T) { t.Errorf("Aminoacid name is incorrect, got %f, want %f", y, 5.3557876867) } - tes.ShutDowTestEnv() - } diff --git a/lib/wrk/wrk_test.go b/lib/wrk/wrk_test.go index 55c7aad4..59448345 100644 --- a/lib/wrk/wrk_test.go +++ b/lib/wrk/wrk_test.go @@ -32,6 +32,4 @@ func TestInit(t *testing.T) { Init(tt.args.version, tt.args.build) }) } - - tes.ShutDowTestEnv() }