Skip to content

Commit

Permalink
Apply PEP8 in sources and setup loki command in poetry
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreRico committed Jan 16, 2025
1 parent 2203ce2 commit dc6eedb
Show file tree
Hide file tree
Showing 23 changed files with 92 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ __pycache__/
# Distribution / packaging
.Python
build/
data/
develop-eggs/
dist/
downloads/
Expand Down
2 changes: 1 addition & 1 deletion biofilter_modules/biofilter_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Biofilter(
def getVersionTuple(cls):
# tuple = (major,minor,revision,dev,build,date)
# dev must be in ('a','b','rc','release') for lexicographic comparison
return (2, 4, 4, "release", "", "2024-12-01")
return (3, 0, 1, "release", "", "2025-01-01")

@classmethod
def getVersionString(cls):
Expand Down
17 changes: 16 additions & 1 deletion loki_modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))

from loki_modules.loki_db import Database
from loki_modules.loki_db import Database # noqa E402
from loki_modules.loki_build import main # noqa E402
from loki_modules.loki_mixins import ( # noqa E402
Schema,
VersionMixin,
Expand All @@ -13,9 +14,17 @@
DatabaseOperationsMixin,
DatabaseLiftOverMixin,
DatabaseQueryMixin,
SourceUtilityMethods,
SourceDbOperations,
UpdaterDownloadMixin,
UpdaterDatabaseMixin,
UpdaterLiftOverMixin,
UpdaterOperationsMixin,
)


