// Retrieve Process processURI = "http://${hostname}/api/v2/processes/${processLIMSID}" process = GLSRestApiUtils.httpGET(processURI, username, password)<prc:process uri="http://yourIPaddress/api/v2/processes/A14-BMJ-100830-24-1472" limsid="A14-BMJ-100830-24-1472"> <type>API Cookbook Example 1.4</type> <date-run>2010-08-30</date-run> <technician uri="http://yourIPaddress/api/v2/researchers/305"> <first-name>Brandon</first-name> <last-name>Johnson</last-name> </technician> <input-output-map> <input uri="http://yourIPaddress/api/v2/artifacts/HAM754A4PA1?state=15633" post-process-uri="http://yourIPaddress/api/v2/artifacts/HAM754A4PA1?state=15641" limsid="HAM754A4PA1"/> <output uri="http://yourIPaddress/api/v2/artifacts/HAM754A4AP8?state=15644" output-type="Analyte" limsid="HAM754A4AP8"/> </input-output-map> <input-output-map> <input uri="http://yourIPaddress/api/v2/artifacts/HAM754A1PA1?state=15622" post-process-uri="http://yourIPaddress/api/v2/artifacts/HAM754A1PA1?state=15646" limsid="HAM754A1PA1"/> <output uri="http://yourIPaddress/api/v2/artifacts/HAM754A1AP8?state=15642" output-type="Analyte" limsid="HAM754A1AP8"/> </input-output-map> <input-output-map> <input uri="http://yourIPaddress/api/v2/artifacts/HAM754A3PA1?state=15626" post-process-uri="http://yourIPaddress/api/v2/artifacts/HAM754A3PA1?state=15637" limsid="HAM754A3PA1"/> <output uri="http://yourIPaddress/api/v2/artifacts/HAM754A3AP8?state=15639" output-type="Analyte" limsid="HAM754A3AP8"/> </input-output-map></prc:process>// For each input-output-map, if its output is an Analyte, set its Library Size UDF process.'input-output-map'.each { if (it.output.@'output-type'[0] == "Analyte") { analyteURI = it.output.@uri[0] analyte = GLSRestApiUtils.httpGET(analyteURI, username, password) analyte = GLSRestApiUtils.setUdfValue(analyte, 'Library Size', '25') GLSRestApiUtils.httpPUT(analyte, analyte.@uri, username, password) } }http://yourIPaddress/api/v2/artifacts/HAM754A4AP8\
<art:artifact uri="http://yourIPaddress/api/v2/artifacts/HAM754A4AP8?state=15644" limsid="HAM754A4AP8"> <name>Colon-4</name> <type>Analyte</type> <output-type>Analyte</output-type> <parent-process uri="http://yourIPaddress/api/v2/processes/A14-BMJ-100830-24-1472" limsid="A14-BMJ-100830-24-1472"/> <volume unit="uL">0.0</volume> <concentration unit="ug/mL">10.0</concentration> <qc-flag>UNKNOWN</qc-flag> <location> <container uri="http://yourIPaddress/api/v2/containers/27-2320" limsid="27-2320"/> <value>1:1</value> </location> <working-flag>true</working-flag> <sample uri="http://yourIPaddress/api/v2/samples/HAM754A4" limsid="HAM754A4"/> <udf:field type="Numeric" name="Library Size">25</udf:field></art:artifact>

