function populate_userinput_from_response(data){
    var columns = data["sampleRelationshipsTableInfo"]["columns"];
    var column_map = data["sampleRelationshipsTableInfo"]["column-map"];
    var restrictions = data["sampleRelationshipsTableInfo"]["restrictionRules"];
    //sorts the columns by the Order key
    columns.sort(function(columnA, columnB){
        return columnA.Order - columnB.Order;
    });
    // parse restriction rules
    var relation_to_relationshipType = {};
    var gender_to_relation = {};
    var relationshipType_to_relations = {};
    $.each(restrictions, function(i, restriction){
        if (typeof restriction["For"] != 'undefined') {
            if (restriction["For"]["Name"] == 'RelationshipType') {
                $.each(restriction["Valid"]["Values"], function(i, value){
                    relation_to_relationshipType[value] = relation_to_relationshipType[value] || [];
                    relation_to_relationshipType[value].push(restriction["For"]["Value"]);
                });
                if (!('AndFor' in restriction)){
                    relationshipType_to_relations[restriction["For"]["Value"]] = restriction["Valid"]["Values"];
                }
            } else if (restriction["For"]["Name"] == 'Relation') {
                $.each(restriction["Valid"]["Values"], function(i, value){
                    gender_to_relation[value] = gender_to_relation[value] || [];
                    gender_to_relation[value].push(restriction["For"]["Value"]);
                });
                // also save which relations have associated Gender
                USERINPUT.relations_with_gender[restriction["For"]["Value"]] = restriction["Valid"]["Values"];
            }
        }
    });
    // Workflow
    $.each(column_map, function(i, cm){
        var workflow = cm["Workflow"];
        var irReference = cm["irReference"] || "";
        // reference name conversion: TS "GRCh38.p2.mask1" = IR "GRCh38"
        var reference = (irReference == "GRCh38") ? "GRCh38.p2.mask1" : irReference
        var relationshipType = cm["RelationshipType"];
        var nucleotideType = cm["DNA_RNA_Workflow"] || "";
        var tagImmuneRepertoire = cm["tag_IMMUNE_REPERTOIRE_SHORT_ASSAY"] || "";
        var tagDNA = cm["tag_DNA"] || "";
        var tagRNA = cm["tag_RNA"] || "";
        var DNA_RNA = (tagImmuneRepertoire.toLowerCase() == "true" && tagDNA.toLowerCase() == "true") ? "DNA" : nucleotideType;
        DNA_RNA = (tagImmuneRepertoire.toLowerCase() == "true" && tagRNA.toLowerCase() == "true") ? "RNA" : DNA_RNA;
        nucleotideType = DNA_RNA;
        USERINPUT.workflows.push({
            "Workflow": workflow != "Upload Only" ? workflow : "",
            "display": get_decorated_workflow_name(cm, workflow, irReference, ION_PRELOADED_LABEL, SEPARATOR),
            "tag_isFactoryProvidedWorkflow": cm["tag_isFactoryProvidedWorkflow"],
            "ApplicationType": cm["ApplicationType"],
            "RelationshipType": relationshipType,
            "Reference": reference,
            "nucleotideType": (nucleotideType=="DNA" || nucleotideType=="RNA") ? nucleotideType : "",
            "relations_list": relationshipType_to_relations[relationshipType] || []
        });
    });
    // Relation and Gender
    $.each(columns, function(i, column){
        if (column["Name"] == "Relation"){
            USERINPUT.relations = $.map(column["Values"], function(value, key){
                var relationshipType = relation_to_relationshipType[value] || [];
                return {
                    "Relation": value,
                    "display": value,
                    "RelationshipType": relationshipType.toString()
                };
            });
        }
        if (column["Name"] == "Gender"){
            USERINPUT.genders = $.map(column["Values"], function(value, key){
                var relation =  gender_to_relation[value] || [];
                return {
                    "Gender": value,
                    "display": value,
                    "Relation": relation.toString()
                };
            });
        }
        if (column["Name"] == "CancerType"){
            USERINPUT.cancerTypes = $.map(column["Values"], function(value, key){
                return {
                    "CancerType": value,
                    "display": value
                };
            });
        }
        if (column["Name"] == "Population"){
            USERINPUT.populations = $.map(column["Values"], function(value, key){
                return {
                    "Population": value,
                    "display": value
                };
            });
        }
        if (column["Name"] == "MouseStrains"){
            USERINPUT.mouseStrains = $.map(column["Values"], function(value, key){
                return {
                    "MouseStrains": value,
                    "display": value
                };
            });
        }
    });
}
/**
 Parse data returned from IRU and save in USERINPUT
**/
Parse data returned from IRU and save in USERINPUT
Parse data returned from IRU and save in USERINPUT
function populate_userinput_from_response(data){
    var columns = data["sampleRelationshipsTableInfo"]["columns"];
    var column_map = data["sampleRelationshipsTableInfo"]["column-map"];
    var restrictions = data["sampleRelationshipsTableInfo"]["restrictionRules"];
    columns.sort(function(columnA, columnB){
        return columnA.Order - columnB.Order;
    });
    var relation_to_relationshipType = {};
    var gender_to_relation = {};
    var relationshipType_to_relations = {};
    $.each(restrictions, function(i, restriction){
        if (typeof restriction["For"] != 'undefined') {
            if (restriction["For"]["Name"] == 'RelationshipType') {
                $.each(restriction["Valid"]["Values"], function(i, value){
                    relation_to_relationshipType[value] = relation_to_relationshipType[value] || [];
                    relation_to_relationshipType[value].push(restriction["For"]["Value"]);
                });
                if (!('AndFor' in restriction)){
                    relationshipType_to_relations[restriction["For"]["Value"]] = restriction["Valid"]["Values"];
                }
            } else if (restriction["For"]["Name"] == 'Relation') {
                $.each(restriction["Valid"]["Values"], function(i, value){
                    gender_to_relation[value] = gender_to_relation[value] || [];
                    gender_to_relation[value].push(restriction["For"]["Value"]);
                });
                USERINPUT.relations_with_gender[restriction["For"]["Value"]] = restriction["Valid"]["Values"];
            }
        }
    });
    $.each(column_map, function(i, cm){
        var workflow = cm["Workflow"];
        var irReference = cm["irReference"] || "";
        var reference = (irReference == "GRCh38") ? "GRCh38.p2.mask1" : irReference
        var relationshipType = cm["RelationshipType"];
        var nucleotideType = cm["DNA_RNA_Workflow"] || "";
        var tagImmuneRepertoire = cm["tag_IMMUNE_REPERTOIRE_SHORT_ASSAY"] || "";
        var tagDNA = cm["tag_DNA"] || "";
        var tagRNA = cm["tag_RNA"] || "";
        var DNA_RNA = (tagImmuneRepertoire.toLowerCase() == "true" && tagDNA.toLowerCase() == "true") ? "DNA" : nucleotideType;
        DNA_RNA = (tagImmuneRepertoire.toLowerCase() == "true" && tagRNA.toLowerCase() == "true") ? "RNA" : DNA_RNA;
        nucleotideType = DNA_RNA;
        USERINPUT.workflows.push({
            "Workflow": workflow != "Upload Only" ? workflow : "",
            "display": get_decorated_workflow_name(cm, workflow, irReference, ION_PRELOADED_LABEL, SEPARATOR),
            "tag_isFactoryProvidedWorkflow": cm["tag_isFactoryProvidedWorkflow"],
            "ApplicationType": cm["ApplicationType"],
            "RelationshipType": relationshipType,
            "Reference": reference,
            "nucleotideType": (nucleotideType=="DNA" || nucleotideType=="RNA") ? nucleotideType : "",
            "relations_list": relationshipType_to_relations[relationshipType] || []
        });
    });
    $.each(columns, function(i, column){
        if (column["Name"] == "Relation"){
            USERINPUT.relations = $.map(column["Values"], function(value, key){
                var relationshipType = relation_to_relationshipType[value] || [];
                return {
                    "Relation": value,
                    "display": value,
                    "RelationshipType": relationshipType.toString()
                };
            });
        }
        if (column["Name"] == "Gender"){
            USERINPUT.genders = $.map(column["Values"], function(value, key){
                var relation =  gender_to_relation[value] || [];
                return {
                    "Gender": value,
                    "display": value,
                    "Relation": relation.toString()
                };
            });
        }
        if (column["Name"] == "CancerType"){
            USERINPUT.cancerTypes = $.map(column["Values"], function(value, key){
                return {
                    "CancerType": value,
                    "display": value
                };
            });
        }
        if (column["Name"] == "Population"){
            USERINPUT.populations = $.map(column["Values"], function(value, key){
                return {
                    "Population": value,
                    "display": value
                };
            });
        }
        if (column["Name"] == "MouseStrains"){
            USERINPUT.mouseStrains = $.map(column["Values"], function(value, key){
                return {
                    "MouseStrains": value,
                    "display": value
                };
            });
        }
    });
}
function populate_userinput_from_response ( data ) { var columns = data [ "sampleRelationshipsTableInfo" ] [ "columns" ] ; var column_map = data [ "sampleRelationshipsTableInfo" ] [ "column-map" ] ; var restrictions = data [ "sampleRelationshipsTableInfo" ] [ "restrictionRules" ] ; columns . sort ( function ( columnA , columnB ) { return columnA . Order - columnB . Order ; } ) ; var relation_to_relationshipType = { } ; var gender_to_relation = { } ; var relationshipType_to_relations = { } ; $ . each ( restrictions , function ( i , restriction ) { if ( typeof restriction [ "For" ] != 'undefined' ) { if ( restriction [ "For" ] [ "Name" ] == 'RelationshipType' ) { $ . each ( restriction [ "Valid" ] [ "Values" ] , function ( i , value ) { relation_to_relationshipType [ value ] = relation_to_relationshipType [ value ] || [ ] ; relation_to_relationshipType [ value ] . push ( restriction [ "For" ] [ "Value" ] ) ; } ) ; if ( ! ( 'AndFor' in restriction ) ) { relationshipType_to_relations [ restriction [ "For" ] [ "Value" ] ] = restriction [ "Valid" ] [ "Values" ] ; } } else if ( restriction [ "For" ] [ "Name" ] == 'Relation' ) { $ . each ( restriction [ "Valid" ] [ "Values" ] , function ( i , value ) { gender_to_relation [ value ] = gender_to_relation [ value ] || [ ] ; gender_to_relation [ value ] . push ( restriction [ "For" ] [ "Value" ] ) ; } ) ; USERINPUT . relations_with_gender [ restriction [ "For" ] [ "Value" ] ] = restriction [ "Valid" ] [ "Values" ] ; } } } ) ; $ . each ( column_map , function ( i , cm ) { var workflow = cm [ "Workflow" ] ; var irReference = cm [ "irReference" ] || "" ; var reference = ( irReference == "GRCh38" ) ? "GRCh38.p2.mask1" : irReference var relationshipType = cm [ "RelationshipType" ] ; var nucleotideType = cm [ "DNA_RNA_Workflow" ] || "" ; var tagImmuneRepertoire = cm [ "tag_IMMUNE_REPERTOIRE_SHORT_ASSAY" ] || "" ; var tagDNA = cm [ "tag_DNA" ] || "" ; var tagRNA = cm [ "tag_RNA" ] || "" ; var DNA_RNA = ( tagImmuneRepertoire . toLowerCase ( ) == "true" && tagDNA . toLowerCase ( ) == "true" ) ? "DNA" : nucleotideType ; DNA_RNA = ( tagImmuneRepertoire . toLowerCase ( ) == "true" && tagRNA . toLowerCase ( ) == "true" ) ? "RNA" : DNA_RNA ; nucleotideType = DNA_RNA ; USERINPUT . workflows . push ( { "Workflow" : workflow != "Upload Only" ? workflow : "" , "display" : get_decorated_workflow_name ( cm , workflow , irReference , ION_PRELOADED_LABEL , SEPARATOR ) , "tag_isFactoryProvidedWorkflow" : cm [ "tag_isFactoryProvidedWorkflow" ] , "ApplicationType" : cm [ "ApplicationType" ] , "RelationshipType" : relationshipType , "Reference" : reference , "nucleotideType" : ( nucleotideType == "DNA" || nucleotideType == "RNA" ) ? nucleotideType : "" , "relations_list" : relationshipType_to_relations [ relationshipType ] || [ ] } ) ; } ) ; $ . each ( columns , function ( i , column ) { if ( column [ "Name" ] == "Relation" ) { USERINPUT . relations = $ . map ( column [ "Values" ] , function ( value , key ) { var relationshipType = relation_to_relationshipType [ value ] || [ ] ; return { "Relation" : value , "display" : value , "RelationshipType" : relationshipType . toString ( ) } ; } ) ; } if ( column [ "Name" ] == "Gender" ) { USERINPUT . genders = $ . map ( column [ "Values" ] , function ( value , key ) { var relation = gender_to_relation [ value ] || [ ] ; return { "Gender" : value , "display" : value , "Relation" : relation . toString ( ) } ; } ) ; } if ( column [ "Name" ] == "CancerType" ) { USERINPUT . cancerTypes = $ . map ( column [ "Values" ] , function ( value , key ) { return { "CancerType" : value , "display" : value } ; } ) ; } if ( column [ "Name" ] == "Population" ) { USERINPUT . populations = $ . map ( column [ "Values" ] , function ( value , key ) { return { "Population" : value , "display" : value } ; } ) ; } if ( column [ "Name" ] == "MouseStrains" ) { USERINPUT . mouseStrains = $ . map ( column [ "Values" ] , function ( value , key ) { return { "MouseStrains" : value , "display" : value } ; } ) ; } } ) ; }
Parse data returned from IRU and save in USERINPUT
Parse data returned from IRU and save in USERINPUT
//sorts the columns by the Order key // parse restriction rules // also save which relations have associated Gender // Workflow // reference name conversion: TS "GRCh38.p2.mask1" = IR "GRCh38" // Relation and Gender