{"action":"created","issue":{"url":"https://api.github.com/repos/biojava/biojava/issues/88","repository_url":"https://api.github.com/repos/biojava/biojava","labels_url":"https://api.github.com/repos/biojava/biojava/issues/88/labels{/name}","comments_url":"https://api.github.com/repos/biojava/biojava/issues/88/comments","events_url":"https://api.github.com/repos/biojava/biojava/issues/88/events","html_url":"https://github.com/biojava/biojava/issues/88","id":25853380,"number":88,"title":"getSymmetryOrder(AFPChain) gives unexpected results","user":{"login":"dmyersturnbull","id":3979879,"avatar_url":"https://avatars.githubusercontent.com/u/3979879?v=3","gravatar_id":"","url":"https://api.github.com/users/dmyersturnbull","html_url":"https://github.com/dmyersturnbull","followers_url":"https://api.github.com/users/dmyersturnbull/followers","following_url":"https://api.github.com/users/dmyersturnbull/following{/other_user}","gists_url":"https://api.github.com/users/dmyersturnbull/gists{/gist_id}","starred_url":"https://api.github.com/users/dmyersturnbull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmyersturnbull/subscriptions","organizations_url":"https://api.github.com/users/dmyersturnbull/orgs","repos_url":"https://api.github.com/users/dmyersturnbull/repos","events_url":"https://api.github.com/users/dmyersturnbull/events{/privacy}","received_events_url":"https://api.github.com/users/dmyersturnbull/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/biojava/biojava/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":{"login":"sbliven","id":595872,"avatar_url":"https://avatars.githubusercontent.com/u/595872?v=3","gravatar_id":"","url":"https://api.github.com/users/sbliven","html_url":"https://github.com/sbliven","followers_url":"https://api.github.com/users/sbliven/followers","following_url":"https://api.github.com/users/sbliven/following{/other_user}","gists_url":"https://api.github.com/users/sbliven/gists{/gist_id}","starred_url":"https://api.github.com/users/sbliven/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbliven/subscriptions","organizations_url":"https://api.github.com/users/sbliven/orgs","repos_url":"https://api.github.com/users/sbliven/repos","events_url":"https://api.github.com/users/sbliven/events{/privacy}","received_events_url":"https://api.github.com/users/sbliven/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/biojava/biojava/milestones/6","html_url":"https://github.com/biojava/biojava/milestones/BioJava%204.2.0","labels_url":"https://api.github.com/repos/biojava/biojava/milestones/6/labels","id":1172839,"number":6,"title":"BioJava 4.2.0","description":"","creator":{"login":"andreasprlic","id":187599,"avatar_url":"https://avatars.githubusercontent.com/u/187599?v=3","gravatar_id":"","url":"https://api.github.com/users/andreasprlic","html_url":"https://github.com/andreasprlic","followers_url":"https://api.github.com/users/andreasprlic/followers","following_url":"https://api.github.com/users/andreasprlic/following{/other_user}","gists_url":"https://api.github.com/users/andreasprlic/gists{/gist_id}","starred_url":"https://api.github.com/users/andreasprlic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andreasprlic/subscriptions","organizations_url":"https://api.github.com/users/andreasprlic/orgs","repos_url":"https://api.github.com/users/andreasprlic/repos","events_url":"https://api.github.com/users/andreasprlic/events{/privacy}","received_events_url":"https://api.github.com/users/andreasprlic/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":35,"state":"open","created_at":"2015-06-19T18:16:59Z","updated_at":"2016-03-08T13:51:33Z","due_on":"2016-03-09T08:00:00Z","closed_at":null},"comments":2,"created_at":"2014-01-18T04:11:59Z","updated_at":"2016-03-08T14:42:00Z","closed_at":null,"body":"This first snippet seems to return 1:\r\n```\r\nint order = getSymmetryOrder(afpChain, 8, 0.4f);\r\n```\r\nThis snipped does what I expect:\r\n```\r\nMap<Integer,Integer> alignment = AlignmentTools.alignmentAsMap(afpChain);\r\nint order = AlignmentTools.getSymmetryOrder(alignment, new AlignmentTools.IdentityMap<Integer>(), 8, 0.4f);\r\n```\r\n\r\nWhat is the difference between these two overloaded methods?"},"comment":{"url":"https://api.github.com/repos/biojava/biojava/issues/comments/193809048","html_url":"https://github.com/biojava/biojava/issues/88#issuecomment-193809048","issue_url":"https://api.github.com/repos/biojava/biojava/issues/88","id":193809048,"user":{"login":"sbliven","id":595872,"avatar_url":"https://avatars.githubusercontent.com/u/595872?v=3","gravatar_id":"","url":"https://api.github.com/users/sbliven","html_url":"https://github.com/sbliven","followers_url":"https://api.github.com/users/sbliven/followers","following_url":"https://api.github.com/users/sbliven/following{/other_user}","gists_url":"https://api.github.com/users/sbliven/gists{/gist_id}","starred_url":"https://api.github.com/users/sbliven/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sbliven/subscriptions","organizations_url":"https://api.github.com/users/sbliven/orgs","repos_url":"https://api.github.com/users/sbliven/repos","events_url":"https://api.github.com/users/sbliven/events{/privacy}","received_events_url":"https://api.github.com/users/sbliven/received_events","type":"User","site_admin":false},"created_at":"2016-03-08T14:41:59Z","updated_at":"2016-03-08T14:41:59Z","body":"I looked into this.\r\n\r\nI can in fact reproduce the bug with highly-symmetric cases where you would expect the SequenceFunctionOrderDetector to work well:\r\n```\r\n\tpublic static void main(String[] args) throws IOException, StructureException {\r\n\t\tString name = \"1itb.A\";\r\n\t\tStructure s = StructureIO.getStructure(name);\r\n\t\tAtom[] ca = StructureTools.getRepresentativeAtomArray(s);\r\n\t\tCeSymmResult result = CeSymm.analyze(ca);\r\n\t\tAFPChain afp = result.getSelfAlignment();\r\n\t\t\r\n\t\tint order1 = AlignmentTools.getSymmetryOrder(afp, 8, .4f);\r\n\t\tMap<Integer,Integer> alignment = AlignmentTools.alignmentAsMap(afp);\r\n\t\tint order2 = AlignmentTools.getSymmetryOrder(alignment, new AlignmentTools.IdentityMap<Integer>(), 8, 0.4f);\r\n\t\tSystem.out.format(\"order1=%d%norder2=%d%n\",order1,order2);\r\n\t}\r\n```\r\n(Yields `order1=1 order2=3`)\r\n\r\nThese methods are part of SymmetryTools, but they were actually written without assuming that the rows of the alignment correspond to the same protein. This was useful when looking at the symmetry of CE-CP alignments, although now I wonder if those results can actually be trusted. Anyways, the methods require an _identity alignment_ which gives a sequential alignment between the residues in each structure of the multiple alignment. For internal symmetry, where the structures are truly identical, an IdentityMap should be used. Thus, the second method is the correct way to calculate the order for internal symmetry. Unfortunately, if no identity alignment is manually specified, it uses the very naive `guessSequentialAlignment` instead. This method assumes that the input alignment is refined (or nearly so). This makes it quite sensitive to gaps in coverage and to register shifts in the self alignment, and it seems to give bad results even in highly-symmetric cases like 1itb.A (beta-trefoil).\r\n\r\nWith a refined alignment, `guessSequentialAlignment` is equivalent to the IdentityMap, so the method works as expected (with some ugly adaptor code to fit CeSymmResults into the old AFPChain-expecting framework):\r\n\r\n```\r\n\t\tMultipleAlignment ma = SymmetryTools.toFullAlignment(result);\r\n\t\tList<Atom[]> atoms = ma.getAtomArrays();\r\n\t\talignment.clear();\r\n\t\tfor(Block block : ma.getBlocks()) {\r\n\t\t\tList<List<Integer>> aln = block.getAlignRes();\r\n\t\t\tfor(int i = 0; i<block.length();i++) {\r\n\t\t\t\talignment.put(aln.get(0).get(i),aln.get(1).get(i));\r\n\t\t\t}\r\n\t\t}\r\n\t\tafp = replaceOptAln(afp, atoms.get(0), atoms.get(1), alignment);\r\n\t\tint order3 = AlignmentTools.getSymmetryOrder(afp, 8, .4f);\r\n```\r\n\r\nTLDR: This is expected. I'll add a note to the documentation and close this issue."}}