{"action":"created","comment":{"url":"https://api.github.com/repos/genome/genome/pulls/comments/25023836","id":25023836,"diff_hunk":"@@ -219,24 +226,70 @@ sub create {\n         for my $alignment (@alignments) {\n             $alignment->add_user(user => $self, label => 'uses');\n         }\n-\n-        return 1;\n-    };\n-    if (my $error = $@) {\n-        $tx->rollback();\n-        die $error;\n-    } elsif ($rv ne 1) {\n+    }\n+    catch {\n         $tx->rollback();\n-        $self->error_message('Unexpected return value: ' . $rv);\n-        die $self->error_message;\n-    } else {\n-        $tx->commit();\n+        die $self->error_message('Merge failed due to error: ' . $_);\n     }\n+    finally {\n+        for my $allocation (@temp_allocations) {\n+            $allocation->delete;\n+        }\n+        unless ($_) {\n+            $tx->commit();\n+            $self->debug_message('Merge done');\n+        }\n+    };\n \n     $self->debug_message(\"Resizing the disk allocation...\");\n     if ($self->_disk_allocation) {\n-        unless ($self->_disk_allocation->reallocate) {\n-            $self->warning_message(\"Failed to reallocate disk allocation: \" . $self->_disk_allocation->id);\n+        unless (eval { $self->_disk_allocation->reallocate }) {\n+            $self->warning_message(\"Failed to reallocate my disk allocation with id (%s). Eval returned (%s) \", $self->_disk_allocation->id, $@);\n+        }\n+        $self->output_dir($self->_disk_allocation->absolute_path); #update if was moved\n+    }\n+\n+    #purge per lane alignment along with its .bai and md5 files, but\n+    #create header files and keep flagstat files for the future use\n+    for my $alignment ($self->collect_individual_alignments) {\n+        for my $bam_path ($alignment->alignment_bam_file_paths) {\n+            my $header = $bam_path . '.header';\n+            unless (-s $header) {\n+                my $sam_path = Genome::Model::Tools::Sam->path_for_samtools_version($self->samtools_version);\n+                my $cmd = \"$sam_path view -H $bam_path > $header\";\n+                Genome::Sys->shellcmd(\n+                    cmd => $cmd,\n+                    input_files  => [$bam_path],\n+                    output_files => [$header],\n+                );\n+            }\n+            my $flagstat = $bam_path . '.flagstat';\n+            unless (-s $flagstat) {\n+                my $cmd = Genome::Model::Tools::Sam::Flagstat->create(\n+                    bam_file    => $bam_path,\n+                    output_file => $flagstat,\n+                    use_version => $self->samtools_version,\n+                );\n+\n+                unless ($cmd->execute) {\n+                    die $self->error_message(\"Fail to run flagstat on $bam_path\");\n+                }\n+            }\n+            $self->debug_message(\"Now removing the per lane bam\");","path":"lib/perl/Genome/InstrumentData/AlignmentResult/Merged.pm","position":111,"original_position":111,"commit_id":"70a3600107f4f82fdc94fcb1f037c2622ab06064","original_commit_id":"70a3600107f4f82fdc94fcb1f037c2622ab06064","user":{"login":"apregier","id":1017787,"avatar_url":"https://avatars.githubusercontent.com/u/1017787?v=3","gravatar_id":"","url":"https://api.github.com/users/apregier","html_url":"https://github.com/apregier","followers_url":"https://api.github.com/users/apregier/followers","following_url":"https://api.github.com/users/apregier/following{/other_user}","gists_url":"https://api.github.com/users/apregier/gists{/gist_id}","starred_url":"https://api.github.com/users/apregier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apregier/subscriptions","organizations_url":"https://api.github.com/users/apregier/orgs","repos_url":"https://api.github.com/users/apregier/repos","events_url":"https://api.github.com/users/apregier/events{/privacy}","received_events_url":"https://api.github.com/users/apregier/received_events","type":"User","site_admin":false},"body":"Should this go in a post-commit hook to limit the chances that the files get deleted but something goes wrong and the merged result doesn't actually get committed?","created_at":"2015-02-19T20:47:28Z","updated_at":"2015-02-19T20:47:28Z","html_url":"https://github.com/genome/genome/pull/407#discussion_r25023836","pull_request_url":"https://api.github.com/repos/genome/genome/pulls/407","_links":{"self":{"href":"https://api.github.com/repos/genome/genome/pulls/comments/25023836"},"html":{"href":"https://github.com/genome/genome/pull/407#discussion_r25023836"},"pull_request":{"href":"https://api.github.com/repos/genome/genome/pulls/407"}}},"pull_request":{"url":"https://api.github.com/repos/genome/genome/pulls/407","id":27306488,"html_url":"https://github.com/genome/genome/pull/407","diff_url":"https://github.com/genome/genome/pull/407.diff","patch_url":"https://github.com/genome/genome/pull/407.patch","issue_url":"https://api.github.com/repos/genome/genome/issues/407","number":407,"state":"open","locked":false,"title":"Recreate per-lane bams on demand (and delete them when done)","user":{"login":"gsanders","id":863032,"avatar_url":"https://avatars.githubusercontent.com/u/863032?v=3","gravatar_id":"","url":"https://api.github.com/users/gsanders","html_url":"https://github.com/gsanders","followers_url":"https://api.github.com/users/gsanders/followers","following_url":"https://api.github.com/users/gsanders/following{/other_user}","gists_url":"https://api.github.com/users/gsanders/gists{/gist_id}","starred_url":"https://api.github.com/users/gsanders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsanders/subscriptions","organizations_url":"https://api.github.com/users/gsanders/orgs","repos_url":"https://api.github.com/users/gsanders/repos","events_url":"https://api.github.com/users/gsanders/events{/privacy}","received_events_url":"https://api.github.com/users/gsanders/received_events","type":"User","site_admin":false},"body":"This PR is to begin the discussion on the deletion and recreation of per-lane bams as appropriate. It's quite possible we are not locking enough and race conditions exist. I'm also sure we could use some code cleanup. We could use a lot of help with both of these things!\r\n\r\nWe are creating a 'real world one-off' integration test, which will a model with two builds. In the first build we will have two instrument data. In the third build we will delete the bams for the first two instrument data and archive the merged bam. The second build should unarchive the merged bam, recreate the two per-lane bams, align the third instrument data, and merge it all. If this works we'll have some confidence that we are doing what is required, but I'd still want to give a long look into locking and race condition issues.","created_at":"2015-01-13T21:30:32Z","updated_at":"2015-02-19T20:47:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d53dd36b10421910b770805bfd4cc202696c973b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/genome/genome/pulls/407/commits","review_comments_url":"https://api.github.com/repos/genome/genome/pulls/407/comments","review_comment_url":"https://api.github.com/repos/genome/genome/pulls/comments/{number}","comments_url":"https://api.github.com/repos/genome/genome/issues/407/comments","statuses_url":"https://api.github.com/repos/genome/genome/statuses/70a3600107f4f82fdc94fcb1f037c2622ab06064","head":{"label":"gsanders:recreate_per_lane_bam","ref":"recreate_per_lane_bam","sha":"70a3600107f4f82fdc94fcb1f037c2622ab06064","user":{"login":"gsanders","id":863032,"avatar_url":"https://avatars.githubusercontent.com/u/863032?v=3","gravatar_id":"","url":"https://api.github.com/users/gsanders","html_url":"https://github.com/gsanders","followers_url":"https://api.github.com/users/gsanders/followers","following_url":"https://api.github.com/users/gsanders/following{/other_user}","gists_url":"https://api.github.com/users/gsanders/gists{/gist_id}","starred_url":"https://api.github.com/users/gsanders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsanders/subscriptions","organizations_url":"https://api.github.com/users/gsanders/orgs","repos_url":"https://api.github.com/users/gsanders/repos","events_url":"https://api.github.com/users/gsanders/events{/privacy}","received_events_url":"https://api.github.com/users/gsanders/received_events","type":"User","site_admin":false},"repo":{"id":23676692,"name":"genome","full_name":"gsanders/genome","owner":{"login":"gsanders","id":863032,"avatar_url":"https://avatars.githubusercontent.com/u/863032?v=3","gravatar_id":"","url":"https://api.github.com/users/gsanders","html_url":"https://github.com/gsanders","followers_url":"https://api.github.com/users/gsanders/followers","following_url":"https://api.github.com/users/gsanders/following{/other_user}","gists_url":"https://api.github.com/users/gsanders/gists{/gist_id}","starred_url":"https://api.github.com/users/gsanders/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gsanders/subscriptions","organizations_url":"https://api.github.com/users/gsanders/orgs","repos_url":"https://api.github.com/users/gsanders/repos","events_url":"https://api.github.com/users/gsanders/events{/privacy}","received_events_url":"https://api.github.com/users/gsanders/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gsanders/genome","description":"","fork":true,"url":"https://api.github.com/repos/gsanders/genome","forks_url":"https://api.github.com/repos/gsanders/genome/forks","keys_url":"https://api.github.com/repos/gsanders/genome/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gsanders/genome/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gsanders/genome/teams","hooks_url":"https://api.github.com/repos/gsanders/genome/hooks","issue_events_url":"https://api.github.com/repos/gsanders/genome/issues/events{/number}","events_url":"https://api.github.com/repos/gsanders/genome/events","assignees_url":"https://api.github.com/repos/gsanders/genome/assignees{/user}","branches_url":"https://api.github.com/repos/gsanders/genome/branches{/branch}","tags_url":"https://api.github.com/repos/gsanders/genome/tags","blobs_url":"https://api.github.com/repos/gsanders/genome/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gsanders/genome/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gsanders/genome/git/refs{/sha}","trees_url":"https://api.github.com/repos/gsanders/genome/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gsanders/genome/statuses/{sha}","languages_url":"https://api.github.com/repos/gsanders/genome/languages","stargazers_url":"https://api.github.com/repos/gsanders/genome/stargazers","contributors_url":"https://api.github.com/repos/gsanders/genome/contributors","subscribers_url":"https://api.github.com/repos/gsanders/genome/subscribers","subscription_url":"https://api.github.com/repos/gsanders/genome/subscription","commits_url":"https://api.github.com/repos/gsanders/genome/commits{/sha}","git_commits_url":"https://api.github.com/repos/gsanders/genome/git/commits{/sha}","comments_url":"https://api.github.com/repos/gsanders/genome/comments{/number}","issue_comment_url":"https://api.github.com/repos/gsanders/genome/issues/comments/{number}","contents_url":"https://api.github.com/repos/gsanders/genome/contents/{+path}","compare_url":"https://api.github.com/repos/gsanders/genome/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gsanders/genome/merges","archive_url":"https://api.github.com/repos/gsanders/genome/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gsanders/genome/downloads","issues_url":"https://api.github.com/repos/gsanders/genome/issues{/number}","pulls_url":"https://api.github.com/repos/gsanders/genome/pulls{/number}","milestones_url":"https://api.github.com/repos/gsanders/genome/milestones{/number}","notifications_url":"https://api.github.com/repos/gsanders/genome/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gsanders/genome/labels{/name}","releases_url":"https://api.github.com/repos/gsanders/genome/releases{/id}","created_at":"2014-09-04T19:41:57Z","updated_at":"2014-09-04T19:44:39Z","pushed_at":"2015-02-17T21:47:25Z","git_url":"git://github.com/gsanders/genome.git","ssh_url":"git@github.com:gsanders/genome.git","clone_url":"https://github.com/gsanders/genome.git","svn_url":"https://github.com/gsanders/genome","homepage":"","size":109557,"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":"b85162a73549a98bb47925da66725297860aa369","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-02-19T20:22:37Z","pushed_at":"2015-02-19T20:25:09Z","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":122886,"stargazers_count":5,"watchers_count":5,"language":"Perl","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":34,"mirror_url":null,"open_issues_count":8,"forks":34,"open_issues":8,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/genome/genome/pulls/407"},"html":{"href":"https://github.com/genome/genome/pull/407"},"issue":{"href":"https://api.github.com/repos/genome/genome/issues/407"},"comments":{"href":"https://api.github.com/repos/genome/genome/issues/407/comments"},"review_comments":{"href":"https://api.github.com/repos/genome/genome/pulls/407/comments"},"review_comment":{"href":"https://api.github.com/repos/genome/genome/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/genome/genome/pulls/407/commits"},"statuses":{"href":"https://api.github.com/repos/genome/genome/statuses/70a3600107f4f82fdc94fcb1f037c2622ab06064"}}}}