func main() { masses := []spectrum.Mass{} scanner := bufio.NewScanner(os.Stdin) for scanner.Scan() { m, err := spectrum.ParseMass(scanner.Text()) if err != nil { log.Fatal(err) } masses = append(masses, m) } if err := scanner.Err(); err != nil { log.Fatal(err) } spec, err := spectrum.New(masses[1:]) if err != nil { log.Fatal(err) } p, ok := spec.Protein() if ok { fmt.Println(p) } else { log.Fatal("Protein not found") } }
func TestFullSpectrum(t *testing.T) { rand.Seed(1) aa := []byte{} for a := range spectrum.MonoisotopicMass { if a == 'L' { continue } aa = append(aa, a) } for k := 0; k < 100; k++ { n := MinLen + rand.Intn(MaxLen-MinLen+1) prot := make([]byte, n) for i := 0; i < n; i++ { j := rand.Intn(len(aa)) prot[i] = aa[j] } protStr := string(prot) w1 := spectrum.Mass(500 + 500*rand.Float64()) w2 := spectrum.Mass(500 + 500*rand.Float64()) masses := []spectrum.Mass{} for i := 0; i <= len(prot); i++ { m1 := w1 for j := 0; j < i; j++ { m1 += spectrum.MonoisotopicMass[prot[j]] } m2 := w2 for j := i; j < len(prot); j++ { m2 += spectrum.MonoisotopicMass[prot[j]] } masses = append(masses, m1, m2) } // Shuffle. for i := 0; i < len(masses)-1; i++ { j := rand.Intn(len(masses) - i) masses[i], masses[i+j] = masses[i+j], masses[i] } sortedMasses := make([]spectrum.Mass, len(masses)) copy(sortedMasses, masses) sort.Sort(spectrum.MassSlice(sortedMasses)) spec, err := spectrum.New(masses) if err != nil { t.Fatalf("Unexpected error: %v", err) } q, ok := spec.Protein() if !ok { t.Errorf("No protein found for %v; expected %s", masses, protStr) } else if q != protStr && q != reversed(protStr) { t.Errorf("Found protein %s; expected %s / %v", q, protStr, masses) } } }
func main() { prots, masses, err := readInput(os.Stdin) if err != nil { log.Fatal(err) } db := []*spectrum.Spectrum{} for _, pr := range prots { s, err := spectrum.FromProtein(pr) if err != nil { log.Fatal(err) } db = append(db, s) } spec, err := spectrum.New(masses) if err != nil { log.Fatal(err) } best := 0 which := "" for _, dbSpec := range db { pr := dbSpec.Source conv := spec.Convolution(dbSpec) m, k := conv.Max() _ = m //fmt.Println(pr) //fmt.Println(k, m) if k > best { best = k which = pr } } fmt.Println(best) fmt.Println(which) }