{"action":"created","issue":{"url":"https://api.github.com/repos/arq5x/bedtools2/issues/381","repository_url":"https://api.github.com/repos/arq5x/bedtools2","labels_url":"https://api.github.com/repos/arq5x/bedtools2/issues/381/labels{/name}","comments_url":"https://api.github.com/repos/arq5x/bedtools2/issues/381/comments","events_url":"https://api.github.com/repos/arq5x/bedtools2/issues/381/events","html_url":"https://github.com/arq5x/bedtools2/issues/381","id":139893674,"number":381,"title":"shuffleBed with -incl does not take interval length into account","user":{"login":"michael-imbeault","id":7590794,"avatar_url":"https://avatars.githubusercontent.com/u/7590794?v=3","gravatar_id":"","url":"https://api.github.com/users/michael-imbeault","html_url":"https://github.com/michael-imbeault","followers_url":"https://api.github.com/users/michael-imbeault/followers","following_url":"https://api.github.com/users/michael-imbeault/following{/other_user}","gists_url":"https://api.github.com/users/michael-imbeault/gists{/gist_id}","starred_url":"https://api.github.com/users/michael-imbeault/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michael-imbeault/subscriptions","organizations_url":"https://api.github.com/users/michael-imbeault/orgs","repos_url":"https://api.github.com/users/michael-imbeault/repos","events_url":"https://api.github.com/users/michael-imbeault/events{/privacy}","received_events_url":"https://api.github.com/users/michael-imbeault/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-03-10T13:58:21Z","updated_at":"2016-03-30T23:35:14Z","closed_at":null,"body":"Using shufflebed with the -incl option leads to unexpected behavior, and after checking the source code it appears that it selects a random interval within -incl without taking the length of the intervals into account.\r\n\r\nSimple scenario: shuffle a bed within a set of regions comprising 9 regions of 1000 bp and 1 region of 100000 bp leads to an even distribution between all the intervals, when it could reasonably be expected that the large region would receive more intervals from the shuffled bed."},"comment":{"url":"https://api.github.com/repos/arq5x/bedtools2/issues/comments/203684586","html_url":"https://github.com/arq5x/bedtools2/issues/381#issuecomment-203684586","issue_url":"https://api.github.com/repos/arq5x/bedtools2/issues/381","id":203684586,"user":{"login":"arq5x","id":72291,"avatar_url":"https://avatars.githubusercontent.com/u/72291?v=3","gravatar_id":"","url":"https://api.github.com/users/arq5x","html_url":"https://github.com/arq5x","followers_url":"https://api.github.com/users/arq5x/followers","following_url":"https://api.github.com/users/arq5x/following{/other_user}","gists_url":"https://api.github.com/users/arq5x/gists{/gist_id}","starred_url":"https://api.github.com/users/arq5x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arq5x/subscriptions","organizations_url":"https://api.github.com/users/arq5x/orgs","repos_url":"https://api.github.com/users/arq5x/repos","events_url":"https://api.github.com/users/arq5x/events{/privacy}","received_events_url":"https://api.github.com/users/arq5x/received_events","type":"User","site_admin":false},"created_at":"2016-03-30T23:35:14Z","updated_at":"2016-03-30T23:35:14Z","body":"Thinking about this some more, simply weighting by length will bias towards chromosomes with a greater total ``-incl`` length anyway. @zeeev just submitted a PR (https://github.com/arq5x/bedtools2/pull/386) with a nice weighted sampling approach that, based on my tests, works the way you'd want:\r\n\r\n    cat a.bed\r\n    chr1\t0\t10\r\n\r\n    cat i.bed\r\n    chr1\t0\t20\tA\r\n    chr1\t50\t70\tB\r\n    chr2\t50\t60\tC\r\n    chr3\t80\t90\tD\r\n\r\n    cat g.txt \r\n    chr1\t100\r\n\r\nSo, we would expect intervals to be shuffled to within A 33% of the time, and chr1 67% of the time. Let us see:\r\n\r\n    for i in {1..30000}; \r\n    do; \r\n        bedtools shuffle -i a.bed -incl i.bed -g g.txt \\\r\n        | bedtools intersect -a - -b i.bed -wa -wb \\\r\n        | cut -f 7; \r\n    done \r\n    | sort | uniq -c\r\n    \r\n    9828 A\r\n    9874 B\r\n    5295 C\r\n    5003 D\r\n    "}}