targetDownstreamArtifactNode = GLSRestApiUtils.httpGET(artifactsListURI + artifactLUID, username, password)
targetReagentLabel = targetDownstreamArtifactNode.'reagent-label'[0]?.'@name'
if (!targetReagentLabel) {
println "Specified artifact should contain at least one reagent-label. Skipping ${artifactLUID}..."
continue
}
// At each upstream level of the workflow the number of searched artifacts may increase due to Pooling processes
upstreamArtifactLUIDs = [ artifactLUID ]
/*
* This 'stack' will store all upstream artifacts that serve as input to an 'Add Multiple Reagents' process
* which are subsequently assigned the 'target' Reagent Label by this process.
*/
foundUpstreamArtifactNodes = []while (!upstreamArtifactLUIDs.isEmpty()) {
currentArtifactLUID = upstreamArtifactLUIDs.pop()
currentArtifactNode = GLSRestApiUtils.httpGET(artifactsListURI + currentArtifactLUID, username, password)
/*
* Upstream traversal will stop when either an artifact is found that does not have reagent label(s) assigned
* (i.e. the artifact is the input to a process that adds reagents and reagent labels), or a root artifact is found.
* At this point, the current artifact is added to the list of 'found' upstream artifact nodes.
*/
if (currentArtifactNode.'reagent-label'.isEmpty() || currentArtifactNode.'parent-process'.isEmpty()) {
foundUpstreamArtifactNodes += [currentArtifactNode]
} else if (currentArtifactNode.'reagent-label'.collect { it.'@name' }.contains(targetReagentLabel)) {
/*
* If the current artifact contains the 'target' reagent label, continue traversing upstream.
* Get the artifact's parent process
*/
parentProcessURI = currentArtifactNode.'parent-process'[0].@uri
parentProcessNode = GLSRestApiUtils.httpGET(parentProcessURI, username, password)
// Find all input-output maps for the parent process
parentProcessNode.'input-output-map'.each {
ioMapInputLUID = it.'input'[0].@limsid
ioMapOutputLUID = it.'output'[0].@limsid
// Push all process input artifacts that have the current artifact as the mapped process output onto the 'stack'
if( ioMapOutputLUID == currentArtifactLUID && !upstreamArtifactLUIDs.contains(ioMapInputLUID) ) {
upstreamArtifactLUIDs.push(ioMapInputLUID)
}
}
}
}/*
* Compute the 'Mean DNA Prep 260:280 Ratio' for all upstream analyte artifacts that have the
* target Reagent Label applied. The assumption here is that the 'DNA prep 260:280 ratio' UDF
* is set on analytes that serve as input to an 'Add Multiple Reagents' process that assigns Reagent Labels.
*/
avgAcrossUpstreamArtifacts = foundUpstreamArtifactNodes.collect {
foundUdf = it.'udf:field'.find{ it.'@name' == upstreamArtifactUdfToMine }
return foundUdf ? foundUdf.value()[0] as double : 0.0
}.sum()/foundUpstreamArtifactNodes.size()// Set the computed mean on the 'Mean DNA Prep 260:280 Ratio' UDF on the target downstream ResultFile
targetDownstreamAritfactUDF = targetDownstreamArtifactNode.'udf:field'.find{ it.'@name' == downstreamArtifactUdfToUpdate }
if (targetDownstreamAritfactUDF) {
targetDownstreamAritfactUDF.setValue(avgAcrossUpstreamArtifacts)
} else {
targetDownstreamArtifactNode.appendNode('udf:field',
['name':downstreamArtifactUdfToUpdate,
'xmlns:udf':'http://genologics.com/ri/userdefined'],
avgAcrossUpstreamArtifacts)
}<art:artifact uri="http://yourIPaddress/api/v2/artifacts/HAM751A481PA1?state=9995" limsid="HAM751A481PA1">
<name>Brain-600</name>
<type>Analyte</type>
<output-type>Analyte</output-type>
<volume unit="uL">645.0</volume>
<concentration unit="ug/mL">0.5478</concentration>
<qc-flag>UNKNOWN</qc-flag>
<location>
<container uri="http://yourIPaddress/api/v2/containers/27-1259" limsid="27-1259"/>
<value>A:1</value>
</location>
<working-flag>true</working-flag>
<sample uri="http://yourIPaddress/api/v2/samples/HAM751A481" limsid="HAM751A481"/>
</art:artifact>Â // Retrieve the artifact
artifactURI = "http://${hostname}/api/v2/artifacts/${artifactLIMSID}"
artifact = GLSRestApiUtils.httpGET(artifactURI, username, password)// Separate the artifact's position inside of its container
containerPosition = artifact.location.value.text()
positionList = containerPosition.tokenize(':')
// Output its position
row = positionList[0]
column = positionList[1]
println "This sample is located at row: $row, column: $column"This sample is located at row: A, column: 1

