Commit 765b2492 authored by Thomas Van Parys's avatar Thomas Van Parys
Browse files

Make linter happy

parent 84f68594
#!/usr/bin/env python3 #!/usr/bin/env python3
import readline
import attr import attr
import sys import sys
import click import click
...@@ -11,6 +10,7 @@ from prettytable import PrettyTable ...@@ -11,6 +10,7 @@ from prettytable import PrettyTable
import cedalion.scripts.plaza_api as plaza import cedalion.scripts.plaza_api as plaza
class bcolors: class bcolors:
HEADER = '\033[95m' HEADER = '\033[95m'
OKBLUE = '\033[94m' OKBLUE = '\033[94m'
...@@ -38,17 +38,16 @@ class bcolors: ...@@ -38,17 +38,16 @@ class bcolors:
@staticmethod @staticmethod
def message(msg): def message(msg):
return bcolors.OKGREEN + msg + bcolors.ENDC return bcolors.OKGREEN + msg + bcolors.ENDC
@staticmethod @staticmethod
def warning(msg): def warning(msg):
return bcolors.WARNING + msg + bcolors.ENDC return bcolors.WARNING + msg + bcolors.ENDC
@staticmethod @staticmethod
def error(msg): def error(msg):
return bcolors.FAIL + msg + bcolors.ENDC return bcolors.FAIL + msg + bcolors.ENDC
@attr.s @attr.s
class SpeciesEntry(object): class SpeciesEntry(object):
cedalionId: str = attr.ib() cedalionId: str = attr.ib()
...@@ -72,17 +71,18 @@ class SpeciesEntry(object): ...@@ -72,17 +71,18 @@ class SpeciesEntry(object):
@staticmethod @staticmethod
def getOutputHeader(): def getOutputHeader():
return '\t'.join(SpeciesEntry.columnHeaders) return '\t'.join(SpeciesEntry.columnHeaders)
def getOutputRow(self): def getOutputRow(self):
return '\t'.join([self.cedalionId, self.longName, self.role, self.plazaId, self.proteome, self.cds, self.gff3]) return '\t'.join([self.cedalionId, self.longName, self.role, self.plazaId, self.proteome, self.cds, self.gff3])
def getAsList(self): def getAsList(self):
return [self.cedalionId, self.longName, self.role, self.plazaId, self.proteome, self.cds, self.gff3] return [self.cedalionId, self.longName, self.role, self.plazaId, self.proteome, self.cds, self.gff3]
def parseSpeciesFile(species_file_name): def parseSpeciesFile(species_file_name):
import csv import csv
entries=[] entries = []
with open(species_file_name) as species_file: with open(species_file_name) as species_file:
reader = csv.DictReader(species_file, delimiter='\t') reader = csv.DictReader(species_file, delimiter='\t')
for row in reader: for row in reader:
...@@ -95,10 +95,10 @@ def parseSpeciesFile(species_file_name): ...@@ -95,10 +95,10 @@ def parseSpeciesFile(species_file_name):
gff3=row['gff3'] if row['gff3'] else '' gff3=row['gff3'] if row['gff3'] else ''
) )
entries.append(entry) entries.append(entry)
return entries return entries
@click.command() @click.command()
@click.argument('species_file', @click.argument('species_file',
nargs=1, required=False, nargs=1, required=False,
...@@ -129,7 +129,7 @@ def prompt(species_file): ...@@ -129,7 +129,7 @@ def prompt(species_file):
table.align['Proteome file'] = 'l' table.align['Proteome file'] = 'l'
table.align['CDS file'] = 'l' table.align['CDS file'] = 'l'
table.align['GFF3 file'] = 'l' table.align['GFF3 file'] = 'l'
n = 1 n = 1
for e in entries: for e in entries:
table.add_row([bcolors.mark(str(n))] + e.getAsList()) table.add_row([bcolors.mark(str(n))] + e.getAsList())
...@@ -137,13 +137,11 @@ def prompt(species_file): ...@@ -137,13 +137,11 @@ def prompt(species_file):
print(table) print(table)
def quitPrompt(): def quitPrompt():
confirm = input("Quit. Are you sure? (y/N)> ") confirm = input("Quit. Are you sure? (y/N)> ")
if confirm == 'y': if confirm == 'y':
print("Bye!") print("Bye!")
sys.exit() sys.exit()
def addSpecies(): def addSpecies():
print() print()
...@@ -179,7 +177,6 @@ def prompt(species_file): ...@@ -179,7 +177,6 @@ def prompt(species_file):
if confirm == 'y': if confirm == 'y':
del entries[speciesNr] del entries[speciesNr]
def getEntryDetails(thisEntry): def getEntryDetails(thisEntry):
output = [] output = []
output.append("\t{}: {}".format(bcolors.markOption(SpeciesEntry.contentNames['name'],'I'), thisEntry.cedalionId)) output.append("\t{}: {}".format(bcolors.markOption(SpeciesEntry.contentNames['name'],'I'), thisEntry.cedalionId))
...@@ -192,8 +189,7 @@ def prompt(species_file): ...@@ -192,8 +189,7 @@ def prompt(species_file):
details = '\n'.join(output) details = '\n'.join(output)
return details return details
def editSpecies(entryNr): def editSpecies(entryNr):
entryNr = entryNr - 1 entryNr = entryNr - 1
...@@ -207,19 +203,18 @@ def prompt(species_file): ...@@ -207,19 +203,18 @@ def prompt(species_file):
print("Entering '-' will erase the current value.") print("Entering '-' will erase the current value.")
print() print()
##Edit prompt #Edit prompt
def editCedalionId(): def editCedalionId():
value = input("{} ({})> ".format(SpeciesEntry.contentNames['name'], thisEntry.cedalionId)) value = input("{} ({})> ".format(SpeciesEntry.contentNames['name'], thisEntry.cedalionId))
if value: if value:
thisEntry.cedalionId = value thisEntry.cedalionId = value
def editLongName(): def editLongName():
value = input("{} ({})> ".format(SpeciesEntry.contentNames['long_name'], thisEntry.longName)) value = input("{} ({})> ".format(SpeciesEntry.contentNames['long_name'], thisEntry.longName))
if value: if value:
thisEntry.longName = value if value!='-' else '' thisEntry.longName = value if value!='-' else ''
def editRole(): def editRole():
roles = {'n': 'new', roles = {'n': 'new',
'b': 'background', 'b': 'background',
...@@ -231,7 +226,7 @@ def prompt(species_file): ...@@ -231,7 +226,7 @@ def prompt(species_file):
value = input("{} ({}) ({})> ".format(SpeciesEntry.contentNames['type'], thisEntry.role, roleOptions)) value = input("{} ({}) ({})> ".format(SpeciesEntry.contentNames['type'], thisEntry.role, roleOptions))
if value in roles: if value in roles:
thisEntry.role = roles[value] thisEntry.role = roles[value]
def editPlazaId(): def editPlazaId():
value = input("{} ({})> ".format(SpeciesEntry.contentNames['plaza_id'], thisEntry.plazaId)) value = input("{} ({})> ".format(SpeciesEntry.contentNames['plaza_id'], thisEntry.plazaId))
if value: if value:
...@@ -245,22 +240,20 @@ def prompt(species_file): ...@@ -245,22 +240,20 @@ def prompt(species_file):
thisEntry.longName = hits[value] thisEntry.longName = hits[value]
else: else:
print(bcolors.error("Plaza Id not found")) print(bcolors.error("Plaza Id not found"))
def editProteome(): def editProteome():
value = input("{} ({})> ".format(SpeciesEntry.contentNames['proteome'], thisEntry.proteome)) value = input("{} ({})> ".format(SpeciesEntry.contentNames['proteome'], thisEntry.proteome))
if value: if value:
thisEntry.proteome = value if value!='-' else '' thisEntry.proteome = value if value!='-' else ''
def editCds(): def editCds():
value = input("{} ({})> ".format(SpeciesEntry.contentNames['cds'], thisEntry.cds)) value = input("{} ({})> ".format(SpeciesEntry.contentNames['cds'], thisEntry.cds))
thisEntry.cds = value if value!='-' else '' thisEntry.cds = value if value!='-' else ''
def editGff3(): def editGff3():
value = input("{} ({})> ".format(SpeciesEntry.contentNames['gff3'], thisEntry.gff3)) value = input("{} ({})> ".format(SpeciesEntry.contentNames['gff3'], thisEntry.gff3))
thisEntry.gff3 = value if value!='-' else '' thisEntry.gff3 = value if value!='-' else ''
editOptions = { editOptions = {
'i': editCedalionId, 'i': editCedalionId,
'l': editLongName, 'l': editLongName,
...@@ -270,7 +263,7 @@ def prompt(species_file): ...@@ -270,7 +263,7 @@ def prompt(species_file):
'c': editCds, 'c': editCds,
'g': editGff3 'g': editGff3
} }
choice = '*' choice = '*'
while choice == '*' or choice in editOptions: while choice == '*' or choice in editOptions:
choice = input("Select attribute for '{}'> ".format(thisEntry.cedalionId)) choice = input("Select attribute for '{}'> ".format(thisEntry.cedalionId))
...@@ -279,19 +272,17 @@ def prompt(species_file): ...@@ -279,19 +272,17 @@ def prompt(species_file):
print() print()
print(getEntryDetails(thisEntry)) print(getEntryDetails(thisEntry))
def generateLaunchScript(): def generateLaunchScript():
runName = input("Cedalion run name> ") runName = input("Cedalion run name> ")
launchScript = "launch_{}.sh".format(runName) launchScript = "launch_{}.sh".format(runName)
## Get main Nextflow pipeline script # Get main Nextflow pipeline script
main_nf = 'main.nf' main_nf = 'main.nf'
modpath, modfile = os.path.split(__file__) modpath, modfile = os.path.split(__file__)
cedpath, mod = os.path.split(modpath) cedpath, mod = os.path.split(modpath)
mainpath, mod = os.path.split(cedpath) mainpath, mod = os.path.split(cedpath)
main_nf_path = os.path.join(mainpath, main_nf) main_nf_path = os.path.join(mainpath, main_nf)
inputDir = '.' inputDir = '.'
inputDirEntered = input("Data input folder (default: .)> ") inputDirEntered = input("Data input folder (default: .)> ")
if inputDirEntered: if inputDirEntered:
...@@ -306,7 +297,7 @@ def prompt(species_file): ...@@ -306,7 +297,7 @@ def prompt(species_file):
workDirEntered = input("Working and cache folder (default: ./work)> ") workDirEntered = input("Working and cache folder (default: ./work)> ")
if workDirEntered: if workDirEntered:
workDir = workDirEntered workDir = workDirEntered
scriptLines = [] scriptLines = []
scriptLines.append("module load nextflow") scriptLines.append("module load nextflow")
scriptLines.append("export NXF_WORK={}".format(workDir)) scriptLines.append("export NXF_WORK={}".format(workDir))
...@@ -318,13 +309,13 @@ def prompt(species_file): ...@@ -318,13 +309,13 @@ def prompt(species_file):
os.chmod(launchScript, 0o775) os.chmod(launchScript, 0o775)
print("Launch script saved to: {}".format(launchScript)) print("Launch script saved to: {}".format(launchScript))
def saveList(): def saveList():
if species_file: if species_file:
outputFileName = species_file outputFileName = species_file
else: else:
outputFileName = "species.tsv" outputFileName = "species.tsv"
outputFileEntered = input("Save file (default: {})> ".format(outputFileName)) outputFileEntered = input("Save file (default: {})> ".format(outputFileName))
if outputFileEntered: if outputFileEntered:
outputFileName = outputFileEntered outputFileName = outputFileEntered
...@@ -345,19 +336,19 @@ def prompt(species_file): ...@@ -345,19 +336,19 @@ def prompt(species_file):
cids = {'empty': 0} cids = {'empty': 0}
roles = {'new': 0, 'background': 0, 'outgroup': 0} roles = {'new': 0, 'background': 0, 'outgroup': 0}
for e in entries: for e in entries:
if not e.cedalionId: if not e.cedalionId:
cids['empty'] +=1 cids['empty'] +=1
else: else:
if e.cedalionId not in cids: if e.cedalionId not in cids:
cids[e.cedalionId] = 0 cids[e.cedalionId] = 0
cids[e.cedalionId] +=1 cids[e.cedalionId] +=1
roles[e.role] +=1 roles[e.role] +=1
if not e.longName: if not e.longName:
print(bcolors.error("'{}' should specify a full species name.".format(e.cedalionId))) print(bcolors.error("'{}' should specify a full species name.".format(e.cedalionId)))
if e.role == 'new' and not e.proteome: if e.role == 'new' and not e.proteome:
print(bcolors.error("'{}' should specify a proteome fasta file.".format(e.cedalionId))) print(bcolors.error("'{}' should specify a proteome fasta file.".format(e.cedalionId)))
approved = False approved = False
...@@ -396,9 +387,8 @@ def prompt(species_file): ...@@ -396,9 +387,8 @@ def prompt(species_file):
if roles['background'] == 0: if roles['background'] == 0:
print(bcolors.error("A Cedalion run needs at least one 'background' species.")) print(bcolors.error("A Cedalion run needs at least one 'background' species."))
approved = False approved = False
return approved
return approved
def save(): def save():
approved = checkList() approved = checkList()
...@@ -407,7 +397,7 @@ def prompt(species_file): ...@@ -407,7 +397,7 @@ def prompt(species_file):
confirm = input("Are you sure you want to save this file? (y/N)>") confirm = input("Are you sure you want to save this file? (y/N)>")
if confirm != 'y': if confirm != 'y':
return return
saveList() saveList()
generateLaunchScript() generateLaunchScript()
...@@ -418,10 +408,8 @@ def prompt(species_file): ...@@ -418,10 +408,8 @@ def prompt(species_file):
print("Bye!") print("Bye!")
sys.exit() sys.exit()
def helpDoc(): def helpDoc():
helpList = [ helpList = [
'list selected species', 'list selected species',
'find in Plaza', 'find in Plaza',
...@@ -431,17 +419,17 @@ def prompt(species_file): ...@@ -431,17 +419,17 @@ def prompt(species_file):
'help', 'help',
'quit' 'quit'
] ]
helpList = [ '\t' + bcolors.markPosition(line, 0) for line in helpList] helpList = ['\t' + bcolors.markPosition(line, 0) for line in helpList]
print() print()
for line in helpList: for line in helpList:
print(line) print(line)
print() print()
def unknownOption(): def unknownOption():
print("Option unknown") print("Option unknown")
print() print()
options = {'q': quitPrompt, options = {'q': quitPrompt,
'a': addSpecies, 'a': addSpecies,
'l': listSpecies, 'l': listSpecies,
...@@ -455,7 +443,7 @@ def prompt(species_file): ...@@ -455,7 +443,7 @@ def prompt(species_file):
entries = parseSpeciesFile(species_file) entries = parseSpeciesFile(species_file)
else: else:
entries = [] entries = []
choice = '' choice = ''
print("This is the interactive Cedalion Launcher.") print("This is the interactive Cedalion Launcher.")
...@@ -478,11 +466,10 @@ def prompt(species_file): ...@@ -478,11 +466,10 @@ def prompt(species_file):
editChoice = int(choice) editChoice = int(choice)
if editChoice > 0 and editChoice <= len(entries): if editChoice > 0 and editChoice <= len(entries):
editSpecies(editChoice) editSpecies(editChoice)
except: except ValueError:
# Ignore non-numeric input
pass pass
if __name__ == '__main__': if __name__ == '__main__':
prompt() prompt()
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