Commit c7d63a16 authored by Mathieu Giraud's avatar Mathieu Giraud

*.py: code cleaning, no built-in redefinitions

Thanks to landscape.io.
parent 441657bd
......@@ -15,9 +15,9 @@ def get_required_files(germlines_data):
for recombination in germlines_json[germline]['recombinations']:
for gene in ['5', '4', '3']:
if gene in recombination:
for file in recombination[gene]:
if file not in files:
files.append(file)
for f in recombination[gene]:
if f not in files:
files.append(f)
return files
if len(sys.argv) != 3:
......
......@@ -52,8 +52,8 @@ def parse(fasta, endline=''):
if header or sequence:
yield (header, sequence)
def extract_field_if_exists(str, separator, field_number):
fields = str.split(separator)
def extract_field_if_exists(s, separator, field_number):
fields = s.split(separator)
if len(fields) > field_number:
return fields[field_number]
return str
......
......@@ -206,9 +206,9 @@ def get_gene_name(allele):
return allele.name[:allele.name.find('*')]
def write_seq_to_file(seq, code, file):
def write_seq_to_file(seq, code, f):
seq.header = seq.header.replace(' ', '_')+"__"+code
file.write(str(seq))
f.write(str(seq))
def generate_to_file(repertoire, recombination, code, f, nb_recomb):
print(" ==>", f)
......@@ -223,9 +223,9 @@ def generate_to_file(repertoire, recombination, code, f, nb_recomb):
def list_random_tuple(s):
try:
list = s.split(':')
list_r = s.split(':')
result_list = []
for item in list:
for item in list_r:
one, two = map(float, item.split(','))
result_list.append((lambda: random_pos_int(one, two)))
return result_list
......
......@@ -94,7 +94,7 @@ def store_data_if_updownstream(fasta_header, path, data, genes):
data[path+'/'+gene][gene_name].append(gene_coord)
def retrieve_genes(filename, genes, additional_length):
file = verbose_open_w(filename)
f = verbose_open_w(filename)
for gene in genes:
for coord in genes[gene]:
start = coord['from']
......@@ -103,7 +103,7 @@ def retrieve_genes(filename, genes, additional_length):
end += additional_length
elif additional_length < 0:
start = max(1, start + additional_length)
file.write(get_gene_sequence(gene, coord['imgt_name'], start, end))
f.write(get_gene_sequence(gene, coord['imgt_name'], start, end))
# Phe
......
......@@ -128,8 +128,8 @@ def compare(data1, data2, args):
ids_1_cut = ids_1[:args.nb] if args.nb else ids_1
for id in ids_1_cut:
print_clone_in_self_and_others(id)
for cid in ids_1_cut:
print_clone_in_self_and_others(cid)
### Display clones of other ListWindows not present in this ListWindows
if args.verbose:
......@@ -137,10 +137,10 @@ def compare(data1, data2, args):
print("==== Other clones in the top %d of other files" % args.nb_others)
for o in [ids_2]:
for id in o[:args.nb_others]:
if id in ids_1[:args.nb]:
for cid in o[:args.nb_others]:
if cid in ids_1[:args.nb]:
continue
print_clone_in_self_and_others(id)
print_clone_in_self_and_others(cid)
......
......@@ -117,8 +117,8 @@ class Window:
return obj
def get_nb_reads(self, id, point=0):
return self[id]["reads"][point]
def get_nb_reads(self, cid, point=0):
return self[cid]["reads"][point]
def latex(self, point=0, base_germline=10000, base=10000, tag=''):
reads = self.d["reads"][point]
......@@ -309,8 +309,8 @@ class ListWindows(VidjilJson):
def save_json(self, output):
'''save ListWindows in .json format'''
print("==>", output)
with open(output, "w") as file:
json.dump(self, file, indent=2, default=self.toJson)
with open(output, "w") as f:
json.dump(self, f, indent=2, default=self.toJson)
def load(self, file_path, *args, **kwargs):
if not '.clntab' in file_path:
......@@ -328,8 +328,8 @@ class ListWindows(VidjilJson):
if verbose:
print("<==", file_path, "\t", end=' ')
with open(file_path, "r") as file:
tmp = json.load(file, object_hook=self.toPython)
with open(file_path, "r") as f:
tmp = json.load(f, object_hook=self.toPython)
self.d=tmp.d
# Be robust against 'null' values for clones
if not self.d["clones"]:
......
......@@ -13,9 +13,9 @@ parser.add_argument('file', nargs='?', type=argparse.FileType('r'), default=sys.
args = parser.parse_args()
def export_tangle(filename, content):
file = open(filename, "w")
file.write(content)
file.close()
f = open(filename, "w")
f.write(content)
f.close()
def extract_tangle(content, names=None):
r'''
......@@ -41,10 +41,10 @@ def extract_tangle(content, names=None):
tangles.append(current_tangle)
return tangles
def extract_tangle_and_output(content, dir, names=None):
def extract_tangle_and_output(content, dirname, names=None):
tangles = extract_tangle(content, names)
for result in tangles:
export_tangle(dir + os.sep + result['filename'],
export_tangle(dirname + os.sep + result['filename'],
result['content'])
if args.test:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment