function formatDataToArray (data) {
                    var newdata = [];
                    data.forEach(function (item) {
                        // create rows:
                        var row = [];

                        try {
                            // var db = item.sourceID;

                            // col 0: data origin: public / private
                            row.push((item.access_level === otConsts.ACCESS_LEVEL_PUBLIC) ? otConsts.ACCESS_LEVEL_PUBLIC_DIR : otConsts.ACCESS_LEVEL_PRIVATE_DIR);

                            // 1: disease name
                            row.push('<a href="/disease/' + item.disease.id + '">' + item.disease.efo_info.label + '</a>');

                            // 2: reported trait
                            row.push(
                                item.sourceID === otConsts.datasources.OT_GENETICS.id ? (
                                    '<a class=\'ot-external-link\' href=\'' + item.evidence.variant2disease.study_link + '\' target=\'_blank\'>' + item.disease.reported_trait + '</a>'
                                ) : (
                                    otDictionary.NA
                                )
                            );

                            // 3: publications
                            // since there is only 1 or no publications, here we show it as "author(year)"
                            // which is consistent with the genetics portal
                            var refs = [];
                            if (checkPath(item, 'evidence.variant2disease.provenance_type.literature.references')) {
                                refs = item.evidence.variant2disease.provenance_type.literature.references;
                            }
                            var pmidsList = otUtils.getPmidsList(refs);
                            var pubInfo = otDictionary.NA;
                            if (refs.length && refs[0].author) {
                                pubInfo = '<a class=\'ot-external-link\' href=\'' + refs[0].lit_id + '\' target=\'_blank\'>' + refs[0].author + ' (' + refs[0].year + ')</a>';
                            } else if (refs.length) {
                                pubInfo = otUtils.getPublicationsString(pmidsList);
                            }
                            row.push(pubInfo);

                            // 4: Publication ids (hidden)
                            row.push(pmidsList.join(', '));

                            // 5: Variant
                            var variants = '';
                            var variantId = '';
                            if (item.sourceID === otConsts.datasources.OT_GENETICS.id) {
                                variantId = (item.variant.rs_id || item.variant.id);
                                variants = '<a class=\'ot-external-link\' href=\'' + item.variant.source_link + '\' target=\'_blank\'>' + variantId + '</a>';
                            } else if (item.sourceID === otConsts.datasources.PHEWAS.id) {
                                variantId = item.variant.rs_id;
                                variants = '<a class=\'ot-external-link\' href=\'http://www.ensembl.org/Homo_sapiens/Variation/Explore?v=' + variantId + '\' target=\'_blank\'>' + variantId + '</a>'; 
                            } 
                            else {
                                variantId = item.variant.id.split('/').pop();
                                variants = '<a class=\'ot-external-link\' href=\'http://www.ensembl.org/Homo_sapiens/Variation/Explore?v=' + variantId + '\' target=\'_blank\'>' + variantId + '</a>';
                            }
                            row.push(variants);

                            // 6: variant type
                            var t = otClearUnderscoresFilter(otUtils.getEcoLabel(item.evidence.evidence_codes_info, item.evidence.gene2variant.functional_consequence.split('/').pop()));
                            row.push(t);

                            // 7: p-value
                            // Note that occasionally the pvalue might be stored as a String (in the response JSON) which triggers an error
                            // so we cast it to a number to be safe
                            row.push(
                                (item.evidence.variant2disease.resource_score.mantissa && item.evidence.variant2disease.resource_score.exponent) ?
                                    item.evidence.variant2disease.resource_score.mantissa + 'e' + item.evidence.variant2disease.resource_score.exponent
                                    :
                                    '' + item.evidence.variant2disease.resource_score.value
                            );

                            // 8: Gene prioritisation
                            row.push(item.sourceID === otConsts.datasources.OT_GENETICS.id ? (item.evidence.gene2variant.resource_score.value).toFixed(5) : -1);

                            // 9: evidence source
                            if (item.sourceID === otConsts.datasources.PHEWAS_23andme.id) {
                                row.push('<a class=\'ot-external-link\' href=\'https://test-rvizapps.biogen.com/23andmeDev/\' target=\'_blank\'>'
                                    + otClearUnderscoresFilter(item.sourceID)
                                    + '</a>');
                            } else if (item.sourceID === otConsts.datasources.PHEWAS.id) {
                                row.push('<a class=\'ot-external-link\' href=\'https://phewascatalog.org/phewas\' target=\'_blank\'>'
                                    + otClearUnderscoresFilter(item.sourceID)
                                    + '</a>');
                            } else if (item.sourceID === otConsts.datasources.OT_GENETICS.id) {
                                row.push('<a class=\'ot-external-link\' href=\'https://genetics.opentargets.org/study-locus/' 
                                    + item.evidence.variant2disease.study_link.split('/').pop() + '/'
                                    + item.variant.id + '\' target=\'_blank\'>'
                                    + otConsts.datasources.OT_GENETICS.label
                                    + '</a>');
                            } else {
                                row.push('<a class=\'ot-external-link\' href=\'https://www.ebi.ac.uk/gwas/search?query=' + item.variant.id.split('/').pop() + '\' target=\'_blank\'>'
                                    + otClearUnderscoresFilter(item.sourceID)
                                    + '</a>');
                            }

                            // 10-14: hidden columns for filtering and custom sorting
                            row.push(variantId); // variant
                            row.push(otClearUnderscoresFilter(item.sourceID)); // evidence source
                            row.push(item.disease.efo_info.label);
                            row.push(item.sourceID === otConsts.datasources.OT_GENETICS.id ? item.evidence.gene2variant.resource_score.value : -1); // gene prioritisation score
                            row.push(item.sourceID === otConsts.datasources.OT_GENETICS.id ? item.disease.reported_trait : otDictionary.NA);    // reported trait

                            newdata.push(row); // push, so we don't end up with empty rows
                        } catch (e) {
                            scope.ext.hasError = true;
                            $log.error('Error parsing common disease data:');
                            $log.error(e);
                        }
                    });
                    return newdata;
                }
