Skip to content

Commit

Permalink
script that reads nexus file
Browse files Browse the repository at this point in the history
  • Loading branch information
sun13005 committed Apr 21, 2017
1 parent 00e8a42 commit fbf6075
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions readseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,30 @@ def patterns():
assert len(parts) == 2
taxon_name = parts[0]
sequence = parts[1]
# print 'sequence===', sequence

taxon_names.append(taxon_name)
sequences_list.append(sequence)
sequences[taxon_name] = sequence



# print 'sequences dict==', sequences
# print 'sequences list==', sequences_list

pattern_list = []

k=0
while k < nchar:
site_pattern = ''
for i,m in enumerate(sequences_list):
site_pattern += m[k]
# print 'site_pattern=', site_pattern
pattern_list.append(site_pattern)
k+=1
# print '!!!!!!!!'
# print pattern_list
# print
pattern_dict = dict()
for i in pattern_list:
pattern_dict[i] = pattern_dict.get(i, 0) + 1 #http://www.pythonlearn.com/html-008/cfbook010.html#
pattern_dict[i] = pattern_dict.get(i, 0) + 1

# print'------------'
# print pattern_dict
# print
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
# print sorted_values
# print '**********'
# sorted_values.reverse() ###sorted according to key values larger to smaller
sorted_values.sort(cmp = lambda x,y:cmp(x[1],y[1])) ###sorted according to values in alphabetical order
# print sorted_values

Expand Down

0 comments on commit fbf6075

Please sign in to comment.