Skip to content

Commit

Permalink
Merge pull request #2164 from sanger/y25-010-use-sample-name-for-libr…
Browse files Browse the repository at this point in the history
…ary-batch-creation

Y25-010 use sample name for library batch creation
  • Loading branch information
seenanair authored Jan 29, 2025
2 parents 3fb10f3 + fdabdbb commit 7c27e24
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/stores/utilities/pacbioLibraryBatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const validateAndFormatAsPayloadData = ({ record, info }, requests, tags) => {
return createError(`tag ${tag} not found`)
}

const request = requests.find((r) => r.source_identifier === source)
const request = requests.find((r) => r.sample_name === source)
if (!request) {
return createError(`source ${source} not found`)
}
Expand Down Expand Up @@ -73,7 +73,7 @@ async function fetchTagsAndRequests(sources, tagSet) {

const rootStore = useRootStore()
let promise = rootStore.api.traction.pacbio.requests.get({
filter: { source_identifier: sources.join(',') },
filter: { sample_name: sources.join(',') },
})
let response = await handleResponse(promise)

Expand Down
7 changes: 5 additions & 2 deletions tests/factories/PacbioLibraryBatchFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const PacbioLibraryBatchFactory = (tags = []) => {
insert_size: 10191,
created_at: '2024/11/15 17:38',
deactivated_at: null,
sample_name: '2STDY97',
source_identifier: 'GEN-1725896371-4:B3',
pacbio_request_id: 407,
tag_id: 303,
Expand Down Expand Up @@ -89,6 +90,7 @@ const PacbioLibraryBatchFactory = (tags = []) => {
insert_size: 10191,
created_at: '2024/11/15 17:38',
deactivated_at: null,
sample_name: '5049STDY8152830',
source_identifier: 'DN814327C:A1',
pacbio_request_id: 407,
tag_id: 304,
Expand Down Expand Up @@ -153,6 +155,7 @@ const PacbioLibraryBatchFactory = (tags = []) => {
}),
tubes: tubesObj,
libraries: librariesObj,
librariesArray: Object.values(librariesObj),
}
}

Expand All @@ -174,7 +177,7 @@ const PacbioLibraryBatchFactory = (tags = []) => {
duplicate_tags && indx > 0
? lines[0].split(',')[1]
: tagArrr.find((t) => t.id === String(library.tag_id))?.group_id
const source = indx === 0 && invalid_source ? 'test' : library.source_identifier
const source = indx === 0 && invalid_source ? 'test' : library.sample_name
lines[indx] = [
source,
tag,
Expand All @@ -192,7 +195,7 @@ const PacbioLibraryBatchFactory = (tags = []) => {
const tagArrr = Object.values(tags)
const libraries_attributes = Object.values(storeData.libraries).map((library) => {
const tag = tagArrr.find((t) => t.id === String(library.tag_id))?.group_id
const request = requests.find((r) => r.source_identifier === library.source_identifier)
const request = requests.find((r) => r.sample_name === library.sample_name)
return {
...library,
pacbio_request_id: request?.id,
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/stores/pacbioLibraryBatchCreate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ describe('usePacbioLibraryBatchCreateStore', () => {
)
expect(success).toBeFalsy()
expect(errors).toEqual(
`Duplicate sources found in the csv: ${pacbioLibraryBatchFactory.storeData.librariesInBatch.map((batch) => batch.source).join(', ')}`,
`Duplicate sources found in the csv: ${pacbioLibraryBatchFactory.storeData.librariesArray
.map((batch) => batch.sample_name)
.join(', ')}`,
)
})

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/stores/utilities/pabioLibraryBatches.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('pacbioLibraryBatches', () => {

it('returns an error if tag is not found in tags', () => {
const record = {
source: requests[0].source_identifier,
source: requests[0].sample_name,
tag: 'abc',
concentration: 10,
insert_size: 100,
Expand All @@ -75,7 +75,7 @@ describe('pacbioLibraryBatches', () => {
const tag = pacbioTagSetFactory.storeData.selected.tag
const request = pacbioRequestFactory.content.data[0]
const record = {
source: request.attributes.source_identifier,
source: request.attributes.sample_name,
tag_set: tagSet.name,
tag: tag.group_id,
concentration: 10,
Expand Down Expand Up @@ -119,14 +119,14 @@ describe('pacbioLibraryBatches', () => {
}
tagSet = pacbioTagSetFactory.storeData.selected.tagSet
requestsData = pacbioRequestFactory.storeData.requestsArray
sources = requestsData.map((r) => r.source_identifier)
sources = requestsData.map((r) => r.sample_name)
})

it('fetches requests and tags successfully', async () => {
const { requests, tags } = await fetchTagsAndRequests(sources, tagSet.name)

expect(rootStore.api.traction.pacbio.requests.get).toHaveBeenCalledWith({
filter: { source_identifier: sources.join(',') },
filter: { sample_name: sources.join(',') },
})
expect(rootStore.api.traction.pacbio.tag_sets.get).toHaveBeenCalledWith({
include: 'tags',
Expand All @@ -142,7 +142,7 @@ describe('pacbioLibraryBatches', () => {
const { requests, tags } = await fetchTagsAndRequests(sources, tagSet.name)

expect(rootStore.api.traction.pacbio.requests.get).toHaveBeenCalledWith({
filter: { source_identifier: sources.join(',') },
filter: { sample_name: sources.join(',') },
})
expect(rootStore.api.traction.pacbio.tag_sets.get).toHaveBeenCalledWith({
include: 'tags',
Expand All @@ -158,7 +158,7 @@ describe('pacbioLibraryBatches', () => {
const { requests } = await fetchTagsAndRequests(sources, tagSet.name)

expect(rootStore.api.traction.pacbio.requests.get).toHaveBeenCalledWith({
filter: { source_identifier: sources.join(',') },
filter: { sample_name: sources.join(',') },
})
expect(rootStore.api.traction.pacbio.tag_sets.get).toHaveBeenCalledWith({
include: 'tags',
Expand Down

0 comments on commit 7c27e24

Please sign in to comment.