#Code to find shared patients in PET data and SNP data 
from pandas import *
import allel

def intersect(a1, a2): 
    return list(set(a1) & set(a2))

def intersectpatient(pet_data, snp_data): 
    #Get PET_image patient IDs
    pet_patients = pet_data["RID"]
    pet_patients = pet_patients.to_list()
    pet_patients = unique(pet_patients)
    #Get SNP patient ID
    callset = allel.read_vcf(snp_data)
    snp_patients_temp = callset['samples']
    #RIDs for SNP are the last four digits 
    snp_patients = []
    for patient in snp_patients_temp: 
        snp_patients.append(int(patient[-4:]))
    return intersect(snp_patients, pet_patients)

def sharedpatient(): 
    #Change Dataset accordingly
    pet_data = read_csv("UCBERKELEYAV1451_11_16_21.csv")
    snp_data = "new_vcf.vcf"
    patients = intersectpatient(pet_data, snp_data)
    return patients 
