annotate alignment/phytab_ssr.py @ 0:5b9a38ec4a39 draft default tip

First commit of old repositories
author osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
date Tue, 11 Mar 2014 12:19:13 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
1 #!/usr/bin/env python
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
2
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
3 import os
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
4 import optparse
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
5 import subprocess
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
6 from multiprocessing import Pool
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
7 from functools import partial
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
8
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
9 directory = ""
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
10 results = "results.data"
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
11 extension = ".fs"
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
12 slim_extension = ".slim"
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
13 jarpath='/home/galaxy/pkgs/SSR/SimilarSequenceRemover.jar'
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
14
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
15 def unescape(string):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
16 mapped_chars = {
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
17 '>': '__gt__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
18 '<': '__lt__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
19 "'": '__sq__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
20 '"': '__dq__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
21 '[': '__ob__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
22 ']': '__cb__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
23 '{': '__oc__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
24 '}': '__cc__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
25 '@': '__at__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
26 '\n': '__cn__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
27 '\r': '__cr__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
28 '\t': '__tc__',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
29 '#': '__pd__'
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
30 }
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
31
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
32 for key, value in mapped_chars.iteritems():
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
33 string = string.replace(value, key)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
34
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
35 return string
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
36
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
37
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
38 def isTabular(file):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
39 with open(file) as f:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
40 for line in f:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
41 if line[0] == '>':
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
42 return False
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
43 return True
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
44
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
45
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
46 def toData(text):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
47 text = text.split('\n')
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
48 result = ''
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
49 for line in text:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
50 if '>' in line:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
51 line = '\n' + line.replace('> ', "") + '\t'
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
52 line = line.replace(" ", "\t")
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
53 result += line
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
54 return result[1:] # Index past the first newline char
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
55
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
56 def toDataSingle(text):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
57 text = text.split('\n')
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
58 result = ''
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
59 for line in text:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
60 line = line + '\n'
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
61 result += line
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
62 return result[1:] # Index past the first newline char
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
63
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
64 def runSimilarSequenceRemover(input):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
65 input_name = directory + os.sep + input
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
66 outfasta = input_name + slim_extension
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
67 call = subprocess.call(['java','-jar', jarpath, '-i', input_name, '-o', outfasta, 's=' + percentage, '-h', alignallornot ])
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
68
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
69 class Sequence:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
70 def __init__(self, string):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
71 lis = string.split()
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
72 self.species = lis[0]
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
73 self.family = lis[1]
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
74 self.name = lis[2]
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
75 self.header = ' '.join(lis[:-1])
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
76 self.sequence = lis[-1]
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
77 self.string = string
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
78
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
79 def printFASTA(self):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
80 return '> ' + self.header + '\n' + self.sequence + '\n'
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
81
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
82
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
83 def saveMulti(tabFile):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
84 with open(tabFile) as f:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
85 for line in f:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
86 seq = Sequence(line)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
87 with open(directory + os.sep + seq.family + extension, "a") as p:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
88 p.write(seq.printFASTA())
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
89
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
90
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
91 def saveSingle(fastaFile):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
92 with open(fastaFile) as f:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
93 for line in f:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
94 with open(directory + os.sep + "fasta" + extension, "a") as p:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
95 p.write(line)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
96
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
97
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
98 def main():
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
99 usage = """%prog [options]
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
100 options (listed below) default to 'None' if omitted
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
101 """
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
102 parser = optparse.OptionParser(usage=usage)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
103
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
104 parser.add_option(
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
105 '-d', '--directory',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
106 metavar="PATH",
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
107 dest='path',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
108 default='.',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
109 help='Path to working directory.')
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
110
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
111 parser.add_option(
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
112 '-i', '--in',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
113 dest='input',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
114 action='store',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
115 type='string',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
116 metavar="FILE",
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
117 help='Name of input data.')
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
118
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
119 parser.add_option(
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
120 '-a', '--alignall',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
121 dest='alignall',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
122 action='store',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
123 type='string', help='t or f. t only aligns first 100 sites instead of entire seq')
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
124
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
125 parser.add_option(
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
126 '-s', '--similarity',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
127 dest='similarity',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
128 action='store',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
129 type='float',
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
130 help='Percentage similarity as cutoff (eg 0.99).')
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
131
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
132 options, args = parser.parse_args()
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
133
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
134 global directory
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
135 global percentage
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
136 global alignallornot
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
137 inputFile = unescape(options.input)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
138 directory = unescape(options.path) + os.sep + "data"
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
139 percentage = str(options.similarity)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
140 alignallornot = options.alignall
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
141
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
142 os.mkdir(directory)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
143
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
144 if isTabular(inputFile):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
145 saveMulti(inputFile)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
146 else:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
147 saveSingle(inputFile)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
148
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
149 pool = Pool()
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
150 list_of_files = [file for file in os.listdir(directory) if file.lower().endswith(extension)]
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
151 list_of_files = sorted(list_of_files)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
152
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
153 pool.map(runSimilarSequenceRemover, list_of_files)
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
154
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
155 result = [file for file in os.listdir(directory) if file.lower().endswith(slim_extension)]
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
156 if isTabular(inputFile):
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
157 with open(directory + os.sep + results, "a") as f:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
158 for file in result:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
159 with open(directory + os.sep + file, "r") as r:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
160 f.write(toData(r.read()) + "\n")
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
161 else:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
162 with open(directory + os.sep + results, "a") as f:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
163 for file in result:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
164 with open(directory + os.sep + file, "r") as r:
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
165 f.write(r.read() +'\n')
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
166
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
167 if __name__ == '__main__':
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
168 main()
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
169
5b9a38ec4a39 First commit of old repositories
osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu>
parents:
diff changeset
170