// Retrieve the process
processURI = "http://${hostname}/api/v2/processes/${processLIMSID}"
process = GLSRestApiUtils.httpGET(processURI, username, password)<prc:process uri="http://yourIPaddress/api/v2/processes/A13-BMJ-100830-24-1475" limsid="A13-BMJ-100830-24-1475">
<type>API Cookbook Example 1.3</type>
<date-run>2010-08-30</date-run>
<technician uri="http://yourIPaddress/api/v2/researchers/305">
<first-name>Brandon</first-name>
<last-name>Johnson</last-name>
</technician>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/HAM754A3PA1?state=15657" post-process-uri="http://yourIPaddress/api/v2/artifacts/HAM754A3PA1?state=15678" limsid="HAM754A3PA1"/>
<output uri="http://yourIPaddress/api/v2/artifacts/HAM754A3AP10?state=15683" output-type="Analyte" limsid="HAM754A3AP10"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/HAM754A1PA1?state=15651" post-process-uri="http://yourIPaddress/api/v2/artifacts/HAM754A1PA1?state=15685" limsid="HAM754A1PA1"/>
<output uri="http://yourIPaddress/api/v2/artifacts/HAM754A1AP10?state=15680" output-type="Analyte" limsid="HAM754A1AP10"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/HAM754A2PA1?state=15656" post-process-uri="http://yourIPaddress/api/v2/artifacts/HAM754A2PA1?state=15686" limsid="HAM754A2PA1"/>
<output uri="http://yourIPaddress/api/v2/artifacts/HAM754A2AP10?state=15681" output-type="Analyte" limsid="HAM754A2AP10"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/HAM754A6PA1?state=15659" post-process-uri="http://yourIPaddress/api/v2/artifacts/HAM754A6PA1?state=15679" limsid="HAM754A6PA1"/>
<output uri="http://yourIPaddress/api/v2/artifacts/HAM754A6AP10?state=15677" output-type="Analyte" limsid="HAM754A6AP10"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/HAM754A4PA1?state=15655" post-process-uri="http://yourIPaddress/api/v2/artifacts/HAM754A4PA1?state=15682" limsid="HAM754A4PA1"/>
<output uri="http://yourIPaddress/api/v2/artifacts/HAM754A4AP10?state=15687" output-type="Analyte" limsid="HAM754A4AP10"/>
</input-output-map>
<input-output-map>
<input uri="http://yourIPaddress/api/v2/artifacts/HAM754A5PA1?state=15652" post-process-uri="http://yourIPaddress/api/v2/artifacts/HAM754A5PA1?state=15684" limsid="HAM754A5PA1"/>
<output uri="http://yourIPaddress/api/v2/artifacts/HAM754A5AP10?state=15688" output-type="Analyte" limsid="HAM754A5AP10"/>
</input-output-map>
</prc:process>// For each input-output-map process.'input-output-map'.each { if (it.output.@'output-type'[0] == "Analyte") { // Retrieve the analyte analyteURI = it.output.@uri[0] analyte = GLSRestApiUtils.httpGET(analyteURI, username, password) // Retrieve the analyte's sample and get its Priority UDF's value sampleURI = analyte.sample.@uri[0] sample = GLSRestApiUtils.httpGET(sampleURI, username, password) samplePriority = sample.'udf:field'.find { it.@name== 'Priority' }?.text() // Rename the analyte nameNode = analyte.name[0]// For each input-output-map
process.'input-output-map'.each {
if (it.output.@'output-type'[0] == "Analyte") {
// Retrieve the analyte
analyteURI = it.output.@uri[0]
analyte = GLSRestApiUtils.httpGET(analyteURI, username, password)
// Retrieve the analyte's sample and get its Priority UDF's value
sampleURI = analyte.sample.@uri[0]
sample = GLSRestApiUtils.httpGET(sampleURI, username, password)
samplePriority = sample.'udf:field'.find { it.@name== 'Priority' }?.text()
// Rename the analyte
nameNode = analyte.name[0]<art:artifact uri="http://yourIPaddress/api/v2/artifacts/AFF853A43AP2?state=20985" limsid="AFF853A43AP2">
<name>Heart-1</name>
<type>Analyte</type>
<output-type>Analyte</output-type>
<parent-process uri="http://yourIPaddress/api/v2/processes/A13-BMJ-100923-24-2182" limsid="A13-BMJ-100923-24-2182"/>
<qc-flag>UNKNOWN</qc-flag>
<location>
<container uri="http://yourIPaddress/api/v2/containers/27-303" limsid="27-303"/>
<value>1:1</value>
</location>
<working-flag>true</working-flag>
<sample uri="http://yourIPaddress/api/v2/samples/AFF853A43" limsid="AFF853A43"/>
</art:artifact>newName = nameNode.text() + " " + samplePriority
nameNode.setValue(newName)
returnNode = GLSRestApiUtils.httpPUT(analyte, analyte.@uri, username, password)
}
}Â <art:artifact uri="http://yourIPaddress/api/v2/artifacts/AFF853A43AP2?state=20985" limsid="AFF853A43AP2">
<name>Heart-1 sp1</name>
<type>Analyte</type>
<output-type>Analyte</output-type>
<parent-process uri="http://yourIPaddress/api/v2/processes/A13-BMJ-100923-24-2182" limsid="A13-BMJ-100923-24-2182"/>
<qc-flag>UNKNOWN</qc-flag>
<location>
<container uri="http://yourIPaddress:/api/v2/containers/27-303" limsid="27-303"/>
<value>1:1</value>
</location>
<working-flag>true</working-flag>
<sample uri="http://yourIPaddress/api/v2/samples/AFF853A43" limsid="AFF853A43"/>
</art:artifact>Â outputToInputMap = [:]
processURI = "http://${hostname}/api/v2/processes/${processLIMSID}"
p+cess = GLSRestApiUtils.httpGET(processURI, username, password)Â <prc:process uri="http://IPAddress/api/v2/processes/TES-SA1-130107-24-5259" limsid="TES-SA1-130107-24-5259">
<type uri="http://IPAddress/api/v2/processtypes/355">Cookbook Example Process</type>
<date-run>2013-01-07</date-run>
<technician uri="http://IPAddress/api/v2/researchers/1">
<first-name>System</first-name>
<last-name>Administrator</last-name>
</technician>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A3PA1?state=8055" uri="http://IPAddress/api/v2/artifacts/ADM224A3PA1?state=8040" limsid="ADM224A3PA1" />
<output uri="http://IPAddress/api/v2/artifacts/92-13007?state=8065" output-generation-type="PerAllInputs" output-type="ResultFile" limsid="92-13007" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A3PA1?state=8055" uri="http://IPAddress/api/v2/artifacts/ADM224A3PA1?state=8040" limsid="ADM224A3PA1" />
<output uri="http://IPAddress/api/v2/artifacts/ADM224A3TE3?state=8054" output-generation-type="PerInput" output-type="Analyte" limsid="ADM224A3TE3" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A5PA1?state=8053" uri="http://IPAddress/api/v2/artifacts/ADM224A5PA1?state=8047" limsid="ADM224A5PA1" />
<output uri="http://IPAddress/api/v2/artifacts/92-13007?state=8065" output-generation-type="PerAllInputs" output-type="ResultFile" limsid="92-13007" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A5PA1?state=8053" uri="http://IPAddress/api/v2/artifacts/ADM224A5PA1?state=8047" limsid="ADM224A5PA1" />
<output uri="http://IPAddress/api/v2/artifacts/ADM224A5TE3?state=8060" output-generation-type="PerInput" output-type="Analyte" limsid="ADM224A5TE3" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A2PA1?state=8056" uri="http://IPAddress/api/v2/artifacts/ADM224A2PA1?state=8042" limsid="ADM224A2PA1" />
<output uri="http://IPAddress/api/v2/artifacts/92-13007?state=8065" output-generation-type="PerAllInputs" output-type="ResultFile" limsid="92-13007" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A2PA1?state=8056" uri="http://IPAddress/api/v2/artifacts/ADM224A2PA1?state=8042" limsid="ADM224A2PA1" />
<output uri="http://IPAddress/api/v2/artifacts/ADM224A2TE3?state=8059" output-generation-type="PerInput" output-type="Analyte" limsid="ADM224A2TE3" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A4PA1?state=8063" uri="http://IPAddress/api/v2/artifacts/ADM224A4PA1?state=8048" limsid="ADM224A4PA1" />
<output uri="http://IPAddress/api/v2/artifacts/92-13007?state=8065" output-generation-type="PerAllInputs" output-type="ResultFile" limsid="92-13007" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A4PA1?state=8063" uri="http://IPAddress/api/v2/artifacts/ADM224A4PA1?state=8048" limsid="ADM224A4PA1" />
<output uri="http://IPAddress/api/v2/artifacts/ADM224A4TE3?state=8057" output-generation-type="PerInput" output-type="Analyte" limsid="ADM224A4TE3" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A1PA1?state=8061" uri="http://IPAddress/api/v2/artifacts/ADM224A1PA1?state=8046" limsid="ADM224A1PA1" />
<output uri="http://IPAddress/api/v2/artifacts/92-13007?state=8065" output-generation-type="PerAllInputs" output-type="ResultFile" limsid="92-13007" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A1PA1?state=8061" uri="http://IPAddress/api/v2/artifacts/ADM224A1PA1?state=8046" limsid="ADM224A1PA1" />
<output uri="http://IPAddress/api/v2/artifacts/ADM224A1TE3?state=8058" output-generation-type="PerInput" output-type="Analyte" limsid="ADM224A1TE3" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A6PA1?state=8064" uri="http://IPAddress/api/v2/artifacts/ADM224A6PA1?state=8045" limsid="ADM224A6PA1" />
<output uri="http://IPAddress/api/v2/artifacts/92-13007?state=8065" output-generation-type="PerAllInputs" output-type="ResultFile" limsid="92-13007" />
</input-output-map>
<input-output-map>
<input post-process-uri="http://IPAddress/api/v2/artifacts/ADM224A6PA1?state=8064" uri="http://IPAddress/api/v2/artifacts/ADM224A6PA1?state=8045" limsid="ADM224A6PA1" />
<output uri="http://IPAddress/api/v2/artifacts/ADM224A6TE3?state=8062" output-generation-type="PerInput" output-type="Analyte" limsid="ADM224A6TE3" />
</input-output-map>
</prc:process>Â outputLIMSID -> [output-type, inputLIMSID-1, inputLIMSID-2, inputLIMSID-3, ...|output-type, inputLIMSID-1, inputLIMSID-2, inputLIMSID-3, ...]// For each io-map in the process, add its information to outputToInputMap
process.'input-output-map'.each {
outputType = it.'output'[0].'@output-type'
outputLIMSID = it.'output'[0].@limsid
inputLIMSID = it.'input'[0].@limsid
// outputToInputMap stores all the output type and LIMS IDs of all the inputs to the output
if (!outputToInputMap[outputLIMSID]) {
outputToInputMap[outputLIMSID] = [outputType, inputLIMSID]
} else {
// If entry already exists, add another input to the list
outputToInputMap[outputLIMSID] << inputLIMSID
}
}// Print the contents of the map, which stores the inputs LIMSIDs under the output's LIMSID
o+tputToInputMap.each { key, value -> println "$key is a(n) ${value[0]} with input:"
for (int i = 1; i < value.size(); i++) {
println '\t' + value[i]
}
}92-13007 is a(n) ResultFile with input:
27-2028
27-2029
27-2030
27-2031
27-2032
27-2033
27-2034 is a(n) Analyte with input:
27-2028
27-2035 is a(n) Analyte with input:
27-2029
27-2036 is a(n) Analyte with input:
27-2030
27-2037 is a(n) Analyte with input:
27-2031
27-2038 is a(n) Analyte with input:
27-2032
27-2039 is a(n) Analyte with input:
27-2033