__all__ = [
"main",
"Database",
"loki_db",
"loki_source",
Expand All @@ -30,4 +39,10 @@
"DatabaseOperationsMixin",
"DatabaseLiftOverMixin",
"DatabaseQueryMixin",
"SourceUtilityMethods",
"SourceDbOperations",
"UpdaterDownloadMixin",
"UpdaterDatabaseMixin",
"UpdaterLiftOverMixin",
"UpdaterOperationsMixin",
]
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_biogrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Source_biogrid(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.1 (2022-04-13)"
return "3.0.0 (2025-01-01)"

def download(self, options, path):
# download the latest source files
Expand Down
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_chainfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Source_chainfiles(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.2 (2014-06-27)"
return "3.0.0 (2025-01-01)"

def download(self, options, path):
# define callback to search for all available hgX liftover chain files
Expand Down
76 changes: 38 additions & 38 deletions loki_modules/loaders/loki_source_dbsnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _identifyLatestSNPContig(self, filenames):

@classmethod
def getVersionString(cls):
return "2.3 (2018-11-01)"
return "3.0.0 (2025-01-01)"

@classmethod
def getOptions(cls):
Expand Down Expand Up @@ -132,7 +132,7 @@ def remFilesCallback(ftp, path):
string = urlpath.read().decode("utf-8")
onlyfiles = list(
set(
re.findall(r"b([0-9]+)_SNPContigLocusId_(.*)\.bcp\.gz", string)
re.findall(r"b([0-9]+)_SNPContigLocusId_(.*)\.bcp\.gz", string) # noqa E501
) # noqa E501
)
bestfile = self._identifyLatestSNPContig(onlyfiles)
Expand Down Expand Up @@ -247,10 +247,10 @@ def update(self, options, path):
name = words[1]
desc = words[2]
coding = (
int(words[5]) if (len(words) > 5 and words[5] != "") else None
int(words[5]) if (len(words) > 5 and words[5] != "") else None # noqa E501
) # noqa E501
exon = (
int(words[6]) if (len(words) > 6 and words[6] != "") else None
int(words[6]) if (len(words) > 6 and words[6] != "") else None # noqa E501
) # noqa E501

roleID[code] = self.addRole(name, desc, coding, exon)
Expand All @@ -261,38 +261,38 @@ def update(self, options, path):

# process SNP roles
""" /* from human_9606_table.sql.gz */
CREATE TABLE [b137_SNPContigLocusId]
(
[snp_id] [int] NULL ,
[contig_acc] [varchar](32) NOT NULL ,
[contig_ver] [tinyint] NULL ,
[asn_from] [int] NULL ,
[asn_to] [int] NULL ,
[locus_id] [int] NULL ,
[locus_symbol] [varchar](64) NULL ,
[mrna_acc] [varchar](32) NOT NULL ,
[mrna_ver] [smallint] NOT NULL ,
[protein_acc] [varchar](32) NULL ,
[protein_ver] [smallint] NULL ,
[fxn_class] [int] NULL ,
[reading_frame] [int] NULL ,
[allele] [varchar](255) NULL ,
[residue] [varchar](1000) NULL ,
[aa_position] [int] NULL ,
[build_id] [varchar](4) NOT NULL ,
[ctg_id] [int] NULL ,
[mrna_start] [int] NULL ,
[mrna_stop] [int] NULL ,
[codon] [varchar](1000) NULL ,
[protRes] [char](3) NULL ,
[contig_gi] [int] NULL ,
[mrna_gi] [int] NULL ,
[mrna_orien] [tinyint] NULL ,
[cp_mrna_ver] [int] NULL ,
[cp_mrna_gi] [int] NULL ,
[verComp] [int] NULL
)
"""
CREATE TABLE [b137_SNPContigLocusId]
(
[snp_id] [int] NULL ,
[contig_acc] [varchar](32) NOT NULL ,
[contig_ver] [tinyint] NULL ,
[asn_from] [int] NULL ,
[asn_to] [int] NULL ,
[locus_id] [int] NULL ,
[locus_symbol] [varchar](64) NULL ,
[mrna_acc] [varchar](32) NOT NULL ,
[mrna_ver] [smallint] NOT NULL ,
[protein_acc] [varchar](32) NULL ,
[protein_ver] [smallint] NULL ,
[fxn_class] [int] NULL ,
[reading_frame] [int] NULL ,
[allele] [varchar](255) NULL ,
[residue] [varchar](1000) NULL ,
[aa_position] [int] NULL ,
[build_id] [varchar](4) NOT NULL ,
[ctg_id] [int] NULL ,
[mrna_start] [int] NULL ,
[mrna_stop] [int] NULL ,
[codon] [varchar](1000) NULL ,
[protRes] [char](3) NULL ,
[contig_gi] [int] NULL ,
[mrna_gi] [int] NULL ,
[mrna_orien] [tinyint] NULL ,
[cp_mrna_ver] [int] NULL ,
[cp_mrna_gi] [int] NULL ,
[verComp] [int] NULL
)
"""
self.log("processing SNP roles ...\n")
setRole = set()
numRole = numOrphan = numInc = 0
Expand Down Expand Up @@ -502,7 +502,7 @@ def processChmSNPs(
for chm, listPos in listChrPos.items():
self.addChromosomeSNPLoci(self._loki.chr_num[chm], listPos)
self.log(
"writing chromosome %s SNPs to the database completed\n" % fileChm
"writing chromosome %s SNPs to the database completed\n" % fileChm # noqa E501
) # noqa E501

# print results
Expand All @@ -527,6 +527,6 @@ def processChmSNPs(
)
if setBadChr:
self.log(
"WARNING: %d SNPs on mismatching chromosome\n" % (len(setBadChr))
"WARNING: %d SNPs on mismatching chromosome\n" % (len(setBadChr)) # noqa E501
) # noqa E501
listChrPos = setBadBuild = setBadVers = setBadFilter = setBadChr = None
6 changes: 3 additions & 3 deletions loki_modules/loaders/loki_source_entrez.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Source_entrez(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.4 (2022-04-12)"
return "3.0.0 (2025-01-01)"

@classmethod
def getOptions(cls):
Expand Down Expand Up @@ -378,9 +378,9 @@ def update(self, options, path):
% (len(setBadChr)) # noqa E501
)
self.logPop()
entrezChm = setOrphan = setBadNC = setBadBuild = setBadChr = setBadVers = (
entrezChm = setOrphan = setBadNC = setBadBuild = setBadChr = setBadVers = ( # noqa E501
buildGenes
) = None # noqa E501 # noqa E501
) = None # noqa E501

# store gene regions
self.log("writing gene regions to the database ...\n")
Expand Down
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Source_go(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.1 (2022-04-14)"
return "3.0.0 (2025-01-01)"

# getVersionString()

Expand Down
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_gwas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Source_gwas(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.5 (2016-09-19)"
return "3.0.0 (2025-01-01)"

def download(self, options, path):
# download the latest source files
Expand Down
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _identifyLatestFilename(self, filenames):

@classmethod
def getVersionString(cls):
return "2.2 (2018-02-20)"
return "3.0.0 (2025-01-01)"

def download(self, options, path):
self.downloadFilesFromHTTP(
Expand Down
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_oreganno.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Source_oreganno(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.1 (2016-09-19)"
return "3.0.0 (2025-01-01)"

def download(self, options):
"""
Expand Down
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_pfam.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Source_pfam(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.2 (2016-02-08)"
return "3.0.0 (2025-01-01)"

def download(self, options, path):
self.downloadFilesFromHTTP(
Expand Down
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_pharmgkb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Source_pharmgkb(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.3 (2018-10-30)"
return "3.0.0 (2025-01-01)"

def download(self, options, path):
self.downloadFilesFromHTTPS(
Expand Down
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_reactome.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Source_reactome(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.1 (2015-01-23)"
return "3.0.0 (2025-01-01)"

def download(self, options):
# download the latest source files
Expand Down
2 changes: 1 addition & 1 deletion loki_modules/loaders/loki_source_ucsc_ecr.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Source_ucsc_ecr(loki_source.Source):

@classmethod
def getVersionString(cls):
return "2.0.1 (2013-03-01)"
return "3.0.0 (2025-01-01)"

@classmethod
def getOptions(cls):
Expand Down
7 changes: 5 additions & 2 deletions loki_modules/loki-build.py → loki_modules/loki_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
from loki_modules import loki_db


if __name__ == "__main__":
def main():
version = "LOKI version %s" % (loki_db.Database.getVersionString())

# define arguments
Expand Down Expand Up @@ -442,4 +442,7 @@ def rmtree_error(func, path, exc):
db.testDatabaseWriteable()
db.optimizeDatabase()
# if knowledge
# __main__


if __name__ == "__main__":
main()
18 changes: 9 additions & 9 deletions loki_modules/loki_mixins/source_utility_methods_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import urllib.request as urllib2
import zlib
import wget
from datetime import datetime
from datetime import datetime, timezone


class SourceUtilityMethods:
Expand Down Expand Up @@ -211,7 +211,7 @@ def downloadFilesFromFTP(self, remHost, remFiles):
if os.path.exists(locPath):
stat = os.stat(locPath)
locSize[locPath] = int(stat.st_size)
locTime[locPath] = datetime.datetime.fromtimestamp(
locTime[locPath] = datetime.fromtimestamp(
stat.st_mtime
) # noqa E501

Expand All @@ -220,7 +220,7 @@ def downloadFilesFromFTP(self, remHost, remFiles):
# format, but most servers return "ls -l"-ish space-delimited columns
# (permissions) (?) (user) (group) (size) (month) (day) (year-or-time)
# (filename)
now = datetime.datetime.utcnow()
now = datetime.now(timezone.utc)

def ftpDirCB(rem_dir, line):
words = line.split()
Expand All @@ -229,15 +229,15 @@ def ftpDirCB(rem_dir, line):
remSize[remFn] = int(words[4])
timestamp = " ".join(words[5:8])
try:
time = datetime.datetime.strptime(timestamp, "%b %d %Y")
time = datetime.strptime(timestamp, "%b %d %Y")
except ValueError:
try:
time = datetime.datetime.strptime(
time = datetime.strptime(
"%s %d" % (timestamp, now.year), "%b %d %H:%M %Y"
)
except ValueError:
try:
time = datetime.datetime.strptime(
time = datetime.strptime(
"%s %d" % (timestamp, now.year - 1),
"%b %d %H:%M %Y", # noqa E501
)
Expand Down Expand Up @@ -342,7 +342,7 @@ def _downloadHTTP(
if os.path.exists(locPath):
stat = os.stat(locPath)
locSize[locPath] = int(stat.st_size)
locTime[locPath] = datetime.datetime.fromtimestamp(
locTime[locPath] = datetime.fromtimestamp(
stat.st_mtime
) # noqa E501
# check remote file sizes and times
Expand All @@ -366,11 +366,11 @@ def _downloadHTTP(
last_modified = info.get("last-modified")
if last_modified:
try:
remTime[locPath] = datetime.datetime.strptime(
remTime[locPath] = datetime.strptime(
last_modified, "%a, %d %b %Y %H:%M:%S %Z"
)
except ValueError:
remTime[locPath] = datetime.datetime.utcnow()
remTime[locPath] = datetime.now(timezone.utc)

response.close()
self.log(" OK\n")
Expand Down
Loading

0 comments on commit dc6eedb

Please sign in to comment.