{"action":"created","issue":{"url":"https://api.github.com/repos/genometools/genometools/issues/793","repository_url":"https://api.github.com/repos/genometools/genometools","labels_url":"https://api.github.com/repos/genometools/genometools/issues/793/labels{/name}","comments_url":"https://api.github.com/repos/genometools/genometools/issues/793/comments","events_url":"https://api.github.com/repos/genometools/genometools/issues/793/events","html_url":"https://github.com/genometools/genometools/issues/793","id":153095827,"number":793,"title":"Possible error in phase calculation when a CDS segment is 1bp long","user":{"login":"lucventurini","id":8897821,"avatar_url":"https://avatars.githubusercontent.com/u/8897821?v=3","gravatar_id":"","url":"https://api.github.com/users/lucventurini","html_url":"https://github.com/lucventurini","followers_url":"https://api.github.com/users/lucventurini/followers","following_url":"https://api.github.com/users/lucventurini/following{/other_user}","gists_url":"https://api.github.com/users/lucventurini/gists{/gist_id}","starred_url":"https://api.github.com/users/lucventurini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucventurini/subscriptions","organizations_url":"https://api.github.com/users/lucventurini/orgs","repos_url":"https://api.github.com/users/lucventurini/repos","events_url":"https://api.github.com/users/lucventurini/events{/privacy}","received_events_url":"https://api.github.com/users/lucventurini/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/genometools/genometools/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":{"login":"satta","id":27732,"avatar_url":"https://avatars.githubusercontent.com/u/27732?v=3","gravatar_id":"","url":"https://api.github.com/users/satta","html_url":"https://github.com/satta","followers_url":"https://api.github.com/users/satta/followers","following_url":"https://api.github.com/users/satta/following{/other_user}","gists_url":"https://api.github.com/users/satta/gists{/gist_id}","starred_url":"https://api.github.com/users/satta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/satta/subscriptions","organizations_url":"https://api.github.com/users/satta/orgs","repos_url":"https://api.github.com/users/satta/repos","events_url":"https://api.github.com/users/satta/events{/privacy}","received_events_url":"https://api.github.com/users/satta/received_events","type":"User","site_admin":false},"assignees":[{"login":"satta","id":27732,"avatar_url":"https://avatars.githubusercontent.com/u/27732?v=3","gravatar_id":"","url":"https://api.github.com/users/satta","html_url":"https://github.com/satta","followers_url":"https://api.github.com/users/satta/followers","following_url":"https://api.github.com/users/satta/following{/other_user}","gists_url":"https://api.github.com/users/satta/gists{/gist_id}","starred_url":"https://api.github.com/users/satta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/satta/subscriptions","organizations_url":"https://api.github.com/users/satta/orgs","repos_url":"https://api.github.com/users/satta/repos","events_url":"https://api.github.com/users/satta/events{/privacy}","received_events_url":"https://api.github.com/users/satta/received_events","type":"User","site_admin":false}],"milestone":null,"comments":8,"created_at":"2016-05-04T19:32:08Z","updated_at":"2016-07-01T13:44:20Z","closed_at":null,"body":"#It seems that GenomeTools is treating 1bp CDS exons in the wrong way when calculating the phase, by considering them as length 2 instead of 1. \r\n\r\nPrologue: to calculate phases in a tool I am working on, I am using the following function:\r\n```\r\ndef __calculate_phases(coding, previous):\r\n\r\n    # Previous indicates whether the record began with a phase different from 0\r\n    # for incomplete gene models\r\n    total_cds_length = -previous\r\n\r\n    __calculated_phases = []\r\n    for cds_segment in coding:\r\n        length = cds_segment[1][1] - cds_segment[1][0] + 1\r\n        phase = (3 - (total_cds_length % 3)) % 3\r\n        total_cds_length += length\r\n        __calculated_phases.append(phase)\r\n\r\n    return total_cds_length, __calculated_phases\r\n```\r\nI am not sure it is correct as I have not been able to find the relevant corresponding section in the GenomeTools codebase. \r\n\r\nIn my case, I have the following GFF entry:\r\n\r\n```\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tgene\t40282\t46004\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960;Name=TRIAE_CS42_5DL_TGACv1_434051_AA1427960;biotype=protein_coding;confidence=High\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tmRNA\t40282\t46004\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960;Name=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2;aed=0.0;note=TRIAE_CS42_5DL_TGACv1_434051_AA1427960;confidence=High;has_start=True;has_stop=True;original_stop=True;protein_rank=P1;transcript_rank=T2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t40282\t40933\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon1;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tthree_prime_UTR\t40282\t40720\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.three_prime_UTR1;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t40721\t40933\t.\t-\t0\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS1;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t41018\t41111\t.\t-\t1\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS2;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t41018\t41111\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon2;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t41227\t41468\t.\t-\t0\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS3;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t41227\t41468\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon3;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t41673\t41831\t.\t-\t0\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS4;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t41673\t41831\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon4;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t41946\t42820\t.\t-\t2\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS5;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t41946\t42820\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon5;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t42905\t42913\t.\t-\t2\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS6;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t42905\t42913\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon6;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t45373\t45496\t.\t-\t0\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS7;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t45373\t45496\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon7;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t45600\t45651\t.\t-\t1\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS8;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t45600\t45651\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon8;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t45726\t45726\t.\t-\t2\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS9;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t45726\t45726\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon9;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tCDS\t45875\t45893\t.\t-\t0\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.CDS10;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\texon\t45875\t46004\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.exon10;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\nTriticum_aestivum_CS42_TGACv1_scaffold_434051_5DL\tTGACv1\tfive_prime_UTR\t45894\t46004\t.\t-\t.\tID=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2.five_prime_UTR1;Parent=TRIAE_CS42_5DL_TGACv1_434051_AA1427960.2\r\n```\r\n\r\nThe gt gff3 tool (latest release, version 1.5.8, linux x86_64 binaries) complains that the phase is incorrect for this entry, with the following error:\r\n\r\n```\r\nwarning: CDS feature on line 19 in file \"stdin\" has the wrong phase 1 -> correcting it to 0\r\nwarning: CDS feature on line 17 in file \"stdin\" has the wrong phase 0 -> correcting it to 2\r\nwarning: CDS feature on line 15 in file \"stdin\" has the wrong phase 2 -> correcting it to 1\r\nwarning: CDS feature on line 13 in file \"stdin\" has the wrong phase 2 -> correcting it to 1\r\nwarning: CDS feature on line 11 in file \"stdin\" has the wrong phase 0 -> correcting it to 2\r\nwarning: CDS feature on line 9 in file \"stdin\" has the wrong phase 0 -> correcting it to 2\r\nwarning: CDS feature on line 7 in file \"stdin\" has the wrong phase 1 -> correcting it to 0\r\nwarning: CDS feature on line 6 in file \"stdin\" has the wrong phase 0 -> correcting it to 2\r\n```\r\n\r\nThe complaints begin after line 21, ie an exon/CDS line with length 1 (45276 .. 45276). \r\nThis seems wrong to me, for the following reasons:\r\n\r\n1- If I have understood the method of calculation right, the phase should be calculated by taking the modulo 3 of the amount of sequence already met before encountering the current CDS segment; see the code at the beginning of the issue report.\r\n\r\n   My function agrees with the phases present in the input GFF record I pasted in the comment, but not with GenomeTools; it reports the total CDS length as being 1788 ie a number divisible by 3.\r\n\r\n2 - I can obtain the same results as GenomeTools in terms of phases by adding 2 instead of 1 to the total_cds_length variable when encountering the 1-bp exon:\r\n\r\n```\r\ndef __calculate_phases(coding, previous):\r\n    # Previous indicates whether the record began with a phase different from 0\r\n    # for incomplete gene models\r\n\r\n    total_cds_length = -previous\r\n\r\n    __calculated_phases = []\r\n    for cds_segment in coding:\r\n        length = cds_segment[1][1] - cds_segment[1][0] + 1\r\n        # This agrees with GenomeTools\r\n        if length == 1:\r\n             length += 1\r\n        phase = (3 - (total_cds_length % 3)) % 3\r\n        total_cds_length += length\r\n        __calculated_phases.append(phase)\r\n\r\n    return total_cds_length, __calculated_phases\r\n```\r\n\r\nThe result in this case will agree with GenomeTools regarding the phases, *but the total CDS length will be incorrect (1789, and 1789 % 3 == 1)*. This seems quite wrong."},"comment":{"url":"https://api.github.com/repos/genometools/genometools/issues/comments/229950239","html_url":"https://github.com/genometools/genometools/issues/793#issuecomment-229950239","issue_url":"https://api.github.com/repos/genometools/genometools/issues/793","id":229950239,"user":{"login":"satta","id":27732,"avatar_url":"https://avatars.githubusercontent.com/u/27732?v=3","gravatar_id":"","url":"https://api.github.com/users/satta","html_url":"https://github.com/satta","followers_url":"https://api.github.com/users/satta/followers","following_url":"https://api.github.com/users/satta/following{/other_user}","gists_url":"https://api.github.com/users/satta/gists{/gist_id}","starred_url":"https://api.github.com/users/satta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/satta/subscriptions","organizations_url":"https://api.github.com/users/satta/orgs","repos_url":"https://api.github.com/users/satta/repos","events_url":"https://api.github.com/users/satta/events{/privacy}","received_events_url":"https://api.github.com/users/satta/received_events","type":"User","site_admin":false},"created_at":"2016-07-01T13:44:20Z","updated_at":"2016-07-01T13:44:20Z","body":"Reopening until the corner case is fixed as well."}}
{"actor":{"display_login":"satta"}}