Commit c7d63a16 authored by Mathieu Giraud's avatar Mathieu Giraud

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

Thanks to
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:
for f in recombination[gene]:
if f not in files:
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):
def write_seq_to_file(seq, code, file):
def write_seq_to_file(seq, code, f):
seq.header = seq.header.replace(' ', '_')+"__"+code
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):
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):
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:
for cid in ids_1_cut:
### 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]:
......@@ -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)
# 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")
f = open(filename, "w")
def extract_tangle(content, names=None):
......@@ -41,10 +41,10 @@ def extract_tangle(content, names=None):
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'],
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