Ejemplo n.º 1
0
def _create_or_update_pending_sampleSetItem(
        request, user, sampleSet_ids, sample, sampleGender,
        sampleRelationshipRole, sampleRelationshipGroup, sampleControlType,
        selectedBarcodeKit, selectedBarcode, sampleCancerType,
        sampleCellularityPct, sampleNucleotideType, pcrPlateRow,
        sampleBiopsyDays, sampleCellNum, sampleCoupleId, sampleEmbryoId,
        sampleSetItemDescription):

    if selectedBarcode:
        dnabarcode = models.dnaBarcode.objects.get(name=selectedBarcodeKit,
                                                   id_str=selectedBarcode)
    else:
        dnabarcode = None

    if sampleNucleotideType.lower() == "fusions":
        sampleNucleotideType = "rna"

    for sampleSet_id in sampleSet_ids:
        sampleSet = get_object_or_404(SampleSet, pk=sampleSet_id)
        relationshipGroup = int(
            sampleRelationshipGroup) if sampleRelationshipGroup else 0
        pcrPlateColumn = "1" if pcrPlateRow else ""

        sampleSetItem_kwargs = {
            'gender': sampleGender,
            'relationshipRole': sampleRelationshipRole,
            'relationshipGroup': relationshipGroup,
            'controlType': sampleControlType,
            'cancerType': sampleCancerType,
            'cellularityPct': sampleCellularityPct,
            'dnabarcode': dnabarcode,
            'pcrPlateRow': pcrPlateRow,
            'pcrPlateColumn': pcrPlateColumn,
            'biopsyDays': sampleBiopsyDays,
            'cellNum': sampleCellNum,
            'coupleId': sampleCoupleId,
            'embryoId': sampleEmbryoId,
            'description': sampleSetItemDescription,
            'lastModifiedUser': user,
        }
        try:
            sampleSetItem = SampleSetItem.objects.get(
                sample=sample,
                sampleSet_id=sampleSet_id,
                nucleotideType=sampleNucleotideType,
                dnabarcode=dnabarcode)
        except:
            sampleSetItem = SampleSetItem(sample=sample,
                                          sampleSet_id=sampleSet_id,
                                          nucleotideType=sampleNucleotideType,
                                          creator=user)

        for field, value in sampleSetItem_kwargs.iteritems():
            setattr(sampleSetItem, field, value)
        sampleSetItem.save()
Ejemplo n.º 2
0
def _get_nucleotideType_choices(request):
    nucleotideType_tuple = SampleSetItem.get_nucleotideType_choices()        
    nucleotideType_choices = OrderedDict()
    for i, (internalValue, displayedValue) in enumerate(nucleotideType_tuple):
        nucleotideType_choices[internalValue] = displayedValue

    return nucleotideType_choices
Ejemplo n.º 3
0
def _get_pcrPlateCol_valid_values(request):
    col_choices_tuple = SampleSetItem.get_ampliseq_plate_v1_column_choices()
    col_values = []
    for i, (internalValue, displayedValue) in enumerate(col_choices_tuple):
        col_values.append(displayedValue)

    return col_values
Ejemplo n.º 4
0
def _get_pcrPlateRow_valid_values(request):
    row_choices_tuple = SampleSetItem.get_ampliseq_plate_v1_row_choices()
    row_values = []
    for i, (internalValue, displayedValue) in enumerate(row_choices_tuple):
        row_values.append(displayedValue)

    return row_values
Ejemplo n.º 5
0
def _get_pcrPlateRow_choices(request):
    row_choices_tuple = SampleSetItem.get_ampliseq_plate_v1_row_choices()
    row_choices = OrderedDict()
    for i, (internalValue, displayedValue) in enumerate(row_choices_tuple):
        row_choices[internalValue] = displayedValue

    return row_choices
Ejemplo n.º 6
0
def _get_pcrPlateCol_valid_values(request):
    col_choices_tuple = SampleSetItem.get_ampliseq_plate_v1_column_choices()
    col_values = []
    for i, (internalValue, displayedValue) in enumerate(col_choices_tuple):
        col_values.append(displayedValue)

    return col_values
Ejemplo n.º 7
0
def _get_pcrPlateRow_valid_values(request):
    row_choices_tuple = SampleSetItem.get_ampliseq_plate_v1_row_choices()
    row_values = []
    for i, (internalValue, displayedValue) in enumerate(row_choices_tuple):
        row_values.append(displayedValue)

    return row_values
Ejemplo n.º 8
0
def _get_pcrPlateRow_choices(request):
    row_choices_tuple = SampleSetItem.get_ampliseq_plate_v1_row_choices()
    row_choices = OrderedDict()
    for i, (internalValue, displayedValue) in enumerate(row_choices_tuple):
        row_choices[internalValue] = displayedValue

    return row_choices
Ejemplo n.º 9
0
def _get_nucleotideType_choices(request):
    nucleotideType_tuple = SampleSetItem.get_nucleotideType_choices()
    nucleotideType_choices = OrderedDict()
    for i, (internalValue, displayedValue) in enumerate(nucleotideType_tuple):
        nucleotideType_choices[internalValue] = displayedValue

    return nucleotideType_choices
Ejemplo n.º 10
0
def _create_or_update_pending_sampleSetItem(request, user, sampleSet_ids, sample, sampleGender, sampleRelationshipRole, sampleRelationshipGroup, sampleControlType,
        selectedBarcodeKit, selectedBarcode, sampleCancerType, sampleCellularityPct, sampleNucleotideType,
        pcrPlateRow, sampleBiopsyDays, sampleCellNum, sampleCoupleId, sampleEmbryoId, sampleSetItemDescription):

    if selectedBarcode:
        dnabarcode = models.dnaBarcode.objects.get(name=selectedBarcodeKit, id_str=selectedBarcode)
    else:
        dnabarcode = None

    if sampleNucleotideType.lower() == "fusions":
        sampleNucleotideType = "rna"

    for sampleSet_id in sampleSet_ids:
        sampleSet = get_object_or_404(SampleSet, pk=sampleSet_id)
        relationshipGroup = int(sampleRelationshipGroup) if sampleRelationshipGroup else 0
        pcrPlateColumn = "1" if pcrPlateRow else ""

        sampleSetItem_kwargs = {
            'gender': sampleGender,
            'relationshipRole': sampleRelationshipRole,
            'relationshipGroup': relationshipGroup,
            'controlType': sampleControlType,
            'cancerType': sampleCancerType,
            'cellularityPct': sampleCellularityPct,
            'dnabarcode': dnabarcode,
            'pcrPlateRow': pcrPlateRow,
            'pcrPlateColumn': pcrPlateColumn,
            'biopsyDays': sampleBiopsyDays,
            'cellNum': sampleCellNum,
            'coupleId': sampleCoupleId,
            'embryoId': sampleEmbryoId,
            'description': sampleSetItemDescription,
            'lastModifiedUser': user,
        }
        try:
            sampleSetItem = SampleSetItem.objects.get(sample=sample, sampleSet_id=sampleSet_id, nucleotideType=sampleNucleotideType, dnabarcode=dnabarcode)
        except:
            sampleSetItem = SampleSetItem(sample=sample, sampleSet_id=sampleSet_id, nucleotideType=sampleNucleotideType, creator=user)

        for field, value in sampleSetItem_kwargs.iteritems():
            setattr(sampleSetItem, field, value)
        sampleSetItem.save()
Ejemplo n.º 11
0
def _get_nucleotideType_choices(sampleGroupType=""):
    nucleotideType_choices = []
    for internalValue, displayedValue in SampleSetItem.get_nucleotideType_choices():
        if internalValue == "rna" and "fusions" in sampleGroupType.lower():
            continue
        else:
            nucleotideType_choices.append((internalValue, displayedValue))

    if "fusions" in sampleGroupType.lower() or not sampleGroupType:
        nucleotideType_choices.append(('fusions', 'Fusions'))

    return nucleotideType_choices
Ejemplo n.º 12
0
def _get_nucleotideType_choices(sampleGroupType=""):
    nucleotideType_choices = []
    for internalValue, displayedValue in SampleSetItem.get_nucleotideType_choices():
        if internalValue == "rna" and "fusions" in sampleGroupType.lower():
            continue
        else:
            nucleotideType_choices.append((internalValue, displayedValue))

    if "fusions" in sampleGroupType.lower() or not sampleGroupType:
        nucleotideType_choices.append(("fusions", "Fusions"))

    return nucleotideType_choices
Ejemplo n.º 13
0
def _create_or_update_sampleSetItem(
    queryDict, user, item_id=None, sampleSet_id=None, sample=None
):
    # use case 1: if item_id is defined we are editing existing SampleSetItem
    # use case 2: if sampleSet_id is defined we are editing or adding a new SampleSetItem

    sampleSetItem_kwargs = _get_sampleSetItem_kwargs(queryDict, sampleSet_id)
    if item_id:
        sampleSetItem = get_object_or_404(SampleSetItem, pk=item_id)

    elif sampleSet_id:
        sampleSet = get_object_or_404(SampleSet, pk=sampleSet_id)
        try:
            sampleSetItem = SampleSetItem.objects.get(
                sample=sample,
                sampleSet_id=sampleSet_id,
                nucleotideType=sampleSetItem_kwargs["nucleotideType"],
                dnabarcode=sampleSetItem_kwargs["dnaBarcode"],
            )
        except Exception:
            sampleSetItem = SampleSetItem(
                sample=sample,
                sampleSet_id=sampleSet_id,
                nucleotideType=sampleSetItem_kwargs["nucleotideType"],
                creator=user,
            )
    else:
        raise Exception(
            "Unable to update sample: missing SampleSetItem id or SampleSet id"
        )

    for field, value in sampleSetItem_kwargs.items():
        setattr(sampleSetItem, field, value)

    logger.debug(
        "views_helper._create_or_update_sampleSetItem sampleSetItem_kwargs=%s"
        % (sampleSetItem_kwargs)
    )
    sampleSetItem.save()