Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #2 from sun13005/brnlenMCMC
Brnlen mcmc
- Loading branch information
Showing
14 changed files
with
241 additions
and
989 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
def patterns(): | ||
# | ||
import re, os, glob, itertools, fnmatch, sys, shutil | ||
from itertools import combinations | ||
from collections import Counter | ||
|
||
script_dir = os.path.dirname(os.path.realpath(sys.argv[0])) | ||
# path = os.path.join(script_dir, 'nexus') | ||
|
||
genes = [] | ||
data = {} | ||
# print 'Reading nexus files...' | ||
for filename in glob.glob(os.path.join(script_dir, '*.nex')): | ||
|
||
m = re.match('(.+).nex', os.path.basename(filename)) | ||
gene_name = m.group(1) | ||
# print 'gene_name=', gene_name | ||
genes.append(gene_name) | ||
f = open(filename, 'r').read() | ||
|
||
m = re.search('ntax\s*=\s*(\d+)', f, re.M | re.S) | ||
ntax = int(m.group(1)) | ||
# print 'ntax=', ntax | ||
|
||
m = re.search('nchar\s*=\s*(\d+)', f, re.M | re.S) | ||
nchar = int(m.group(1)) | ||
# print 'nchar=', nchar | ||
|
||
m = re.search('Matrix\s+(.+?);', f, re.M | re.S) | ||
matrix = m.group(1).strip() | ||
matrix_lines = matrix.split('\n') | ||
|
||
taxon_names = [] | ||
sequences = {} | ||
sequences_list = [] | ||
for line in matrix_lines: | ||
parts = line.strip().split() | ||
assert len(parts) == 2 | ||
taxon_name = parts[0] | ||
sequence = parts[1] | ||
|
||
taxon_names.append(taxon_name) | ||
sequences_list.append(sequence) | ||
sequences[taxon_name] = sequence | ||
|
||
pattern_list = [] | ||
|
||
k=0 | ||
while k < nchar: | ||
site_pattern = '' | ||
for i,m in enumerate(sequences_list): | ||
site_pattern += m[k] | ||
pattern_list.append(site_pattern) | ||
k+=1 | ||
pattern_dict = dict() | ||
for i in pattern_list: | ||
pattern_dict[i] = pattern_dict.get(i, 0) + 1 | ||
|
||
tmp = [] | ||
for key in pattern_dict.keys(): ###convert dict to key of tupules | ||
# print 'key=', key | ||
tmp.append((pattern_dict[key],key)) | ||
|
||
sorted_values = sorted(tmp) ###sorted according to key smaller to larger | ||
sorted_values.sort(cmp = lambda x,y:cmp(x[1],y[1])) ###sorted according to values in alphabetical order | ||
|
||
return pattern_dict | ||
|
||
|
Binary file not shown.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(((1:0.54019,(5:0.40299,10:0.40299):0.1372):0.72686,(6:0.10576,4:0.10576):1.16129):0.42537,(2:0.58122,(9:0.21295,(7:0.16691,(8:0.14622,3:0.14622):0.02069):0.04604):0.36827):1.1112) |
Oops, something went wrong.