Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/clinical options columns #52

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/api_service/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,13 @@ def get_number_samples_in_common_action(request):
@login_required
def get_number_samples_in_common_clinical_validation_source(request):
json_request_data = json.loads(request.body)
headers_in_front: Optional[List[str]] = json_request_data.get('headersColumnsNames')
clinical_data: Optional[List[str]] = json_request_data.get('clinicalData')
mrna_source_id = json_request_data.get('mRNASourceId')
mrna_source_type = json_request_data.get('mRNASourceType')

gem_source_id = json_request_data.get('gemSourceId')
gem_source_type = json_request_data.get('gemSourceType')
if None in [mrna_source_id, gem_source_id, mrna_source_type, gem_source_type, json_request_data, headers_in_front]:
if None in [mrna_source_id, gem_source_id, mrna_source_type, gem_source_type, json_request_data, clinical_data]:
response = {
'status': ResponseStatus(
ResponseCode.ERROR,
Expand Down Expand Up @@ -518,13 +518,13 @@ def get_number_samples_in_common_clinical_validation_source(request):
)
# Gets intersection
if response is None:
intersection = get_intersection_clinical(samples_list_mrna, samples_list_gem, headers_in_front)
intersection = get_intersection_clinical(samples_list_mrna, samples_list_gem, clinical_data)
response = {
'status': ResponseStatus(ResponseCode.SUCCESS),
'data': {
'number_samples_mrna': len(samples_list_mrna) if samples_list_mrna is not None else 0,
'number_samples_gem': len(samples_list_gem) if samples_list_gem is not None else 0,
'number_samples_clinical': len(headers_in_front) if headers_in_front is not None else 0,
'number_samples_clinical': len(clinical_data) if clinical_data is not None else 0,
'number_samples_in_common': intersection.size
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Base } from '../Base'
import { Grid, Header, Button, Modal, DropdownItemProps, Table, Icon } from 'semantic-ui-react'
import { DjangoTag, DjangoUserFile, TagType, DjangoInstitution, DjangoMethylationPlatform, DjangoResponseUploadUserFileError, DjangoUserFileUploadErrorInternalCode, DjangoSurvivalColumnsTupleSimple, RowHeader } from '../../utils/django_interfaces'
import ky from 'ky'
import { getDjangoHeader, alertGeneralError, getFileTypeSelectOptions, getDefaultNewTag, copyObject, formatDateLocale, getFileTypeName } from '../../utils/util_functions'
import { getDjangoHeader, alertGeneralError, getFileTypeSelectOptions, getDefaultNewTag, copyObject, formatDateLocale, getFileTypeName, getInputFileCSVColumns } from '../../utils/util_functions'
import { TagsPanel } from './TagsPanel'
import { FileType, Nullable } from '../../utils/interfaces'
import { NewFileForm } from './NewFileForm'
Expand Down Expand Up @@ -65,6 +65,8 @@ interface FilesManagerState {
addingTag: boolean,
uploadPercentage: number,
uploadState: Nullable<UploadState>
/** posibles values for survival tuple */
survivalTuplesPossiblesValues: string[],
}

/**
Expand Down Expand Up @@ -94,7 +96,8 @@ class FilesManager extends React.Component<{}, FilesManagerState> {
newFile: this.getDefaultNewFile(),
addingTag: false,
uploadPercentage: 0,
uploadState: null
uploadState: null,
survivalTuplesPossiblesValues: []
}
}

Expand All @@ -121,19 +124,18 @@ class FilesManager extends React.Component<{}, FilesManagerState> {
*/
fileChange = () => {
const newFileForm = this.state.newFile

// Get Filename if file was selected
const newFile = this.newFileInputRef.current
const newFileName = (newFile && newFile.files.length > 0) ? newFile.files[0].name : FILE_INPUT_LABEL

// If there wasn't a File name written by the user, loads the filename in the input
const newFileNameUser = (newFileForm.newFileNameUser.trim().length > 0) ? newFileForm.newFileNameUser : newFileName

// Sets the new field values
newFileForm.newFileName = newFileName
newFileForm.newFileNameUser = newFileNameUser

this.setState({ newFile: newFileForm })
getInputFileCSVColumns(newFile.files[0]).then((headersColumnsNames) => {
this.setState({ newFile: newFileForm, survivalTuplesPossiblesValues: headersColumnsNames })
})
}

/**
Expand Down Expand Up @@ -764,6 +766,7 @@ class FilesManager extends React.Component<{}, FilesManagerState> {
handleSurvivalFormDatasetChanges={this.handleSurvivalFormDatasetChanges}
addSurvivalFormTuple={this.addSurvivalFormTuple}
removeSurvivalFormTuple={this.removeSurvivalFormTuple}
survivalTuplesPossiblesValues={this.state.survivalTuplesPossiblesValues}
/>

<TagsPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ interface NewFileFormProps {
isEditing: boolean,
uploadState: Nullable<UploadState>
uploadFile: () => void,
fileChange: (e: any) => void,
fileChange: any, // (e: any) => void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sacar el comentario

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAJAJA, recuerdo poner ese any, para probar sin problemas. Ahi lo vuelvo como estaba antes, un (e:any)=> void. Porque recibe almenos un metodo que va a recibir el evento, no un cualquier cosa

handleAddFileInputsChange: (name: string, value: any) => void,
resetNewFileForm: () => void,
handleSurvivalFormDatasetChanges: (idx: number, name: string, value) => void,
addSurvivalFormTuple: () => void,
removeSurvivalFormTuple: (idx: number) => void
removeSurvivalFormTuple: (idx: number) => void,
survivalTuplesPossiblesValues: string[],
}

/**
Expand Down Expand Up @@ -297,6 +298,7 @@ export const NewFileForm = (props: NewFileFormProps) => {
addSurvivalFormTuple={props.addSurvivalFormTuple}
removeSurvivalFormTuple={props.removeSurvivalFormTuple}
disabled={props.uploadingFile}
survivalTuplesPossiblesValues={props.survivalTuplesPossiblesValues}
/>
}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import { Button, Grid, Icon, Label, Popup } from 'semantic-ui-react'
import { DjangoCGDSStudy, DjangoCommonResponse, DjangoExperiment, DjangoExperimentClinicalSource, DjangoExperimentSource, DjangoNumberSamplesInCommonClinicalValidationResult, DjangoResponseCode, DjangoSurvivalColumnsTupleSimple, DjangoUserFile, ExperimentState } from '../../../utils/django_interfaces'
import { CustomAlert, CustomAlertTypes, FileType, KySearchParams, Nullable, Source, SourceType } from '../../../utils/interfaces'
import { alertGeneralError, cleanRef, experimentSourceIsValid, getDefaultSource, getDjangoHeader, getFilenameFromSource, getFileSizeInMB, getInputFileCSVColumns, makeSourceAndAppend } from '../../../utils/util_functions'
import { alertGeneralError, cleanRef, experimentSourceIsValid, getDefaultSource, getDjangoHeader, getFilenameFromSource, getFileSizeInMB, getInputFileCSVColumns, getInputFileCSVFirstColumnAllRows, makeSourceAndAppend } from '../../../utils/util_functions'
import { SurvivalTuplesForm } from '../../survival/SurvivalTuplesForm'
import { SourceForm } from '../SourceForm'
import { BiomarkerState, InferenceExperimentForTable } from '../../biomarkers/types'
Expand Down Expand Up @@ -71,6 +71,8 @@ interface ClinicalSourceState {
cgdsStudyName: Nullable<string>,
/** alert interface */
alert: CustomAlert,
/** posibles values for survival tuple */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Por consistencia, arrancá los comentarios en mayúscula hdp!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vos sabes que nunca me di cuenta ajajaj. Dale ahora lo tomo para toda la documentacion que vaya a hacer. Gracias!

survivalTuplesPossiblesValues: string[],
}

/**
Expand All @@ -89,7 +91,8 @@ export class ClinicalSourcePopup extends React.Component<PopupClinicalSourceProp
gettingSourceData: false,
unlinkingSource: false,
cgdsStudyName: null,
alert: this.getDefaultAlertProps()
alert: this.getDefaultAlertProps(),
survivalTuplesPossiblesValues: []
}
}

Expand Down Expand Up @@ -168,32 +171,37 @@ export class ClinicalSourcePopup extends React.Component<PopupClinicalSourceProp

if (fileSizeInMB < MAX_FILE_SIZE_IN_MB_WARN) {
const file = clinicalSource.newUploadedFileRef.current.files[0]
getInputFileCSVColumns(file, undefined, FileType.CLINICAL).then((headersColumnsNames) => {
// Sets the Request's Headers
const myHeaders = getDjangoHeader()
// Sends an array of headers to compare in server
const jsonData = {
headersColumnsNames,
mRNASourceId,
mRNASourceType: SourceType.UPLOADED_DATASETS,
gemSourceId,
gemSourceType: SourceType.UPLOADED_DATASETS
}
getInputFileCSVFirstColumnAllRows(file, undefined).then((firstColumnAllRows) => {
getInputFileCSVColumns(file, undefined).then((headersColumnsNames) => {
// Sets the Request's Headers
const myHeaders = getDjangoHeader()
// Sends an array of headers to compare in server
const jsonData = {
clinicalData: firstColumnAllRows,
mRNASourceId,
mRNASourceType: SourceType.UPLOADED_DATASETS,
gemSourceId,
gemSourceType: SourceType.UPLOADED_DATASETS
}

ky.post(urlGetCommonSamplesClinicalSource, { json: jsonData, headers: myHeaders }).then((response) => {
response.json().then((jsonResponse: DjangoNumberSamplesInCommonClinicalValidationResult) => {
if (jsonResponse.status.code === DjangoResponseCode.SUCCESS) {
if (jsonResponse.data.number_samples_in_common > 0) {
this.setState({ clinicalSource })
} else {
this.clinicalSourceVoid()
ky.post(urlGetCommonSamplesClinicalSource, { json: jsonData, headers: myHeaders }).then((response) => {
response.json().then((jsonResponse: DjangoNumberSamplesInCommonClinicalValidationResult) => {
if (jsonResponse.status.code === DjangoResponseCode.SUCCESS) {
if (jsonResponse.data.number_samples_in_common > 0) {
this.setState({
clinicalSource,
survivalTuplesPossiblesValues: headersColumnsNames
})
} else {
this.clinicalSourceVoid()
}
}
}
}).catch((err) => {
console.log('Error parsing JSON ->', err)
})
}).catch((err) => {
console.log('Error parsing JSON ->', err)
console.log('Error getting user experiments', err)
Copy link
Member

@Genarito Genarito Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya que estamos, corregir el mensaje de error. Acá no está trayendo los experimentos del usuario

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dejar el comentario que editaste como estaba antes 'Error parsing JSON ->'. Ese estaba bien! Lo que está mal es el de abajo que dice "Error getting user experiments" cuando en realidad choca contra un endpoint que compara los Samples en común. Debería decir algo como "Error getting samples in common"

})
}).catch((err) => {
console.log('Error getting user experiments', err)
})
})
}
Expand Down Expand Up @@ -510,6 +518,7 @@ export class ClinicalSourcePopup extends React.Component<PopupClinicalSourceProp
} else {
clinicalIsDisabled = experiment.state !== BiomarkerState.COMPLETED
}

const survColumnsAreComplete = !this.validateSurvivalsColumnsComplete()
const iconExtraClassNames = this.props.iconExtraClassNames ?? ''
const clinicalButtonClassName = clinicalIsDisabled
Expand Down Expand Up @@ -584,6 +593,7 @@ export class ClinicalSourcePopup extends React.Component<PopupClinicalSourceProp
handleSurvivalFormDatasetChanges={this.handleSurvivalFormDatasetChanges}
addSurvivalFormTuple={this.addSurvivalFormTuple}
removeSurvivalFormTuple={this.removeSurvivalFormTuple}
survivalTuplesPossiblesValues={this.state.survivalTuplesPossiblesValues}
/>
</Grid.Column>
}
Expand Down
Loading
Loading