Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert six assignment statements to augmented source code #27

Open
elfring opened this issue Jan 24, 2023 · 2 comments
Open

Convert six assignment statements to augmented source code #27

elfring opened this issue Jan 24, 2023 · 2 comments

Comments

@elfring
Copy link

elfring commented Jan 24, 2023

👀 Some source code analysis tools can help to find opportunities for improving software components.
💭 I propose to increase the usage of augmented assignment statements accordingly.

diff --git a/fdog/libs/addtaxon.py b/fdog/libs/addtaxon.py
index 8e38620..b25b3b3 100644
--- a/fdog/libs/addtaxon.py
+++ b/fdog/libs/addtaxon.py
@@ -91,7 +91,7 @@ def create_genome(args):
             ### check if id longer than 20 character
             if len(id) > 20:
                 long_id = 1
-                mod_id_index = mod_id_index + 1
+                mod_id_index += 1
                 id = '%s_%s' % (spec_name.split('@')[1], mod_id_index)
                 if not ori_id in id_dict:
                     id_dict[ori_id] = id
@@ -157,7 +157,7 @@ def create_annoFile(outPath, genome_file, cpus, force):
     """ Create annotation json for a given genome_file """
     annoCmd = 'fas.doAnno -i %s -o %s --cpus %s' % (genome_file, outPath+'/annotation_dir', cpus)
     if force:
-        annoCmd = annoCmd + " --force"
+        annoCmd += " --force"
     try:
         subprocess.call([annoCmd], shell = True)
     except:
diff --git a/fdog/libs/alignment.py b/fdog/libs/alignment.py
index 507eaa5..7c1699c 100644
--- a/fdog/libs/alignment.py
+++ b/fdog/libs/alignment.py
@@ -123,5 +123,5 @@ def calc_aln_score(fa1, fa2, aln_strategy = 'local', debugCore = False):
             if gene_id in aln_score:
                 if re.search('\(\s+\d+\)', l):
                     l = re.sub(r'\(\s+','(', l)
-                aln_score[gene_id] = aln_score[gene_id] + int(l.split()[2])
+                aln_score[gene_id] += int(l.split()[2])
     return(aln_score)
diff --git a/fdog/libs/blast.py b/fdog/libs/blast.py
index ff41608..3c8dc5d 100644
--- a/fdog/libs/blast.py
+++ b/fdog/libs/blast.py
@@ -75,7 +75,7 @@ def make_blastdb(args):
     (specName, specFile, outPath, silent) = args
     blastCmd = 'makeblastdb -dbtype prot -in %s -out %s/coreTaxa_dir/%s/%s' % (specFile, outPath, specName, specName)
     if silent == True:
-        blastCmd = blastCmd + '> /dev/null 2>&1'
+        blastCmd += '> /dev/null 2>&1'
     try:
         subprocess.call([blastCmd], shell = True)
     except:
diff --git a/fdog/libs/zzz.py b/fdog/libs/zzz.py
index 219ac76..8bd4f22 100644
--- a/fdog/libs/zzz.py
+++ b/fdog/libs/zzz.py
@@ -87,10 +87,10 @@ def count_line(file, pattern, contain):
         for line in f:
             if contain:
                 if pattern in line:
-                    nline = nline + 1
+                    nline += 1
             else:
                 if not pattern in line:
-                    nline = nline + 1
+                    nline += 1
     return(nline)
 
 
@trvinh
Copy link
Member

trvinh commented Jan 24, 2023

@elfring I will check this soon :) May I ask which code analysis tool did you use above? Many thanks!

@elfring
Copy link
Author

elfring commented Jan 24, 2023

🤔 How do you think about to improve source code transformation tools accordingly?

Markus_Elfring@Sonne:…/Projekte/fDOG/lokal> perl -p -i.orig -0777 -e 's/^(?<indentation>\s+)(?<target>\S+)\s*=\s*\k<target>[ \t]*(?<operator>[+\-%&|^@]|\*\*?|\/\/?|<<|>>)/$+{indentation}$+{target} $+{operator}=/gm' $(find -name '*.py')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants