in client/client/dataServices/vcf/vcf-analyzer.js [18:165]
static analyzeVariant(variant, currentChromosome, sample){
if (variant.analyzed) {
return variant;
}
let zygosity = 0; // unknown
let organismType;
if (variant.genotypeData && variant.genotypeData.organismType) {
organismType = variant.genotypeData.organismType;
} else if (sample && variant.genotypeData[sample]) {
organismType = variant.genotypeData[sample].organismType;
} else if (variant.genotypeData) {
const [firstSample] = Object.values(variant.genotypeData || {});
if (firstSample && firstSample.organismType) {
organismType = firstSample.organismType;
}
}
switch ((organismType || '').toLowerCase()){
case 'homozygous': zygosity = 1; break;
case 'heterozygous': zygosity = 2; break;
}
const result = {
analyzed: true,
alternativeAllelesInfo: [],
symbol: null,
name: null,
length: variant.endIndex - variant.startIndex + 1,
interChromosome: false,
isDefaultPositioning: true,
startIndexCorrected: variant.startIndex + VcfAnalyzer.getVariantTranslation(variant),
serverStartIndex: variant.startIndex,
positioningInfos:[{
startIndex: variant.startIndex + VcfAnalyzer.getVariantTranslation(variant),
endIndex: variant.endIndex,
length: variant.endIndex - variant.startIndex + 1
}],
zygosity
};
variant = Object.assign(variant, result);
if (variant.type !== undefined && variant.type !== null && variant.type.toLowerCase() === 'statistic') {
return variant;
}
if (variant.type.toLowerCase() === 'ins') {
variant.endIndex = variant.startIndex;
}
const alternativeAllelesInfo = VcfAnalyzer.analyzeAlternativeAlleles(variant);
let name = null;
let symbol = null;
let structuralSymbol = null;
if (variant.type === null || variant.type === undefined){
for (let i = 0; i < alternativeAllelesInfo.length; i++){
if (alternativeAllelesInfo[i].info && alternativeAllelesInfo[i].info.type){
variant.type = alternativeAllelesInfo[i].info.type;
break;
}
}
}
if (variant.type === null || variant.type === undefined){
variant.type = '';
}
switch (variant.type.toLowerCase()){
case 'ins':
{
symbol = structuralSymbol = name = '+';
}
break;
case 'del':
{
symbol = structuralSymbol = name = '\u2014';
}
break;
case 'snv':
{
symbol = structuralSymbol = name = '\u2192';
}
break;
}
if (name === null){
symbol = structuralSymbol = name = variant.type;
}
if (variant.structural) {
symbol = '';
}
let isInterChromosome = false;
let currentChromosomeWithPrefix = currentChromosome;
const currentChromosomeWithBrackets = `<${ currentChromosome }>`;
if (currentChromosomeWithPrefix.toLowerCase().indexOf('chr') === -1){
currentChromosomeWithPrefix = `chr${ currentChromosomeWithPrefix}`;
}
alternativeAllelesInfo.forEach(alt => {
if (alt.mate){
alt.mate.intraChromosome = VcfAnalyzer.isCurrentChromosome(
{
chromosome: currentChromosome,
chromosomeWithPrefix: currentChromosomeWithPrefix,
chromosomeWithBrackets: currentChromosomeWithBrackets
}, alt.mate.chromosome);
if (alt.mate.intraChromosome && alt.mate.position !== null && alt.mate.position !== undefined){
alt.mate.boundaries = {
startIndex: Math.min(variant.startIndex, alt.mate.position),
endIndex: Math.max(variant.startIndex, alt.mate.position)
};
}
isInterChromosome = isInterChromosome || !alt.mate.intraChromosome;
}
});
const variantPositioningInfos = [];
for (let i = 0; i < alternativeAllelesInfo.length; i++){
const alt = alternativeAllelesInfo[i];
if (alt.mate && alt.mate.boundaries){
alt.positioningInfoIndex = variantPositioningInfos.length;
variantPositioningInfos.push({
startIndex: alt.mate.boundaries.startIndex + VcfAnalyzer.getVariantTranslation(variant),
endIndex: alt.mate.boundaries.endIndex,
length: alt.mate.boundaries.endIndex - alt.mate.boundaries.startIndex + 1
});
}
}
if (variantPositioningInfos.length === 0){
variant.isDefaultPositioning = true;
variantPositioningInfos.push({
startIndex: variant.startIndex + VcfAnalyzer.getVariantTranslation(variant),
endIndex: variant.endIndex,
length: variant.endIndex - variant.startIndex + 1
});
}
else {
variant.isDefaultPositioning = false;
}
const buildDisplayTextFn = function(alternativeAlleleInfo) {
VcfAnalyzer.buildAlternativeAlleleDisplayText(variant, alternativeAlleleInfo);
};
alternativeAllelesInfo.forEach(buildDisplayTextFn);
variant.analyzed = true;
variant.alternativeAllelesInfo = alternativeAllelesInfo;
variant.positioningInfos = variantPositioningInfos;
variant.symbol = symbol;
variant.name = name;
variant.structuralSymbol = structuralSymbol;
variant.length = variant.endIndex - variant.startIndex + 1;
variant.interChromosome = isInterChromosome;
variant.zygosity = zygosity;
return variant;
}