# Code coverage report for lib/dataLoader.js

## Statements: 74.42% (32 / 43) Branches: 72.22% (13 / 18) Functions: 63.64% (7 / 11) Lines: 74.42% (32 / 43) Ignored: none

All files » lib/ » dataLoader.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98

    1
    1
    1

    1
    1

    1
    1
    12
    8
    304

    304
    304
    304

    1
    1

    1
    1
    1

    1
    1
    770

    1

    1
    134
    134
    134
    134
    133
    1
    1

    1

    1/*jslint node: true */
    /*jshint laxbreak: true */
    "use strict";

    var $ = require('jquery');
    var _ = require('underscore');
    var Evidence = require('./Evidence');

    var DataLoader = function() {
        return {
            get: function(proxy, uniprotID) {
                var url = 'www.ebi.ac.uk/uniprot/services/restful/features/';
                if(!proxy) {
                    url = 'https://' + url;
                }

                return $.ajax({
                    url: proxy + url + uniprotID,
                    //We need this dataType to set the Accept header correctly
                    dataType: "json"
                }).done(function(d) {
                    d.variants.features = DataLoader.processVariants(d);
                    return DataLoader.processData(d);
                }).fail(function(e){
                    return(e);
                });
            }, processData: function(d){
                var consecutive = 0;
                _.each(d, function(datum) {
                    if (datum && datum.features) {
                        _.each(datum.features, function(feature) {
                            Iif (feature.variants) {
                                _.each(feature.variants, function(variant) {
                                    variant.internalId = "ft_" + consecutive;
                                    variant.type.label = variant.type.label.replace('_', ' ');
                                    consecutive++;
                                });
                            } else {
                                feature.internalId = "ft_" + consecutive;
                                feature.type.label = feature.type.label.replace('_', ' ');
                                consecutive++;
                            }
                        });
                    }
                });
                d.totalFeatureCount = consecutive;
                return d;
            }, processVariants: function(d){
                var mutationArray = [];
                Eif(d.variants.features.length > 0) {
                    mutationArray.push({
                        'type': {
                            'name':'VARIANT',
                            'label':'Sequence Variant'
                        },
                        'normal':'-',
                        'pos': 0,
                        'variants':[]
                    });
                    var seq = d.sequence.split('');
                    _.each(seq, function(d,i){
                        mutationArray.push({
                            'type': {
                                'name':'VARIANT',
                                'label':'Sequence Variant'
                            },
                            'normal':seq[i],
                            'pos': i+1,
                            'variants':[]
                        });
                    });
                    mutationArray.push({
                        'type': {
                            'name':'VARIANT',
                            'label':'Sequence Variant'
                        },
                        'normal':'-',
                        'pos': seq.length+1,
                        'variants':[]
                    });

                    _.each(d.variants.features, function(d){
                        d.begin = +d.begin;
                        d.wildType = d.wildType ? d.wildType : mutationArray[d.begin].normal;
                        d.sourceType = d.sourceType.toLowerCase();
                        if ((1 <= d.begin) && (d.begin <= seq.length)) {
                            mutationArray[d.begin].variants.push(d);
                        } else Eif ((seq.length+1) === d.begin) {
                            mutationArray[d.begin - 1].variants.push(d);
                        }
                    });
                }
                return mutationArray;
            }
        };
    } ();

    module.exports = DataLoader;