{"action":"created","comment":{"url":"https://api.github.com/repos/genome/genome/pulls/comments/27823139","id":27823139,"diff_hunk":"@@ -0,0 +1,280 @@\n+package Genome::Model::ClinSeq::Command::IdentifyLoh;\n+\n+use strict;\n+use warnings;\n+use File::Spec;\n+use Genome;\n+\n+class Genome::Model::ClinSeq::Command::IdentifyLoh {\n+  is => ['Command::V2',\n+        'Genome::Model::ClinSeq::Util',\n+  ],\n+  has_input => [\n+    clinseq_build => {\n+        is => 'Genome::Model::Build::ClinSeq',\n+        doc => 'ClinSeq build to identify LOH regions in.\n+            [Either this or a somatic variation build is required.]',\n+        is_optional => 1,\n+    },\n+    outdir => {\n+        is => 'FilesystemPath',\n+        doc => 'Directory where output files will be written.',\n+    },\n+    somvar_build => {\n+        is => 'Genome::Model::Build::SomaticVariation',\n+        doc => 'SomVar build to identify LOH regions in.\n+        [Either this or a clinseq build is required.]',\n+        is_optional => 1,\n+    },\n+    minprobes=> {\n+        is => 'Number',\n+        is_optional => 1,\n+        doc => 'Minimum number of probes to call a loh segment.',\n+        default => 10,\n+    },\n+    segment_pc_cutoff => {\n+        is => 'Number',\n+        is_optional => 1,\n+        doc => 'Minimum percent of LOH in a segment. n_loh_probes/n_probes * 100',\n+        default => 0.95,\n+    },\n+    test => {\n+        is => 'Boolean',\n+        doc => 'set for test-cases',\n+        is_optional => 1,\n+        default => 0,\n+    },\n+    ],\n+    doc => 'Identify regions of LOH using clinseq tumor/normal pairs.',\n+};\n+\n+sub help_synopsis {\n+    return <<EOS\n+genome model clin-seq identify-loh\\\\\n+    --outdir=/tmp/test/ \\\\\n+    --clinseq-build='a4abcd1313eb4376b59e68a9dd9d5ad2'\n+genome model clin-seq identify-loh\\\\\n+    --outdir=/tmp/test/ \\\\\n+    --somvar-build='9dc0385a1b634c9bb85eb2017b3a0c73'\n+EOS\n+}\n+\n+sub help_detail {\n+    return <<EOS\n+Use the results from Varscan in the somatic-variation builds and identify\n+regions of LOH. Specifically, look at heterozygous single nucleotide variants\n+in the normal sample and compare with stretches of homozygosity in the tumor.\n+\n+If a clinseq build is supplied as input, the tool attempts to use the results\n+from the WGS-somatic-variation build input, if these are unavailable the tool\n+looks for WEx-somatic-variation build.\n+\n+Alternatively, instead of a clin-seq build you can supply a\n+somatic-variation build as an input.\n+\n+Thanks to Chris Miller for working out the workflow.\n+EOS\n+}\n+\n+sub __errors__ {\n+    my $self = shift;\n+    my @errors = $self->SUPER::__errors__(@_);\n+    unless (-e $self->outdir && -d $self->outdir) {\n+        push @errors, UR::Object::Tag->create(\n+            type => 'error',\n+            properties => ['outdir'],\n+            desc => \"Outdir: \" . $self->outdir .\n+                \" not found or not a directory\",\n+        );\n+    }\n+    return @errors;\n+}\n+\n+#Get a somatic-variation build from input or from clinseq-build\n+sub resolve_somvar {\n+    my $self = shift;\n+    my $somvar_build = $self->somvar_build;\n+    unless($somvar_build) {\n+        my $clinseq_build = $self->clinseq_build;\n+        unless($clinseq_build) {\n+            die $self->error_message(\"Please pass a somatic-variation\n+                or clinseq build as input.\");\n+        }\n+        $somvar_build = $self->get_best_somvar_build($clinseq_build);\n+    }\n+    return $somvar_build;\n+}\n+\n+#Take Varscan SNVs and split into per-chromosome calls.\n+sub split_snvs {\n+    my $self = shift;\n+    my $varscan_op = shift;\n+    my $snv_prefix = shift;\n+    my $awk_cmd;\n+    #use subsample of chr1 variants for test\n+    if($self->test) {\n+        $awk_cmd = \"awk '\\$1==1 { if(NR\\%1000 == 0) { print > \\\"$snv_prefix.\\\"\\$1\\\".snp\\\" }}' $varscan_op\";\n+    } else {\n+        $awk_cmd = \"awk '{ print > \\\"$snv_prefix.\\\"\\$1\\\".snp\\\" }' $varscan_op\";\n+    }\n+    Genome::Sys->shellcmd(cmd => $awk_cmd);\n+    return;\n+}\n+\n+#Get Varscan SNVs from somatic-variation\n+sub get_varscan_snvs {\n+    my $self = shift;\n+    my $somvar_build = shift;\n+    my $snv_prefix = shift;\n+    my $dd = $somvar_build->data_directory;\n+    my @varscan_snvs =\n+    glob(File::Spec->join($dd, \"variants/snv/varscan-somatic-*/snvs.hq.unfiltered\"));\n+    unless(scalar @varscan_snvs) {\n+        die $self->error_message(\"Unable to find varscan SNVs in $dd\");\n+    }\n+    $self->status_message(\"varscan snvs file found: \" .\n+        join(\"\\t\", @varscan_snvs));\n+    $self->split_snvs($varscan_snvs[0], $snv_prefix);\n+}\n+\n+#Get tumor/normal BAMs from somatic-variation\n+sub get_tumor_normal_bam {\n+    my $self = shift;\n+    my $somvar_build = shift;\n+    my $tumor_bam = $somvar_build->tumor_model->last_succeeded_build->\n+    whole_rmdup_bam_file;\n+    my $normal_bam = $somvar_build->normal_model->last_succeeded_build->\n+    whole_rmdup_bam_file;\n+    unless (-e $tumor_bam and -e $normal_bam) {\n+        die $self->error_message(\"tumor_bam $tumor_bam or normal_bam \" .\n+            \"$normal_bam does not exist.\");\n+    }\n+    return ($tumor_bam, $normal_bam);\n+}\n+\n+#Get the reference-sequence build from the\n+# ref-align builds used in somatic-variation\n+sub reference_build {\n+    my $self = shift;\n+    my $somvar_build = shift;\n+    my $normal_refalign_build = $somvar_build->normal_build if ($somvar_build);\n+    my $tumor_refalign_build = $somvar_build->tumor_build if ($somvar_build);\n+    my @input_builds = ($normal_refalign_build,\n+        $tumor_refalign_build, $somvar_build);\n+    for my $build (@input_builds){\n+        next unless $build;\n+        my $m = $build->model;\n+        if ($m->can(\"reference_sequence_build\")){\n+            return $m->reference_sequence_build;\n+        }\n+    }\n+}\n+\n+#Filter out putative false-positive SNVs\n+sub filter_snvs {\n+    my $self = shift;\n+    my $somvar_build = shift;\n+    my $snv_prefix = shift;\n+    my ($tumor_bam, $normal_bam) =\n+    $self->get_tumor_normal_bam($somvar_build);\n+    my $refbuild = $self->reference_build($somvar_build);\n+    my $ref_fa = $refbuild->full_consensus_path('fa');\n+    my $filter = Genome::Model::Tools::Varscan::SomaticFilterWorkflow->\n+    create(\n+        outdir => $self->outdir,\n+        tumor_bam => $tumor_bam,\n+        normal_bam => $normal_bam,\n+        prefix => $snv_prefix,\n+        reference => $ref_fa,\n+    );\n+    $filter->execute();\n+}\n+\n+#Combine germline, LOH calls and sort them\n+sub combine_sort_snvs {\n+    my $self = shift;\n+    my $snv_prefix = shift;\n+    my $snv_combined = $snv_prefix . \".combined\";\n+    my $snv_combined_sorted = $snv_prefix . \".combined.sorted\";\n+    my $germline = $snv_prefix . \"*.formatted.LOH.hc.filtered\";\n+    my $loh = $snv_prefix . \"*.formatted.Germline.hc.filtered\";\n+    unless(scalar glob(\"$germline $loh\")) {\n+        die $self->error_message(\"Unable to find $germline or $loh\");\n+    }\n+    my $cat_cmd = \"cat $germline $loh > $snv_combined\";","path":"lib/perl/Genome/Model/ClinSeq/Command/IdentifyLoh.pm","position":204,"original_position":204,"commit_id":"225fb54013bdc33ebc751e145353ede5dac8151d","original_commit_id":"225fb54013bdc33ebc751e145353ede5dac8151d","user":{"login":"tmooney","id":187262,"avatar_url":"https://avatars.githubusercontent.com/u/187262?v=3","gravatar_id":"","url":"https://api.github.com/users/tmooney","html_url":"https://github.com/tmooney","followers_url":"https://api.github.com/users/tmooney/followers","following_url":"https://api.github.com/users/tmooney/following{/other_user}","gists_url":"https://api.github.com/users/tmooney/gists{/gist_id}","starred_url":"https://api.github.com/users/tmooney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmooney/subscriptions","organizations_url":"https://api.github.com/users/tmooney/orgs","repos_url":"https://api.github.com/users/tmooney/repos","events_url":"https://api.github.com/users/tmooney/events{/privacy}","received_events_url":"https://api.github.com/users/tmooney/received_events","type":"User","site_admin":false},"body":"You may be interested in `Genome::Sys->concatenate_files` or `Genome::Sys->cat` (from `Genome::Site::TGI::Extension::Sys`).  The former was created to handle potentially troublesome filenames; the latter long lists that may exceed the allowed length of a command.","created_at":"2015-04-06T19:38:43Z","updated_at":"2015-04-06T19:38:43Z","html_url":"https://github.com/genome/genome/pull/628#discussion_r27823139","pull_request_url":"https://api.github.com/repos/genome/genome/pulls/628","_links":{"self":{"href":"https://api.github.com/repos/genome/genome/pulls/comments/27823139"},"html":{"href":"https://github.com/genome/genome/pull/628#discussion_r27823139"},"pull_request":{"href":"https://api.github.com/repos/genome/genome/pulls/628"}}},"pull_request":{"url":"https://api.github.com/repos/genome/genome/pulls/628","id":32609902,"html_url":"https://github.com/genome/genome/pull/628","diff_url":"https://github.com/genome/genome/pull/628.diff","patch_url":"https://github.com/genome/genome/pull/628.patch","issue_url":"https://api.github.com/repos/genome/genome/issues/628","number":628,"state":"open","locked":false,"title":"Module to identify LOH regions.","user":{"login":"gatoravi","id":764948,"avatar_url":"https://avatars.githubusercontent.com/u/764948?v=3","gravatar_id":"","url":"https://api.github.com/users/gatoravi","html_url":"https://github.com/gatoravi","followers_url":"https://api.github.com/users/gatoravi/followers","following_url":"https://api.github.com/users/gatoravi/following{/other_user}","gists_url":"https://api.github.com/users/gatoravi/gists{/gist_id}","starred_url":"https://api.github.com/users/gatoravi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gatoravi/subscriptions","organizations_url":"https://api.github.com/users/gatoravi/orgs","repos_url":"https://api.github.com/users/gatoravi/repos","events_url":"https://api.github.com/users/gatoravi/events{/privacy}","received_events_url":"https://api.github.com/users/gatoravi/received_events","type":"User","site_admin":false},"body":"This module helps identify LOH regions in the tumor compared to the normal. It takes a clin-seq or somatic-variation build as input. Thanks to @chrisamiller for working out the details.","created_at":"2015-04-03T19:16:59Z","updated_at":"2015-04-06T19:38:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f0cf60ff7f09a9af8e7221fbe0c581762bd6e7f2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/genome/genome/pulls/628/commits","review_comments_url":"https://api.github.com/repos/genome/genome/pulls/628/comments","review_comment_url":"https://api.github.com/repos/genome/genome/pulls/comments{/number}","comments_url":"https://api.github.com/repos/genome/genome/issues/628/comments","statuses_url":"https://api.github.com/repos/genome/genome/statuses/225fb54013bdc33ebc751e145353ede5dac8151d","head":{"label":"gatoravi:clinseq_add_loh","ref":"clinseq_add_loh","sha":"225fb54013bdc33ebc751e145353ede5dac8151d","user":{"login":"gatoravi","id":764948,"avatar_url":"https://avatars.githubusercontent.com/u/764948?v=3","gravatar_id":"","url":"https://api.github.com/users/gatoravi","html_url":"https://github.com/gatoravi","followers_url":"https://api.github.com/users/gatoravi/followers","following_url":"https://api.github.com/users/gatoravi/following{/other_user}","gists_url":"https://api.github.com/users/gatoravi/gists{/gist_id}","starred_url":"https://api.github.com/users/gatoravi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gatoravi/subscriptions","organizations_url":"https://api.github.com/users/gatoravi/orgs","repos_url":"https://api.github.com/users/gatoravi/repos","events_url":"https://api.github.com/users/gatoravi/events{/privacy}","received_events_url":"https://api.github.com/users/gatoravi/received_events","type":"User","site_admin":false},"repo":{"id":24162796,"name":"genome","full_name":"gatoravi/genome","owner":{"login":"gatoravi","id":764948,"avatar_url":"https://avatars.githubusercontent.com/u/764948?v=3","gravatar_id":"","url":"https://api.github.com/users/gatoravi","html_url":"https://github.com/gatoravi","followers_url":"https://api.github.com/users/gatoravi/followers","following_url":"https://api.github.com/users/gatoravi/following{/other_user}","gists_url":"https://api.github.com/users/gatoravi/gists{/gist_id}","starred_url":"https://api.github.com/users/gatoravi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gatoravi/subscriptions","organizations_url":"https://api.github.com/users/gatoravi/orgs","repos_url":"https://api.github.com/users/gatoravi/repos","events_url":"https://api.github.com/users/gatoravi/events{/privacy}","received_events_url":"https://api.github.com/users/gatoravi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gatoravi/genome","description":"","fork":true,"url":"https://api.github.com/repos/gatoravi/genome","forks_url":"https://api.github.com/repos/gatoravi/genome/forks","keys_url":"https://api.github.com/repos/gatoravi/genome/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gatoravi/genome/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gatoravi/genome/teams","hooks_url":"https://api.github.com/repos/gatoravi/genome/hooks","issue_events_url":"https://api.github.com/repos/gatoravi/genome/issues/events{/number}","events_url":"https://api.github.com/repos/gatoravi/genome/events","assignees_url":"https://api.github.com/repos/gatoravi/genome/assignees{/user}","branches_url":"https://api.github.com/repos/gatoravi/genome/branches{/branch}","tags_url":"https://api.github.com/repos/gatoravi/genome/tags","blobs_url":"https://api.github.com/repos/gatoravi/genome/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gatoravi/genome/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gatoravi/genome/git/refs{/sha}","trees_url":"https://api.github.com/repos/gatoravi/genome/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gatoravi/genome/statuses/{sha}","languages_url":"https://api.github.com/repos/gatoravi/genome/languages","stargazers_url":"https://api.github.com/repos/gatoravi/genome/stargazers","contributors_url":"https://api.github.com/repos/gatoravi/genome/contributors","subscribers_url":"https://api.github.com/repos/gatoravi/genome/subscribers","subscription_url":"https://api.github.com/repos/gatoravi/genome/subscription","commits_url":"https://api.github.com/repos/gatoravi/genome/commits{/sha}","git_commits_url":"https://api.github.com/repos/gatoravi/genome/git/commits{/sha}","comments_url":"https://api.github.com/repos/gatoravi/genome/comments{/number}","issue_comment_url":"https://api.github.com/repos/gatoravi/genome/issues/comments{/number}","contents_url":"https://api.github.com/repos/gatoravi/genome/contents/{+path}","compare_url":"https://api.github.com/repos/gatoravi/genome/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gatoravi/genome/merges","archive_url":"https://api.github.com/repos/gatoravi/genome/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gatoravi/genome/downloads","issues_url":"https://api.github.com/repos/gatoravi/genome/issues{/number}","pulls_url":"https://api.github.com/repos/gatoravi/genome/pulls{/number}","milestones_url":"https://api.github.com/repos/gatoravi/genome/milestones{/number}","notifications_url":"https://api.github.com/repos/gatoravi/genome/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gatoravi/genome/labels{/name}","releases_url":"https://api.github.com/repos/gatoravi/genome/releases{/id}","created_at":"2014-09-17T21:18:45Z","updated_at":"2014-10-01T01:29:56Z","pushed_at":"2015-04-03T19:18:06Z","git_url":"git://github.com/gatoravi/genome.git","ssh_url":"git@github.com:gatoravi/genome.git","clone_url":"https://github.com/gatoravi/genome.git","svn_url":"https://github.com/gatoravi/genome","homepage":"","size":114826,"stargazers_count":0,"watchers_count":0,"language":"Perl","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"genome:master","ref":"master","sha":"80645645cd27222cfdf566727b783bafc498bb02","user":{"login":"genome","id":318108,"avatar_url":"https://avatars.githubusercontent.com/u/318108?v=3","gravatar_id":"","url":"https://api.github.com/users/genome","html_url":"https://github.com/genome","followers_url":"https://api.github.com/users/genome/followers","following_url":"https://api.github.com/users/genome/following{/other_user}","gists_url":"https://api.github.com/users/genome/gists{/gist_id}","starred_url":"https://api.github.com/users/genome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genome/subscriptions","organizations_url":"https://api.github.com/users/genome/orgs","repos_url":"https://api.github.com/users/genome/repos","events_url":"https://api.github.com/users/genome/events{/privacy}","received_events_url":"https://api.github.com/users/genome/received_events","type":"Organization","site_admin":false},"repo":{"id":23442737,"name":"genome","full_name":"genome/genome","owner":{"login":"genome","id":318108,"avatar_url":"https://avatars.githubusercontent.com/u/318108?v=3","gravatar_id":"","url":"https://api.github.com/users/genome","html_url":"https://github.com/genome","followers_url":"https://api.github.com/users/genome/followers","following_url":"https://api.github.com/users/genome/following{/other_user}","gists_url":"https://api.github.com/users/genome/gists{/gist_id}","starred_url":"https://api.github.com/users/genome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/genome/subscriptions","organizations_url":"https://api.github.com/users/genome/orgs","repos_url":"https://api.github.com/users/genome/repos","events_url":"https://api.github.com/users/genome/events{/privacy}","received_events_url":"https://api.github.com/users/genome/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/genome/genome","description":"Core modules used by the GMS","fork":false,"url":"https://api.github.com/repos/genome/genome","forks_url":"https://api.github.com/repos/genome/genome/forks","keys_url":"https://api.github.com/repos/genome/genome/keys{/key_id}","collaborators_url":"https://api.github.com/repos/genome/genome/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/genome/genome/teams","hooks_url":"https://api.github.com/repos/genome/genome/hooks","issue_events_url":"https://api.github.com/repos/genome/genome/issues/events{/number}","events_url":"https://api.github.com/repos/genome/genome/events","assignees_url":"https://api.github.com/repos/genome/genome/assignees{/user}","branches_url":"https://api.github.com/repos/genome/genome/branches{/branch}","tags_url":"https://api.github.com/repos/genome/genome/tags","blobs_url":"https://api.github.com/repos/genome/genome/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/genome/genome/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/genome/genome/git/refs{/sha}","trees_url":"https://api.github.com/repos/genome/genome/git/trees{/sha}","statuses_url":"https://api.github.com/repos/genome/genome/statuses/{sha}","languages_url":"https://api.github.com/repos/genome/genome/languages","stargazers_url":"https://api.github.com/repos/genome/genome/stargazers","contributors_url":"https://api.github.com/repos/genome/genome/contributors","subscribers_url":"https://api.github.com/repos/genome/genome/subscribers","subscription_url":"https://api.github.com/repos/genome/genome/subscription","commits_url":"https://api.github.com/repos/genome/genome/commits{/sha}","git_commits_url":"https://api.github.com/repos/genome/genome/git/commits{/sha}","comments_url":"https://api.github.com/repos/genome/genome/comments{/number}","issue_comment_url":"https://api.github.com/repos/genome/genome/issues/comments{/number}","contents_url":"https://api.github.com/repos/genome/genome/contents/{+path}","compare_url":"https://api.github.com/repos/genome/genome/compare/{base}...{head}","merges_url":"https://api.github.com/repos/genome/genome/merges","archive_url":"https://api.github.com/repos/genome/genome/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/genome/genome/downloads","issues_url":"https://api.github.com/repos/genome/genome/issues{/number}","pulls_url":"https://api.github.com/repos/genome/genome/pulls{/number}","milestones_url":"https://api.github.com/repos/genome/genome/milestones{/number}","notifications_url":"https://api.github.com/repos/genome/genome/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/genome/genome/labels{/name}","releases_url":"https://api.github.com/repos/genome/genome/releases{/id}","created_at":"2014-08-28T20:59:19Z","updated_at":"2015-04-06T19:37:44Z","pushed_at":"2015-04-06T19:37:44Z","git_url":"git://github.com/genome/genome.git","ssh_url":"git@github.com:genome/genome.git","clone_url":"https://github.com/genome/genome.git","svn_url":"https://github.com/genome/genome","homepage":"","size":138410,"stargazers_count":8,"watchers_count":8,"language":"Perl","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":36,"mirror_url":null,"open_issues_count":13,"forks":36,"open_issues":13,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/genome/genome/pulls/628"},"html":{"href":"https://github.com/genome/genome/pull/628"},"issue":{"href":"https://api.github.com/repos/genome/genome/issues/628"},"comments":{"href":"https://api.github.com/repos/genome/genome/issues/628/comments"},"review_comments":{"href":"https://api.github.com/repos/genome/genome/pulls/628/comments"},"review_comment":{"href":"https://api.github.com/repos/genome/genome/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/genome/genome/pulls/628/commits"},"statuses":{"href":"https://api.github.com/repos/genome/genome/statuses/225fb54013bdc33ebc751e145353ede5dac8151d"}}}}