/*
                 * Takes the data object returned by the API and formats it
                 * to an array of arrays to be displayed by the dataTable widget.
                 */
Takes the data object returned by the API and formats it
to an array of arrays to be displayed by the dataTable widget.
Takes the data object returned by the API and formats it to an array of arrays to be displayed by the dataTable widget .
function formatDataToArray (data) {
                    var newdata = [];
                    data.forEach(function (item) {
                        var row = [];
                        try {
                            row.push((item.access_level === otConsts.ACCESS_LEVEL_PUBLIC) ? otConsts.ACCESS_LEVEL_PUBLIC_DIR : otConsts.ACCESS_LEVEL_PRIVATE_DIR);
                            row.push('<a href="/disease/' + item.disease.id + '">' + item.disease.efo_info.label + '</a>');
                            row.push(
                                item.sourceID === otConsts.datasources.OT_GENETICS.id ? (
                                    '<a class=\'ot-external-link\' href=\'' + item.evidence.variant2disease.study_link + '\' target=\'_blank\'>' + item.disease.reported_trait + '</a>'
                                ) : (
                                    otDictionary.NA
                                )
                            );
                            var refs = [];
                            if (checkPath(item, 'evidence.variant2disease.provenance_type.literature.references')) {
                                refs = item.evidence.variant2disease.provenance_type.literature.references;
                            }
                            var pmidsList = otUtils.getPmidsList(refs);
                            var pubInfo = otDictionary.NA;
                            if (refs.length && refs[0].author) {
                                pubInfo = '<a class=\'ot-external-link\' href=\'' + refs[0].lit_id + '\' target=\'_blank\'>' + refs[0].author + ' (' + refs[0].year + ')</a>';
                            } else if (refs.length) {
                                pubInfo = otUtils.getPublicationsString(pmidsList);
                            }
                            row.push(pubInfo);
                            row.push(pmidsList.join(', '));
                            var variants = '';
                            var variantId = '';
                            if (item.sourceID === otConsts.datasources.OT_GENETICS.id) {
                                variantId = (item.variant.rs_id || item.variant.id);
                                variants = '<a class=\'ot-external-link\' href=\'' + item.variant.source_link + '\' target=\'_blank\'>' + variantId + '</a>';
                            } else if (item.sourceID === otConsts.datasources.PHEWAS.id) {
                                variantId = item.variant.rs_id;
                                variants = '<a class=\'ot-external-link\' href=\'http://www.ensembl.org/Homo_sapiens/Variation/Explore?v=' + variantId + '\' target=\'_blank\'>' + variantId + '</a>'; 
                            } 
                            else {
                                variantId = item.variant.id.split('/').pop();
                                variants = '<a class=\'ot-external-link\' href=\'http://www.ensembl.org/Homo_sapiens/Variation/Explore?v=' + variantId + '\' target=\'_blank\'>' + variantId + '</a>';
                            }
                            row.push(variants);
                            var t = otClearUnderscoresFilter(otUtils.getEcoLabel(item.evidence.evidence_codes_info, item.evidence.gene2variant.functional_consequence.split('/').pop()));
                            row.push(t);
                            row.push(
                                (item.evidence.variant2disease.resource_score.mantissa && item.evidence.variant2disease.resource_score.exponent) ?
                                    item.evidence.variant2disease.resource_score.mantissa + 'e' + item.evidence.variant2disease.resource_score.exponent
                                    :
                                    '' + item.evidence.variant2disease.resource_score.value
                            );
                            row.push(item.sourceID === otConsts.datasources.OT_GENETICS.id ? (item.evidence.gene2variant.resource_score.value).toFixed(5) : -1);
                            if (item.sourceID === otConsts.datasources.PHEWAS_23andme.id) {
                                row.push('<a class=\'ot-external-link\' href=\'https://test-rvizapps.biogen.com/23andmeDev/\' target=\'_blank\'>'
                                    + otClearUnderscoresFilter(item.sourceID)
                                    + '</a>');
                            } else if (item.sourceID === otConsts.datasources.PHEWAS.id) {
                                row.push('<a class=\'ot-external-link\' href=\'https://phewascatalog.org/phewas\' target=\'_blank\'>'
                                    + otClearUnderscoresFilter(item.sourceID)
                                    + '</a>');
                            } else if (item.sourceID === otConsts.datasources.OT_GENETICS.id) {
                                row.push('<a class=\'ot-external-link\' href=\'https://genetics.opentargets.org/study-locus/' 
                                    + item.evidence.variant2disease.study_link.split('/').pop() + '/'
                                    + item.variant.id + '\' target=\'_blank\'>'
                                    + otConsts.datasources.OT_GENETICS.label
                                    + '</a>');
                            } else {
                                row.push('<a class=\'ot-external-link\' href=\'https://www.ebi.ac.uk/gwas/search?query=' + item.variant.id.split('/').pop() + '\' target=\'_blank\'>'
                                    + otClearUnderscoresFilter(item.sourceID)
                                    + '</a>');
                            }
                            row.push(variantId); 
                            row.push(otClearUnderscoresFilter(item.sourceID)); 
                            row.push(item.disease.efo_info.label);
                            row.push(item.sourceID === otConsts.datasources.OT_GENETICS.id ? item.evidence.gene2variant.resource_score.value : -1); 
                            row.push(item.sourceID === otConsts.datasources.OT_GENETICS.id ? item.disease.reported_trait : otDictionary.NA);    
                            newdata.push(row); 
                        } catch (e) {
                            scope.ext.hasError = true;
                            $log.error('Error parsing common disease data:');
                            $log.error(e);
                        }
                    });
                    return newdata;
                }
