Skip to content

Commit

Permalink
Adding tandem duplications as an SV fusion type and automatically fil…
Browse files Browse the repository at this point in the history
…tering out all events where the genes being fused are the same gene.
  • Loading branch information
VelNZ committed Mar 9, 2018
1 parent b7e27c7 commit f8c2f40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
20 changes: 19 additions & 1 deletion functions/gbs_analysis_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ function analysis_type_svfusions_gbs(array $samples_to_query, array $gene_list_t
# WRITE ALL POTENTIALLY FUSING BLOCKS PER SAMPLE OUT TO BED FILES
#############################################

$samples_bed_paths = write_event_types_per_sample_to_beds($samples_to_query, array("inversion", "BND", "deletion"), "split_deletions");
$samples_bed_paths = write_event_types_per_sample_to_beds($samples_to_query, array("inversion", "BND"), array("deletion", "tandem duplication"));
// Note: this will write block types with 2 breakpoints (e.g. INV/BND) on 2 lines with their separate block IDs but for blocks where it's one event (e.g. deletions) it will write the single block ID followed by -1 and -2 for the 2 breakpoints at the start and end

if ($samples_bed_paths === false) {
Expand Down Expand Up @@ -620,6 +620,24 @@ function analysis_type_svfusions_gbs(array $samples_to_query, array $gene_list_t
}
}

// Go through each parsed block id
foreach (array_keys($intersection_results) as $block_id) {
// If the block id is the first one of one of the ones that were split into their breakpoints
if (preg_match("/\-1$/", $block_id)) {
$paired_split_block_id = preg_replace("/-1$/", "-2", $block_id);

// If the paired breakpoint also overlapped with one or more genes
if (isset($intersection_results[$paired_split_block_id])) {
// If both only overlapped with 1 gene and that gene is the same
if (count($intersection_results[$block_id]["gene"]) == 1 && count($intersection_results[$paired_split_block_id]["gene"]) == 1 && $intersection_results[$block_id]["gene"][0] == $intersection_results[$paired_split_block_id]["gene"][0]) {
// Delete both
unset($intersection_results[$block_id], $intersection_results[$paired_split_block_id]);
}

}
}
}

// Array to store block IDs that were successfully intersected with the gene list (i.e. overlap a gene)
$intersected_block_ids = array_keys($intersection_results);

Expand Down
8 changes: 4 additions & 4 deletions functions/gbs_query_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ function write_samples_methods_to_beds(array $sample_names, array $method_names)
# WRITE EVENT TYPE BLOCKS TO BED FILES PER SAMPLE
#############################################

function write_event_types_per_sample_to_beds(array $sample_names, array $event_types, $deletions_split_flag = NULL) {
function write_event_types_per_sample_to_beds(array $sample_names, array $event_types, array $split_event_types) {
// At least one sample and event type must be supplied
if (count($sample_names) == 0 || count($event_types) == 0) {
return false;
Expand All @@ -505,7 +505,7 @@ function write_event_types_per_sample_to_beds(array $sample_names, array $event_
# FETCH ALL BLOCKS FOR SAMPLES AND EVENT TYPES
#############################################

$GBS_results = fetch_blocks_for_samples_methods_events_gbs($sample_names, array(), $event_types);
$GBS_results = fetch_blocks_for_samples_methods_events_gbs($sample_names, array(), array_merge($event_types, $split_event_types));

if ($GBS_results === false) {
return false;
Expand Down Expand Up @@ -533,8 +533,8 @@ function write_event_types_per_sample_to_beds(array $sample_names, array $event_
foreach (array_keys($GBS_results[$sample_name]) as $method_name) {
// Go through each block
foreach (array_keys($GBS_results[$sample_name][$method_name]) as $block_id) {
// If the flag to split deletions into multiple blocks has been set and the current event is a deletion
if (isset($deletions_split_flag) && $deletions_split_flag == "split_deletions" && $GBS_results[$sample_name][$method_name][$block_id]["event_type"] == "deletion") {
// If the current event is one of the ones for which to split one block into 2 breakpoints because the block is not stored as 2 breakpoints (e.g. deletions)
if (in_array($GBS_results[$sample_name][$method_name][$block_id]["event_type"], $split_event_types)) {
// Create 2 lines in the BED file for the sample + split block into start and end and add a -1/-2 to the end of the block id to enable teasing apart what genes they overlapped with later
array_push($bed_output, $GBS_results[$sample_name][$method_name][$block_id]["chromosome"]."\t".$GBS_results[$sample_name][$method_name][$block_id]["start"]."\t".($GBS_results[$sample_name][$method_name][$block_id]["start"] + 1)."\t".$block_id."-1\n");
array_push($bed_output, $GBS_results[$sample_name][$method_name][$block_id]["chromosome"]."\t".$GBS_results[$sample_name][$method_name][$block_id]["end"]."\t".($GBS_results[$sample_name][$method_name][$block_id]["end"] + 1)."\t".$block_id."-2\n");
Expand Down

0 comments on commit f8c2f40

Please sign in to comment.