Renaming/replacing primary key to query across schemas

81 views Asked by At

I currently have two separate schemas for processed calcium imaging data, in which I've used two different preprocessing methods. The big goal of what I am trying to do is use sources from 1 schema as a reference and pull out the corresponding sources in the second schema. I have done source matching so that I know for each neuron in schema1 what its corresponding neuron in schema2 is.

In a table in schema1, each neuron has an integer primary key called neurID and a foreign key (schema2ID) with the corresponding primary key for that neuron in schema2. The problem I am running into is that in schema2, each neuron's primary key is also called neurID, so this is not the same neuron as in schema1 (e.g., a neuron in schema1 with neurID = 1, schema2ID = 15 would correspond to a neuron in schema2 with neurID = 15, schema1ID = 1).

Ideally, what I would want to do is once I have all the neurons from 1 schema for which I have their corresponding IDs in schema2, I would replace their primary key neurID with the foreign key schema2ID so that I could now use that to get the corresponding neurons in schema2 (since the schema2ID in schema1 is the same as the neurID schema2 primary key). Is there any way to rename a primary key in this way? Or is there some other hacky approach that I could use through creating new tables?

(Note that this is all further complicated by the fact that I also have another primary key 'targID' in each schema for which the indexing also does not mean the same thing across schemas.)

I would really appreciate any tips, as I'm quite stuck. Also happy to show code more directly through DMs etc. Thanks!

1

There are 1 answers

1
Thinh Nguyen On

Perhaps using DataJoint's projection operator (.proj()) would help in your case. The .proj() operation can be used to rename attributes, see https://docs.datajoint.io/python/queries/08-Proj.html?highlight=project

Take your above example, you can try this:

schema1_table * schema2_table.proj(schema2ID='neurID')

or the opposite would work too:

schema1_table.proj(schema1ID='neurID') * schema2_table