<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Build Adjacency Matrix
Step1:  Queries
Step2:  Step through every interaction.
If geneids1 not in matrix - insert it as dict.
If geneids2 not in matrix[geneids1] - insert it as []
If probability not in matrix[geneids1][geneids2] - insert it.
Perform the reverse.
<ASSISTANT_TASK:>
Python Code:
import sqlite3
import json
DATABASE = "data.sqlite"
conn = sqlite3.connect(DATABASE)
cursor = conn.cursor()
Explanation: Build Adjacency Matrix
End of explanation
# For getting the maximum row id
QUERY_MAX_ID = "SELECT id FROM interactions ORDER BY id DESC LIMIT 1"
# Get interaction data
QUERY_INTERACTION = "SELECT geneids1, geneids2, probability FROM interactions WHERE id = {}"
max_id = cursor.execute(QUERY_MAX_ID).fetchone()[0]
Explanation: Queries
End of explanation
matrix = {}
row_id = 0
while row_id <= max_id:
    row_id+= 1
    
    row = cursor.execute(QUERY_INTERACTION.format(row_id))
    row = row.fetchone()
    
    if row == None:
        continue
     
    id1 = row[0]
    id2 = row[1]
    prob = int(round(row[2],2) * 1000)
    # Forward
    if id1 not in matrix:
        matrix[id1] = {}
    if id2 not in matrix[id1]:
        matrix[id1][id2] = []
    if prob not in matrix[id1][id2]:
        matrix[id1][id2].append(prob)
    
    # Backwards
    if id2 not in matrix:
        matrix[id2] = {}
    if id1 not in matrix[id2]:
        matrix[id2][id1] = []
    if prob not in matrix[id2][id1]:
        matrix[id2][id1].append(prob)
    
with open("matrix.json", "w+") as file:
    file.write(json.dumps( matrix ))
Explanation: Step through every interaction.
If geneids1 not in matrix - insert it as dict.
If geneids2 not in matrix[geneids1] - insert it as []
If probability not in matrix[geneids1][geneids2] - insert it.
Perform the reverse.
End of explanation
<END_TASK>