func form(c web.C, w http.ResponseWriter, r *http.Request) { b, err := ioutil.ReadFile("client_secret.json") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } config, err := google.ConfigFromJSON(b, drive.DriveMetadataReadonlyScope, drive.DriveFileScope, plus.UserinfoProfileScope) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } config.RedirectURL = redirectUrl ctx := context.Background() authToken := c.Env["access-token"].(oauth2.Token) plusClient := config.Client(ctx, &authToken) plusService, err := plus.New(plusClient) user, err := plusService.People.Get("me").Do() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } templateData := make(map[string]interface{}) templateData["Image"] = user.Image.Url templateData["Name"] = user.DisplayName session, err := store.Get(r, "p2drive") if err != nil { http.Error(w, err.Error(), 500) return } if flashes := session.Flashes("error"); len(flashes) > 0 { templateData["ErrorFlash"] = flashes[0] } if flashes := session.Flashes("success"); len(flashes) > 0 { templateData["SuccessFlash"] = flashes[0] } session.Save(r, w) if err := templates.Render(w, "projects-param2drive-form.html", templateData); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } }
func compute(c web.C, w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } var inputError []string aa_pattern := "^([AaCcDdEeFfGgHhIiKkLlMmNnPpQqRrSsTtUuVvWwYy]+)$" range_pattern := "^([0-9]+)-([0-9]+)$" aa_match, err := regexp.MatchString(aa_pattern, r.Form.Get("Sequence")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } range_match, err := regexp.MatchString(range_pattern, r.Form.Get("Range")) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } if r.Form.Get("Name") == "" { inputError = append(inputError, "A name is required") } if !aa_match { inputError = append(inputError, "The sequence must be a valid amino acid sequence") } if !range_match { inputError = append(inputError, "The amino acid range must be of the form #-# eg. 21-63") } else { rangeArray := strings.Split(r.Form.Get("Range"), "-") rangeStart, err := strconv.Atoi(rangeArray[0]) rangeStop, err := strconv.Atoi(rangeArray[1]) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } rangeLen := rangeStop - rangeStart + 1 if rangeLen != len(r.Form.Get("Sequence")) { inputError = append(inputError, "The sequence length does not match the range length") } } if r.Form.Get("Features") == "" { inputError = append(inputError, "At least one feature needs to be selected") } if len(inputError) > 0 { session, err := store.Get(r, "p2drive") if err != nil { http.Error(w, err.Error(), 500) return } session.AddFlash(inputError, "error") session.Save(r, w) http.Redirect(w, r, "/projects/p2drive/input", 302) return } p2dInput := inputData{ Sequence: r.Form.Get("Sequence"), Options: r.Form["Features"], } jsonInput, err := json.Marshal(p2dInput) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } jsonOutput, err := exec.Command("python", "scripts/compute_params.py", string(jsonInput)).Output() if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } p2dOutput := outputData{ Name: r.Form.Get("Name"), Sequence: r.Form.Get("Sequence"), Range: r.Form.Get("Range"), } err = json.Unmarshal(jsonOutput, &p2dOutput) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } params := structs.Map(p2dOutput) if err := templates.Render(w, "projects-param2drive-results.html", params); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } }
func faq(c web.C, w http.ResponseWriter, r *http.Request) { if err := templates.Render(w, "faq.html", nil); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } }
func intro(c web.C, w http.ResponseWriter, r *http.Request) { if err := templates.Render(w, "projects-param2drive.html", nil); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } }
func structuresInfo(c web.C, w http.ResponseWriter, r *http.Request) { if err := templates.Render(w, "projects-structures-info.html", nil); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } }