### Start the build process Source: https://docs.gpcrdb.org/building_a_database.html Runs the build_all management command with 4 processes and the -t flag for a test build. Remove -t for a full build (not recommended on the development VM). ```bash /env/bin/python3 manage.py build_all -p 4 -t ``` -------------------------------- ### Indentation example: 4 spaces Source: https://docs.gpcrdb.org/coding_style.html Shows the required 4-space indentation for loops. The example uses a for loop over proteins and prints each protein. ```python for protein in proteins: print(protein) ``` -------------------------------- ### Comment style: # followed by a single space Source: https://docs.gpcrdb.org/coding_style.html Demonstrates the correct format for comments: start with a hash and a single space. ```python # this is a comment ``` -------------------------------- ### Python 2 with urllib2 - Fetch protein and alignment Source: https://docs.gpcrdb.org/web_services.html Legacy example for Python 2 using urllib2. Fetches a protein and an alignment, parsing JSON and iterating with iteritems(). ```python from urllib2 import urlopen import json # fetch a protein url = 'https://gpcrdb.org/services/protein/adrb2_human/' response = urlopen(url) protein_data = json.loads(response.read()) print protein_data print protein_data['sequence'] # fetch an alignment url = 'https://gpcrdb.org/services/alignment/protein/adrb1_human,adrb2_human,adrb3_human/TM3,TM5,TM6/' response = urlopen(url) alignment_data = json.loads(response.read()) for protein, sequence in alignment_data.iteritems(): print protein print sequence ``` -------------------------------- ### Naming conventions: variables, constants, functions, classes Source: https://docs.gpcrdb.org/coding_style.html Illustrates naming conventions: lower_case_with_underscores for variables and functions, UPPER_CASE for constants, and InitialCaps for class names. The example also shows a class with an __init__ method. ```python this_is_a_variable = True THIS_IS_A_CONSTANT = True def this_is_a_function(): pass class ThisIsAClass: __init__(self): pass ``` -------------------------------- ### Update static file repository Source: https://docs.gpcrdb.org/reload_database.html Optional step to collect static files. Not for Vagrant setup. ```bash manage.py collectstatic ``` -------------------------------- ### Import grouping: django, project, other Source: https://docs.gpcrdb.org/coding_style.html Demonstrates grouping imports into three categories (django, project, other) separated by one blank line, and followed by 2 blank lines. The example shows imports from django.conf, protein.models, and yaml. ```python from django.conf import settings from protein.models import Protein import yaml class ... ``` -------------------------------- ### Blank lines after class definitions Source: https://docs.gpcrdb.org/coding_style.html Shows that class definitions are followed by 2 blank lines. The example includes a class definition and a placeholder for the next class. ```python class ThisIsAClass: __init__(self): pass class ... ``` -------------------------------- ### Navigate to project root directory Source: https://docs.gpcrdb.org/reload_database.html Change to the project root directory on the virtual machine. ```bash cd /protwis/sites/protwis ``` -------------------------------- ### Run database migrations Source: https://docs.gpcrdb.org/building_a_database.html Applies Django migrations to set up the database schema. ```bash /env/bin/python3 manage.py migrate ``` -------------------------------- ### Log into the Vagrant VM and navigate to project directory Source: https://docs.gpcrdb.org/building_a_database.html SSH into the Vagrant VM and change to the protwis project directory. ```bash vagrant ssh cd /protwis/sites/protwis ``` -------------------------------- ### Create and checkout a feature branch Source: https://docs.gpcrdb.org/git_workflow.html Creates and switches to a new branch named 'feature/branch-name-describes-ticket'. Use a descriptive branch name. ```bash git checkout -b feature/branch-name-describes-ticket ``` -------------------------------- ### Stage and commit a file Source: https://docs.gpcrdb.org/git_workflow.html Adds a specific file to the index and commits it with a message. Always use the -m flag to provide a commit message. ```bash git add my_file.py git commit -m "Optimized the performance of my_file" ``` -------------------------------- ### Download the newest dump from gpcrdb Source: https://docs.gpcrdb.org/reload_database.html Optional step to download the latest database dump from gpcrdb if you don't already have one. ```bash curl https://files.gpcrdb.org/protwis_sp.sql.gz > ~/protwis.sql.gz ``` -------------------------------- ### Stage all modified and new files Source: https://docs.gpcrdb.org/git_workflow.html Adds all modified and new files to the index for committing. ```bash git add --all ``` -------------------------------- ### Load the dump into the database Source: https://docs.gpcrdb.org/reload_database.html Loads the dump file (either from default location or a chosen one) into the protwis database. ```bash gunzip -c ~/protwis.sql.gz | psql -U protwis -h localhost -d protwis ``` -------------------------------- ### Python 3 with requests - Fetch protein and alignment Source: https://docs.gpcrdb.org/web_services.html Recommended approach. Requires the requests library. Fetches a protein by ID and an alignment for multiple proteins and specific transmembrane segments, printing the JSON response and sequence data. ```python import requests # fetch a protein url = 'https://gpcrdb.org/services/protein/adrb2_human/' response = requests.get(url) protein_data = response.json() print(protein_data) print(protein_data['sequence']) # fetch an alignment url = 'https://gpcrdb.org/services/alignment/protein/adrb1_human,adrb2_human,adrb3_human/TM3,TM5,TM6/' response = requests.get(url) alignment_data = response.json() for protein, sequence in alignment_data.items(): print(protein) print(sequence) ``` -------------------------------- ### Show current branch Source: https://docs.gpcrdb.org/git_workflow.html Displays the current branch name. ```bash git branch ``` -------------------------------- ### Add upstream remote Source: https://docs.gpcrdb.org/git_workflow.html Connects the local repository to the main Protwis repository as 'upstream'. Run from the repo root directory. ```bash git remote add upstream https://github.com/protwis/protwis.git ``` -------------------------------- ### Rebuild local BLAST database Source: https://docs.gpcrdb.org/reload_database.html Optional step to rebuild the local BLAST database. ```bash manage.py build_blast_database ``` -------------------------------- ### Clone the gpcrdb_data repository Source: https://docs.gpcrdb.org/building_a_database.html Clones the gpcrdb_data repository from GitHub into the shared data directory. ```bash cd ~/protwis_vagrant git clone https://github.com/protwis/gpcrdb_data.git shared/data/protwis/gpcr ```