Skip to content

Commit

Permalink
no more array as input
Browse files Browse the repository at this point in the history
  • Loading branch information
nicgirault committed Mar 8, 2017
1 parent 04c8061 commit 824713f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 112 deletions.
26 changes: 13 additions & 13 deletions demo/chords/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ var drawCircos = function(error, GRCh37, cytobands, data) {
height: 1050,
});

console.log(GRCh37)


cytobands = cytobands.map(function(d) {
return {
block_id: d.chrom,
Expand All @@ -33,16 +30,19 @@ var drawCircos = function(error, GRCh37, cytobands, data) {
};
});

data = data.map(function(d){
return [
d.source_id,
parseInt(d.source_breakpoint) - 2000000,
parseInt(d.source_breakpoint) + 2000000,
d.target_id,
parseInt(d.target_breakpoint) - 2000000,
parseInt(d.target_breakpoint) + 2000000,
1
];
data = data.map(function(d) {
return {
source: {
id: d.source_id,
start: parseInt(d.source_breakpoint) - 2000000,
end: parseInt(d.source_breakpoint) + 2000000,
},
target: {
id: d.target_id,
start: parseInt(d.target_breakpoint) - 2000000,
end: parseInt(d.target_breakpoint) + 2000000,
},
};
});

circos
Expand Down
55 changes: 18 additions & 37 deletions dist/circos.js
Original file line number Diff line number Diff line change
Expand Up @@ -19963,18 +19963,10 @@ var Circos =
return { data: [], meta: { min: null, max: null } };
}

var preParsedData = normalize(data, ['parent_id', 'position', 'value']);

var filteredData = preParsedData.filter(function (datum, index) {
var filteredData = data.filter(function (datum, index) {
return checkParent(datum.block_id, index, layoutSummary, 'parent');
}).filter(function (datum, index) {
return checkNumber({ position: datum.position, value: datum.value }, index);
}).map(function (datum) {
return {
block_id: datum.block_id,
position: Math.min(layoutSummary[datum.block_id], parseFloat(datum.position)),
value: parseFloat(datum.value) || 1
};
});

return buildOutput(filteredData);
Expand All @@ -19986,8 +19978,7 @@ var Circos =
return { data: [], meta: { min: null, max: null } };
}

var preParsedData = normalize(data, ['parent_id', 'position', 'value']);
var filteredData = preParsedData.filter(function (datum, index) {
var filteredData = data.filter(function (datum, index) {
return checkParent(datum.block_id, index, layoutSummary, 'parent');
}).filter(function (datum, index) {
return checkNumber({ position: datum.position }, index);
Expand All @@ -19997,40 +19988,30 @@ var Circos =
}

function parseChordData(data, layoutSummary) {
// ['source_id', 'source_start', 'source_end', 'target_id', 'target_start', 'target_end', 'value']
console.log(data);
if (data.length === 0) {
return { data: [], meta: { min: null, max: null } };
}

var preParsedData = normalize(data, ['sourceId', 'sourceStart', 'sourceEnd', 'targetId', 'targetStart', 'targetEnd']);

var formatedData = preParsedData.filter(function (datum, index) {
return checkParent(datum[0], index, layoutSummary, 'sourceId');
var formatedData = data.filter(function (datum, index) {
if (datum.source) {
return checkParent(datum.source.id, index, layoutSummary, 'sourceId');
}
logger.warn('No source for data at index ' + index);
return false;
}).filter(function (datum, index) {
return checkParent(datum[3], index, layoutSummary, 'targetId');
if (datum.target) {
return checkParent(datum.target.id, index, layoutSummary, 'targetId');
}
logger.warn('No target for data at index ' + index);
return false;
}).filter(function (datum, index) {
return checkNumber({
sourceStart: datum[1],
sourceEnd: datum[2],
targetStart: datum[4],
targetEnd: datum[5],
value: datum[6] || 1
sourceStart: datum.source.start,
sourceEnd: datum.source.end,
targetStart: datum.target.start,
targetEnd: datum.target.end,
value: datum.value || 1
}, index);
}).map(function (datum) {
return {
source: {
id: datum[0],
start: Math.max(0, parseFloat(datum[1])),
end: Math.min(layoutSummary[datum[0]], parseFloat(datum[2]))
},
target: {
id: datum[3],
start: Math.max(0, parseFloat(datum[4])),
end: Math.min(layoutSummary[datum[3]], parseFloat(datum[5]))
},
value: parseFloat(datum[6]) || 1
};
});

return {
Expand Down
16 changes: 8 additions & 8 deletions dist/circos.min.js

Large diffs are not rendered by default.

78 changes: 24 additions & 54 deletions src/data-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,13 @@ export function parsePositionValueData(data, layoutSummary) {
return {data: [], meta: {min: null, max: null}};
}

const preParsedData = normalize(data, ['parent_id', 'position', 'value']);

const filteredData = preParsedData
const filteredData = data
.filter((datum, index) =>
checkParent(datum.block_id, index, layoutSummary, 'parent')
)
.filter((datum, index) =>
checkNumber({position: datum.position, value: datum.value}, index)
)
.map((datum) => {
return {
block_id: datum.block_id,
position: Math.min(layoutSummary[datum.block_id], parseFloat(datum.position)),
value: parseFloat(datum.value) || 1,
};
});
);

return buildOutput(filteredData);
}
Expand All @@ -133,8 +124,7 @@ export function parsePositionTextData(data, layoutSummary) {
return {data: [], meta: {min: null, max: null}};
}

const preParsedData = normalize(data, ['parent_id', 'position', 'value']);
const filteredData = preParsedData
const filteredData = data
.filter((datum, index) =>
checkParent(datum.block_id, index, layoutSummary, 'parent')
)
Expand All @@ -146,53 +136,33 @@ export function parsePositionTextData(data, layoutSummary) {
}

export function parseChordData(data, layoutSummary) {
// ['source_id', 'source_start', 'source_end', 'target_id', 'target_start', 'target_end', 'value']
console.log(data)
if (data.length === 0) {
return {data: [], meta: {min: null, max: null}};
}

const preParsedData = normalize(
data,
[
'sourceId',
'sourceStart',
'sourceEnd',
'targetId',
'targetStart',
'targetEnd',
]
);

const formatedData = preParsedData
.filter((datum, index) =>
checkParent(datum[0], index, layoutSummary, 'sourceId')
)
.filter((datum, index) =>
checkParent(datum[3], index, layoutSummary, 'targetId')
)
const formatedData = data
.filter((datum, index) => {
if (datum.source) {
return checkParent(datum.source.id, index, layoutSummary, 'sourceId');
}
logger.warn(`No source for data at index ${index}`);
return false;
})
.filter((datum, index) => {
if (datum.target) {
return checkParent(datum.target.id, index, layoutSummary, 'targetId');
}
logger.warn(`No target for data at index ${index}`);
return false;
})
.filter((datum, index) => checkNumber({
sourceStart: datum[1],
sourceEnd: datum[2],
targetStart: datum[4],
targetEnd: datum[5],
value: datum[6] || 1,
sourceStart: datum.source.start,
sourceEnd: datum.source.end,
targetStart: datum.target.start,
targetEnd: datum.target.end,
value: datum.value || 1,
}, index)
).map((datum) => {
return {
source: {
id: datum[0],
start: Math.max(0, parseFloat(datum[1])),
end: Math.min(layoutSummary[datum[0]], parseFloat(datum[2])),
},
target: {
id: datum[3],
start: Math.max(0, parseFloat(datum[4])),
end: Math.min(layoutSummary[datum[3]], parseFloat(datum[5])),
},
value: parseFloat(datum[6]) || 1,
};
});
);

return {
data: formatedData,
Expand Down

0 comments on commit 824713f

Please sign in to comment.