DiExpress 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: DiExpress
3
+ Version: 0.0.2
4
+ Summary: A sample python package to start sharing your code with the world
5
+ Home-page: https://github.com/HySonLab/DiExpress
6
+ Author: Phuc Pham
7
+ Author-email: phuc.phamhuythienai@gmail.com
8
+ Requires-Python: >=3.7
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: trafilatura
12
+ Dynamic: license-file
13
+
14
+ # Differential Gene Expression (DGE)
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ DiExpress.egg-info/PKG-INFO
6
+ DiExpress.egg-info/SOURCES.txt
7
+ DiExpress.egg-info/dependency_links.txt
8
+ DiExpress.egg-info/requires.txt
9
+ DiExpress.egg-info/top_level.txt
10
+ code/__init__.py
11
+ code/datetime_intel.py
12
+ code/gadget.py
@@ -0,0 +1 @@
1
+ trafilatura
@@ -0,0 +1 @@
1
+ code
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 mrthinh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: DiExpress
3
+ Version: 0.0.2
4
+ Summary: A sample python package to start sharing your code with the world
5
+ Home-page: https://github.com/HySonLab/DiExpress
6
+ Author: Phuc Pham
7
+ Author-email: phuc.phamhuythienai@gmail.com
8
+ Requires-Python: >=3.7
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: trafilatura
12
+ Dynamic: license-file
13
+
14
+ # Differential Gene Expression (DGE)
@@ -0,0 +1 @@
1
+ # Differential Gene Expression (DGE)
@@ -0,0 +1,8 @@
1
+ # Copyright 2022 Phuc Pham @ GitHub
2
+ # See LICENSE for details.
3
+
4
+ __author__ = "Phuc Pham @phuc-pham in GitHub"
5
+ __version__ = "0.0.1"
6
+
7
+ from .gadget import *
8
+ from .datetime_intel import *
@@ -0,0 +1,113 @@
1
+ # Copyright 2022 Thinh Vu @ GitHub
2
+
3
+ from datetime import datetime, date
4
+ from datetime import timedelta
5
+ import pandas as pd
6
+
7
+ def date_from_today(days_delta, format='%Y-%m-%d', backward = True):
8
+ """
9
+ Return a DateTime value using today's DateTime as the base.
10
+ Args:
11
+ days_delta (:obj:`int`, required): How many days to add or subtract from today's
12
+ format (:obj:`str`, required): Datetime format of the output. Ex: "%Y-%m-%d". Concatnate the output string with 'T00:00:00Z' or 'T23:59:59Z' if you need.
13
+ format (:obj:`boolean`, optional): True to get dates in the past, False to get the future ones
14
+ """
15
+ today_val = datetime.now()
16
+ if backward == True:
17
+ target = (today_val - timedelta(days_delta)).strftime(format)
18
+ elif backward == False:
19
+ target = (today_val + timedelta(days_delta)).strftime(format)
20
+ else:
21
+ pass
22
+ return target
23
+
24
+
25
+ def date_start_end(periods, freq, format='%Y-%m-%d'):
26
+ """
27
+ Return a DateTime value using today's DateTime as the base.
28
+ Args:
29
+ format (:obj:`str`, required): Datetime format of the output. Ex: "%Y-%m-%d"
30
+ periods (:obj:`int`, required): How many periods from today
31
+ freq (:obj:`str`, required): datetime frequency code. Ex: 'MS' for Month Start and 'M' for Month End. See more at:
32
+ """
33
+ today = datetime.now().strftime('%Y-%m-%d')
34
+ target = pd.date_range(end=today, periods=periods, freq=freq)[0]\
35
+ .strftime(format)
36
+ return target
37
+
38
+
39
+ # generate week value
40
+ def weeknum_intel(datetime_now):
41
+ """ Generate weeknum for the report, consider the lag time of ICT and PST timezone
42
+ """
43
+ if datetime_now.strftime('%a') == 'Mon':
44
+ this_week = int(datetime_now.strftime('%U'))-1
45
+ last_week = this_week - 1
46
+ else:
47
+ this_week = int(datetime_now.strftime('%U'))
48
+ last_week = this_week - 1
49
+ return this_week, last_week
50
+
51
+
52
+ def month_intel(datetime_now, end_date):
53
+ "Input value should be assigned with datetime.now() value"
54
+ if datetime_now.day == 1 and datetime_now.month < 2: # month = 1
55
+ this_month = 'Dec'
56
+ last_month = 'Nov'
57
+ return this_month, last_month
58
+ elif datetime_now.day > 1 and datetime_now.month < 2 : # month = 1
59
+ this_month = 'Jan'
60
+ last_month = 'Dec'
61
+ return this_month, last_month
62
+ if datetime_now.day == 1 and datetime_now.month == 2:
63
+ this_month = 'Jan'
64
+ last_month = 'Dec'
65
+ return this_month, last_month
66
+ elif datetime_now.day == 1 and datetime_now.month > 2:
67
+ this_month = datetime(datetime_now.year, int(datetime.strptime(end_date, '%Y-%m-%d').strftime('%m')), 1).strftime('%b')
68
+ last_month = datetime(datetime_now.year, int(datetime.strptime(end_date, '%Y-%m-%d').strftime('%m'))-1, 1).strftime('%b')
69
+ return this_month, last_month
70
+ else:
71
+ this_month = datetime_now.strftime('%b')
72
+ last_month = datetime(datetime_now.year, int(datetime.strptime(end_date, '%Y-%m-%d').strftime('%m'))-1, 1).strftime('%b')
73
+ return this_month, last_month
74
+
75
+ def quarter_intel(datetime_now):
76
+ """ Return this quarter, last quarter base on the datetime value of today"""
77
+ if datetime_now.day == 1 and datetime_now.month in [1, 2, 3, 4]:
78
+ this_quarter = 'Q1'
79
+ last_quarter = 'Q4'
80
+ return this_quarter, last_quarter
81
+ elif datetime_now.day > 1 and datetime_now.month in [1, 2, 3]:
82
+ this_quarter = 'Q1'
83
+ last_quarter = 'Q4'
84
+ return this_quarter, last_quarter
85
+ elif datetime_now.day == 1 and datetime_now.month in [7, 10]:
86
+ this_quarter = f'Q{(datetime_now.month-1)//3}'
87
+ last_quarter = f'Q{(datetime_now.month-1)//3-1}'
88
+ return this_quarter, last_quarter
89
+ else:
90
+ this_quarter = f'Q{(datetime_now.month-1)//3+1}'
91
+ last_quarter = f'Q{(datetime_now.month-1)//3}'
92
+ return this_quarter, last_quarter
93
+
94
+ def last_quarter_date (current_quarter):
95
+ """Return the last date of a specific quarter"""
96
+ if current_quarter == 1:
97
+ last_qdate = '03-31'
98
+ elif current_quarter == 2:
99
+ last_qdate = '06-30'
100
+ elif current_quarter == 3:
101
+ last_qdate = '09-30'
102
+ elif current_quarter == 4:
103
+ last_qdate = '12-31'
104
+ return last_qdate
105
+
106
+ def weeknum_gen():
107
+ if today_val.strftime('%a') == 'Mon':
108
+ this_week = int(today_val.strftime('%U'))-1
109
+ last_week = this_week - 1
110
+ else:
111
+ this_week = int(today_val.strftime('%U'))
112
+ last_week = this_week - 1
113
+ return this_week, last_week
@@ -0,0 +1,113 @@
1
+ import shutil
2
+ import os
3
+ import subprocess
4
+ import requests
5
+ from trafilatura import fetch_url, extract
6
+ import yaml
7
+ import gc
8
+ import torch
9
+
10
+ # Working with file systems
11
+ def lmt_detect():
12
+ """Detect the running OS and return file path delimiter"""
13
+ if os.name == 'nt':
14
+ lmt = '\\'
15
+ else:
16
+ lmt = '/'
17
+ return lmt
18
+
19
+ ROOT_DIR = os.path.abspath(os.curdir)
20
+ LMT = lmt_detect()
21
+
22
+ def file_ls(directory=ROOT_DIR):
23
+ """List all file in the root directory"""
24
+ data = []
25
+ for entry in os.listdir(directory):
26
+ if os.path.isfile(os.path.join(directory, entry)):
27
+ data.append(entry)
28
+ return data
29
+
30
+ def subdir_ls(basepath=ROOT_DIR):
31
+ """List all subdirectories in the root folder"""
32
+ data = []
33
+ for entry in os.listdir(basepath):
34
+ if os.path.isdir(os.path.join(basepath, entry)):
35
+ data.append(entry)
36
+ return data
37
+
38
+ def newest_file(path=ROOT_DIR):
39
+ files = os.listdir(path)
40
+ paths = [os.path.join(path, basename) for basename in files]
41
+ return max(paths, key=os.path.getctime)
42
+
43
+ # Credentials reading
44
+ def yaml_cred(item_name, cred_path):
45
+ """Read YAML config file"""
46
+ with open(cred_path) as file:
47
+ documents = yaml.full_load(file)
48
+ for item, doc in documents.items():
49
+ if item == item_name:
50
+ return doc
51
+
52
+ # run cmd commands
53
+ def env_setup(command_ls):
54
+ """Run the cmd command. Use the pipe `|` to separate each command"""
55
+ os.system(command_ls)
56
+
57
+ def runcmd(cmd, verbose = False, *args, **kwargs):
58
+ """Run cmd commands"""
59
+ process = subprocess.Popen(
60
+ cmd,
61
+ stdout = subprocess.PIPE,
62
+ stderr = subprocess.PIPE,
63
+ text = True,
64
+ shell = True
65
+ )
66
+ std_out, std_err = process.communicate()
67
+ if verbose:
68
+ print(std_out.strip(), std_err)
69
+ pass
70
+
71
+ # Data loading
72
+ def read_txt(path_to_file):
73
+ """Read a plain text file"""
74
+ with open(path_to_file) as f:
75
+ content = f.read()
76
+ return content
77
+
78
+ # Memory cleaning
79
+ def memory_cleaner():
80
+ """Free up memory from large model data"""
81
+
82
+ gc.collect()
83
+ torch.cuda.empty_cache()
84
+
85
+
86
+ # API Request
87
+ def api_request(url, payload={}, method='GET'):
88
+ """Request any API endpoints with a default User-Agent"""
89
+ headers = {
90
+ 'accept-language': 'en-US,en;q=0.9',
91
+ 'sec-ch-ua': '"Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"',
92
+ 'sec-ch-ua-platform': '"macOS"',
93
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
94
+ }
95
+ response = requests.request(f"{method}", url, headers=headers, data=payload)
96
+ return response.json()
97
+
98
+ # Get Google font
99
+ def get_google_font(font_family):
100
+ """Download & extract a Google font to local folder"""
101
+ lmt = lmt_detect()
102
+ font_url = 'https://fonts.google.com/download?family={}'.format(font_family)
103
+ response = requests.get(font_url)
104
+ file_name = ROOT_DIR + lmt + '{}.zip'.format(font_family)
105
+ with open(file_name, 'wb') as f:
106
+ f.write(response.content)
107
+ shutil.unpack_archive(file_name, lmt.join([ROOT_DIR, 'font', font_family]))
108
+
109
+ # Convert Web to text
110
+ def web_to_text(url):
111
+ downloaded = fetch_url(url)
112
+ result = extract(downloaded)
113
+ return result
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools>=42",
4
+ "wheel"
5
+ ]
6
+ build-backend = "setuptools.build_meta"
7
+
8
+ [project]
9
+ name = "DiExpress"
10
+ description = "A sample python package to start sharing your code with the world"
11
+ version = "0.0.2"
12
+ readme = "README.md"
13
+ requires-python = ">=3.7"
14
+ dependencies = [
15
+ "trafilatura"
16
+ ]
@@ -0,0 +1,23 @@
1
+ [metadata]
2
+ name = DiExpress
3
+ version = 0.0.2
4
+ author = Phuc Pham
5
+ author_email = phuc.phamhuythienai@gmail.com
6
+ description = A sample python package to start sharing your code with the world
7
+ long_description = file: README.md
8
+ long_description_content_type = text/markdown
9
+ url = https://github.com/HySonLab/DiExpress
10
+ classifiers =
11
+ Programming Language :: Python :: 3
12
+ License :: OSI Approved :: MIT License
13
+ Operating System :: OS Independent
14
+
15
+ [options]
16
+ package_dir =
17
+ packages = find:
18
+ python_requires = >=3.7
19
+
20
+ [egg_info]
21
+ tag_build =
22
+ tag_date = 0
23
+