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

Make linter happy

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