function formatDataToArray ( data ) { var newdata = [ ] ; data . forEach ( function ( item ) { var row = [ ] ; try { row . push ( ( item . access_level === otConsts . ACCESS_LEVEL_PUBLIC ) ? otConsts . ACCESS_LEVEL_PUBLIC_DIR : otConsts . ACCESS_LEVEL_PRIVATE_DIR ) ; row . push ( '<a href="/disease/' + item . disease . id + '">' + item . disease . efo_info . label + '</a>' ) ; row . push ( item . sourceID === otConsts . datasources . OT_GENETICS . id ? ( '<a class=\'ot-external-link\' href=\'' + item . evidence . variant2disease . study_link + '\' target=\'_blank\'>' + item . disease . reported_trait + '</a>' ) : ( otDictionary . NA ) ) ; var refs = [ ] ; if ( checkPath ( item , 'evidence.variant2disease.provenance_type.literature.references' ) ) { refs = item . evidence . variant2disease . provenance_type . literature . references ; } var pmidsList = otUtils . getPmidsList ( refs ) ; var pubInfo = otDictionary . NA ; if ( refs . length && refs [ 0 ] . author ) { pubInfo = '<a class=\'ot-external-link\' href=\'' + refs [ 0 ] . lit_id + '\' target=\'_blank\'>' + refs [ 0 ] . author + ' (' + refs [ 0 ] . year + ')</a>' ; } else if ( refs . length ) { pubInfo = otUtils . getPublicationsString ( pmidsList ) ; } row . push ( pubInfo ) ; row . push ( pmidsList . join ( ', ' ) ) ; var variants = '' ; var variantId = '' ; if ( item . sourceID === otConsts . datasources . OT_GENETICS . id ) { variantId = ( item . variant . rs_id || item . variant . id ) ; variants = '<a class=\'ot-external-link\' href=\'' + item . variant . source_link + '\' target=\'_blank\'>' + variantId + '</a>' ; } else if ( item . sourceID === otConsts . datasources . PHEWAS . id ) { variantId = item . variant . rs_id ; variants = '<a class=\'ot-external-link\' href=\'http://www.ensembl.org/Homo_sapiens/Variation/Explore?v=' + variantId + '\' target=\'_blank\'>' + variantId + '</a>' ; } else { variantId = item . variant . id . split ( '/' ) . pop ( ) ; variants = '<a class=\'ot-external-link\' href=\'http://www.ensembl.org/Homo_sapiens/Variation/Explore?v=' + variantId + '\' target=\'_blank\'>' + variantId + '</a>' ; } row . push ( variants ) ; var t = otClearUnderscoresFilter ( otUtils . getEcoLabel ( item . evidence . evidence_codes_info , item . evidence . gene2variant . functional_consequence . split ( '/' ) . pop ( ) ) ) ; row . push ( t ) ; row . push ( ( item . evidence . variant2disease . resource_score . mantissa && item . evidence . variant2disease . resource_score . exponent ) ? item . evidence . variant2disease . resource_score . mantissa + 'e' + item . evidence . variant2disease . resource_score . exponent : '' + item . evidence . variant2disease . resource_score . value ) ; row . push ( item . sourceID === otConsts . datasources . OT_GENETICS . id ? ( item . evidence . gene2variant . resource_score . value ) . toFixed ( 5 ) : - 1 ) ; if ( item . sourceID === otConsts . datasources . PHEWAS_23andme . id ) { row . push ( '<a class=\'ot-external-link\' href=\'https://test-rvizapps.biogen.com/23andmeDev/\' target=\'_blank\'>' + otClearUnderscoresFilter ( item . sourceID ) + '</a>' ) ; } else if ( item . sourceID === otConsts . datasources . PHEWAS . id ) { row . push ( '<a class=\'ot-external-link\' href=\'https://phewascatalog.org/phewas\' target=\'_blank\'>' + otClearUnderscoresFilter ( item . sourceID ) + '</a>' ) ; } else if ( item . sourceID === otConsts . datasources . OT_GENETICS . id ) { row . push ( '<a class=\'ot-external-link\' href=\'https://genetics.opentargets.org/study-locus/' + item . evidence . variant2disease . study_link . split ( '/' ) . pop ( ) + '/' + item . variant . id + '\' target=\'_blank\'>' + otConsts . datasources . OT_GENETICS . label + '</a>' ) ; } else { row . push ( '<a class=\'ot-external-link\' href=\'https://www.ebi.ac.uk/gwas/search?query=' + item . variant . id . split ( '/' ) . pop ( ) + '\' target=\'_blank\'>' + otClearUnderscoresFilter ( item . sourceID ) + '</a>' ) ; } row . push ( variantId ) ; row . push ( otClearUnderscoresFilter ( item . sourceID ) ) ; row . push ( item . disease . efo_info . label ) ; row . push ( item . sourceID === otConsts . datasources . OT_GENETICS . id ? item . evidence . gene2variant . resource_score . value : - 1 ) ; row . push ( item . sourceID === otConsts . datasources . OT_GENETICS . id ? item . disease . reported_trait : otDictionary . NA ) ; newdata . push ( row ) ; } catch ( e ) { scope . ext . hasError = true ; $log . error ( 'Error parsing common disease data:' ) ; $log . error ( e ) ; } } ) ; return newdata ; }
Takes the data object returned by the API and formats it
 to an array of arrays to be displayed by the dataTable widget.
Takes the data object returned by the API and formats it to an array of arrays to be displayed by the dataTable widget .
// create rows: // var db = item.sourceID; // col 0: data origin: public / private // 1: disease name // 2: reported trait // 3: publications // since there is only 1 or no publications, here we show it as "author(year)" // which is consistent with the genetics portal // 4: Publication ids (hidden) // 5: Variant // 6: variant type // 7: p-value // Note that occasionally the pvalue might be stored as a String (in the response JSON) which triggers an error // so we cast it to a number to be safe // 8: Gene prioritisation // 9: evidence source // 10-14: hidden columns for filtering and custom sorting // variant // evidence source // gene prioritisation score // reported trait // push, so we don't end up with empty rows