use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.
the class StructuralVariantLegsFactory method create.
@NotNull
static List<StructuralVariantLegs> create(@NotNull final List<StructuralVariant> variants) {
final List<ModifiableStructuralVariantLegs> result = createLegs(false, variants);
final Multimap<GenomePosition, ModifiableStructuralVariantLegs> duplicates = findDuplicates(result);
for (GenomePosition duplicatePosition : duplicates.keySet()) {
final StructuralVariantLeg approvedLeg = reduce(duplicatePosition, duplicates.get(duplicatePosition));
boolean match = false;
for (ModifiableStructuralVariantLegs legs : duplicates.get(duplicatePosition)) {
Optional<StructuralVariantLeg> start = legs.start();
if (start.filter(x -> isDuplicate(duplicatePosition, x)).isPresent()) {
assert start.isPresent();
if (start.get().equals(approvedLeg)) {
match = true;
} else {
legs.setStart(Optional.empty());
}
}
Optional<StructuralVariantLeg> end = legs.end();
if (end.filter(x -> isDuplicate(duplicatePosition, x)).isPresent()) {
assert end.isPresent();
if (end.get().equals(approvedLeg)) {
match = true;
} else {
legs.setEnd(Optional.empty());
}
}
}
if (!match) {
result.add(ModifiableStructuralVariantLegs.create().setStart(approvedLeg).setEnd(Optional.empty()));
}
}
return new ArrayList<>(result);
}
use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.
the class PatientReporter method analyseGenomeData.
@NotNull
private GenomeAnalysis analyseGenomeData(@NotNull final String sample, @NotNull final String runDirectory) throws IOException {
LOGGER.info(" Loading somatic snv and indels...");
final List<SomaticVariant> variants = PatientReporterHelper.loadPassedSomaticVariants(sample, runDirectory);
LOGGER.info(" " + variants.size() + " somatic passed snps, mnps and indels loaded for sample " + sample);
LOGGER.info(" Analyzing somatic snp/mnp and indels....");
final VariantAnalysis variantAnalysis = variantAnalyzer().run(variants);
LOGGER.info(" Loading purity numbers...");
final PurityContext context = PatientReporterHelper.loadPurity(runDirectory, sample);
if (context.status().equals(FittedPurityStatus.NO_TUMOR)) {
LOGGER.warn("PURPLE DID NOT DETECT A TUMOR. Proceed with utmost caution!");
}
final FittedPurity purity = context.bestFit();
final FittedPurityScore purityScore = context.score();
final List<PurpleCopyNumber> purpleCopyNumbers = PatientReporterHelper.loadPurpleCopyNumbers(runDirectory, sample);
final List<GeneCopyNumber> panelGeneCopyNumbers = PatientReporterHelper.loadPurpleGeneCopyNumbers(runDirectory, sample).stream().filter(x -> reporterData().panelGeneModel().panel().contains(x.gene())).collect(Collectors.toList());
LOGGER.info(" " + purpleCopyNumbers.size() + " purple copy number regions loaded for sample " + sample);
LOGGER.info(" Analyzing purple somatic copy numbers...");
final PurpleAnalysis purpleAnalysis = ImmutablePurpleAnalysis.builder().gender(context.gender()).status(context.status()).fittedPurity(purity).fittedScorePurity(purityScore).copyNumbers(purpleCopyNumbers).panelGeneCopyNumbers(panelGeneCopyNumbers).build();
final Path structuralVariantVCF = PatientReporterHelper.findStructuralVariantVCF(runDirectory);
LOGGER.info(" Loading structural variants...");
final List<StructuralVariant> structuralVariants = StructuralVariantFileLoader.fromFile(structuralVariantVCF.toString(), true);
LOGGER.info(" Enriching structural variants with purple data.");
final List<EnrichedStructuralVariant> enrichedStructuralVariants = purpleAnalysis.enrichStructuralVariants(structuralVariants);
LOGGER.info(" Analysing structural variants...");
final StructuralVariantAnalysis structuralVariantAnalysis = structuralVariantAnalyzer().run(enrichedStructuralVariants, false);
return ImmutableGenomeAnalysis.of(sample, variantAnalysis, purpleAnalysis, structuralVariantAnalysis);
}
use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.
the class SvVCFAnnotator method generateFilteredSVFile.
private void generateFilteredSVFile(final List<StructuralVariant> variants, final String sampleId) {
try {
if (mFileWriter == null) {
String outputFileName = mOutputPath;
if (!outputFileName.endsWith("/"))
outputFileName += "/";
outputFileName += "svs_incl_filtered.csv";
Path outputFile = Paths.get(outputFileName);
mFileWriter = Files.newBufferedWriter(outputFile);
mFileWriter.write("SampleId,SvId,Type,ChrStart,PosStart,OrientStart,ChrEnd,PosEnd,OrientEnd,Filters\n");
}
for (final StructuralVariant var : variants) {
String filtersStr = var.filters();
if (filtersStr.equals("PASS") || filtersStr.equals("[]") || filtersStr.isEmpty()) {
LOGGER.debug("var({}) was a PASS", var.id());
filtersStr = "PASS";
} else {
// make tokenisable for further searches
LOGGER.debug("var({}) has filters: {}", var.id(), var.filters());
if (filtersStr.charAt(0) == '[')
filtersStr = filtersStr.substring(1);
if (filtersStr.charAt(filtersStr.length() - 1) == ']')
filtersStr = filtersStr.substring(0, filtersStr.length() - 1);
if (!filtersStr.isEmpty())
filtersStr = filtersStr.replace(",", ";");
}
mFileWriter.write(String.format("%s,%s,%s,%s,%d,%d,%s,%d,%d,%s", sampleId, var.id(), var.type(), var.chromosome(true), var.position(true), var.orientation(true), var.chromosome(false), var.position(false), var.orientation(false), filtersStr));
mFileWriter.newLine();
}
} catch (final IOException e) {
LOGGER.error("error writing to outputFile");
}
}
use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.
the class StructuralVariantLegsFactoryTest method testSameVAF.
@Test
public void testSameVAF() {
final StructuralVariant first = sv(100, 200, StructuralVariantType.INV, 0.25, 0.25);
final StructuralVariant second = sv(200, 300, StructuralVariantType.BND, 0.25, 0.25);
final List<StructuralVariant> variants = Lists.newArrayList(first, second);
final List<StructuralVariantLegs> legs = StructuralVariantLegsFactory.create(variants);
assertEquals(2, legs.size());
assertTrue(legs.get(0).start().isPresent());
assertTrue(legs.get(0).end().isPresent());
assertTrue(legs.get(1).start().isPresent());
assertTrue(legs.get(1).end().isPresent());
assertLeg(1, 0.25, legs.get(0).start().get());
assertLeg(1, 0.25, legs.get(0).end().get());
assertLeg(1, 0.25, legs.get(1).start().get());
assertLeg(1, 0.25, legs.get(1).end().get());
}
use of com.hartwig.hmftools.common.variant.structural.StructuralVariant in project hmftools by hartwigmedical.
the class StructuralVariantPositionFactoryTest method excludeInserts.
@Test
public void excludeInserts() {
final StructuralVariant variant = PurpleDatamodelTest.createStructuralVariant("1", 1001, "1", 1001, StructuralVariantType.INS).build();
assertEquals(0, ClusterVariantLegFactory.create(Lists.newArrayList(variant)).size());
}
Aggregations