Creating domain sample set using Python, how to add naming pattern

LabKey Support Forum
Creating domain sample set using Python, how to add naming pattern jack mason  2024-06-18 07:44
Status: Active
 

Am using the Python package to create some samples using the domain API.

Here is some example code:

from labkey.api_wrapper import APIWrapper

labkey_server = 'localhost:8443'
container_path = 'T Cell Cloning Samples/Sequencing'
contextPath = None
schema = 'samples'
table = 'tcc_sample_handover'
api = APIWrapper(labkey_server, container_path, contextPath)

definition = {
    "kind": "SampleSet",
    "domainDesign": {
        "name": "tcc_sample_handover",
        "description": "TCC Sample Handover",
        "fields": [
            {"name": "Name", "rangeURI": "string"},
            {"name": "hla_restriction", "rangeURI": "string"},
            {"name": "tcc_sample_id", "rangeURI": "string"},
            {"name": "tcc", "rangeURI": "string"},
            {"name": "antigen", "rangeURI": "string"},
            {"name": "peptide_sequence", "rangeURI": "string"},
            {"name": "donor", "rangeURI": "string"},
            {"name": "race_prep", "rangeURI": "boolean"},
            {"name": "post_sort_well", "rangeURI": "string"},
            {"name": "cell_per_well", "rangeURI": "string"},
            {"name": "date_frozen", "rangeURI": "dateTime"}
        ]
    }
}

result = api.domain.create(definition)
print(result)

I am unsure how I can add a naming pattern to the definition.
I've added an attachment for what the naming pattern looks like.
Here's a link to the labkey docs for naming patterns also:
https://www.labkey.org/Documentation/wiki-page.view?name=sampleIDs#:~:text=Each sample in a Sample,of the Sample Type definition.

 
 
mohara responded:  2024-06-19 11:27

Hi Jack:

Your best bet here is to define the Sample Type itself using the UI, where you can set up the naming pattern, as well as all the fields needed. Then you can use the python API to populate it.

Another option, since your naming pattern looks to be just the value from a different column, would be to either change the source spreadsheet to rename it OR possibly use an import alias on the SampleID (Name) field, though I have not tried that using the python API myself.

Thanks for reaching out and hope that helps,

--Molly

 
jack mason responded:  2024-06-20 04:03

Hi Molly,

Thank you for the response, I understand that I can only add the naming pattern through the UI.

I am not sure what you mean by source spreadsheets or import aliases, I have not used these terms in LabKey before.
Could you further explain please (with documentation links if possible)? :)

Kind Regards,

Jack

 
mohara responded:  2024-06-20 11:18

Sure, here's a bit more:
What I meant is that the naming pattern you want to use:
${tcc_sample_id}
...is just saying to use the value in the "tcc_sample_id" column of your data (source spreadsheet is how I phrased that).

However the data will be provided, that column will have to exist and have unique values to provide the unique sample naming. One solution is to rename that column in your data to be "Name" instead. If that's possible, then your samples will automatically end up with those names.

If you can't change the incoming data, another possibility is to use an import alias. Essentially, you tell the "Name" field that it should look for "tcc_sample_id" in the data and put that directly in as the sample Name.

Some relevant documentation:

Note that I have not specifically tried the alias on the Name field for a sample type being set via API, and we're not able to provide detailed developer support on this forum, but I believe it is settable there, and that's something else to try if you can't change the actual incoming data field name.

Another resource you may find helpful as you learn the various LabKey terms and options is the playlist available here:

Hope that helps,

--Molly