Ekl-mgenomics 0.1__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.
- ekl_mgenomics-0.1/Ekl_mgenomics/__init__.py +0 -0
- ekl_mgenomics-0.1/Ekl_mgenomics/chunker.py +28 -0
- ekl_mgenomics-0.1/Ekl_mgenomics/cli.py +47 -0
- ekl_mgenomics-0.1/Ekl_mgenomics/report.py +79 -0
- ekl_mgenomics-0.1/Ekl_mgenomics.egg-info/PKG-INFO +5 -0
- ekl_mgenomics-0.1/Ekl_mgenomics.egg-info/SOURCES.txt +12 -0
- ekl_mgenomics-0.1/Ekl_mgenomics.egg-info/dependency_links.txt +1 -0
- ekl_mgenomics-0.1/Ekl_mgenomics.egg-info/entry_points.txt +2 -0
- ekl_mgenomics-0.1/Ekl_mgenomics.egg-info/requires.txt +1 -0
- ekl_mgenomics-0.1/Ekl_mgenomics.egg-info/top_level.txt +1 -0
- ekl_mgenomics-0.1/PKG-INFO +5 -0
- ekl_mgenomics-0.1/pyproject.toml +3 -0
- ekl_mgenomics-0.1/setup.cfg +4 -0
- ekl_mgenomics-0.1/setup.py +15 -0
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from Bio import SeqIO
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
def run_chunk(fasta_path,blast_precursor):
|
|
4
|
+
c=0
|
|
5
|
+
size=0
|
|
6
|
+
for record in SeqIO.parse(fasta_path,"fasta"):
|
|
7
|
+
c+=1
|
|
8
|
+
size=size+int(len(record.seq))
|
|
9
|
+
print(f"No. of bp in {record.id}= {len(record.seq)}")
|
|
10
|
+
r=Path(blast_precursor)/f"C{c}"
|
|
11
|
+
r.mkdir(parents=True,exist_ok=True) # folder per Seq
|
|
12
|
+
v=0
|
|
13
|
+
for i in range(0,len(record.seq),200000):
|
|
14
|
+
v+=1
|
|
15
|
+
with open(r/f"C{c}CH{v}.fasta","w") as f:
|
|
16
|
+
f.write(f">chunk_{i}_{record.id}_Coordinate_{i+200000 if i+200000<len(record.seq) else i+len(record.seq[i:])}\n")
|
|
17
|
+
f.write(str(record.seq[i:i+200000]))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
print(f"Contigs= {c}")
|
|
21
|
+
if c==1:
|
|
22
|
+
print("It is a Circular DNA")
|
|
23
|
+
|
|
24
|
+
print(f"Genome Size= {size}")
|
|
25
|
+
return fasta_path,blast_precursor
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
import subprocess
|
|
4
|
+
from Ekl_mgenomics.chunker import run_chunk
|
|
5
|
+
from Ekl_mgenomics.report import read, printt
|
|
6
|
+
|
|
7
|
+
def main():
|
|
8
|
+
fasta_path = sys.argv[1] # user types: magtools mygenome.fasta
|
|
9
|
+
|
|
10
|
+
base = os.path.splitext(fasta_path)[0] # "mygenome.fasta" → "mygenome"
|
|
11
|
+
blast_precursor = base + "_chunks/" # chunk subfolders → "mygenome_chunks/"
|
|
12
|
+
blast_results = base + "_blast_results/" # all tsvs → "mygenome_blast_results/"
|
|
13
|
+
output = base + "_OrganismTaxonomy.tsv" # final output
|
|
14
|
+
|
|
15
|
+
# Step 1 — chunk
|
|
16
|
+
print("Step 1: Chunking fasta...")
|
|
17
|
+
run_chunk(fasta_path, blast_precursor)
|
|
18
|
+
|
|
19
|
+
# Step 2 — BLAST
|
|
20
|
+
print("\nStep 2: Running BLAST (this will take a while)...")
|
|
21
|
+
os.makedirs(blast_results, exist_ok=True) # create blast_results folder
|
|
22
|
+
|
|
23
|
+
for contig_folder in sorted(os.listdir(blast_precursor)): # loop C1, C2, C3...
|
|
24
|
+
contig_path = os.path.join(blast_precursor, contig_folder)
|
|
25
|
+
if os.path.isdir(contig_path): # make sure it's a folder
|
|
26
|
+
for fasta_file in sorted(os.listdir(contig_path)): # loop C1CH1.fasta...
|
|
27
|
+
if fasta_file.endswith(".fasta"):
|
|
28
|
+
fasta_in = os.path.join(contig_path, fasta_file)
|
|
29
|
+
tsv_out = os.path.join(blast_results, fasta_file.replace(".fasta", ".tsv"))
|
|
30
|
+
|
|
31
|
+
print(f" BLASTing {fasta_file}...")
|
|
32
|
+
subprocess.run([
|
|
33
|
+
"blastn",
|
|
34
|
+
"-query", fasta_in,
|
|
35
|
+
"-db", "nt",
|
|
36
|
+
"-remote",
|
|
37
|
+
"-max_target_seqs", "3",
|
|
38
|
+
"-max_hsps", "5",
|
|
39
|
+
"-outfmt", "7 qacc sacc evalue staxids sscinames",
|
|
40
|
+
"-out", tsv_out
|
|
41
|
+
])
|
|
42
|
+
|
|
43
|
+
# Step 3 — report
|
|
44
|
+
print("\nStep 3: Generating report...")
|
|
45
|
+
read(blast_results)
|
|
46
|
+
printt(output,fasta_path)
|
|
47
|
+
print(f"\nDone! Results saved to {output}")
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from Bio import Entrez
|
|
3
|
+
Entrez.email="eklavyakumar1602@gmail.com"
|
|
4
|
+
dict={}
|
|
5
|
+
def read(blast_results):
|
|
6
|
+
d={}
|
|
7
|
+
for i in sorted(os.listdir(blast_results)):
|
|
8
|
+
if i.endswith(".tsv"):
|
|
9
|
+
with open(blast_results+i)as f:
|
|
10
|
+
ch=i[:-4]
|
|
11
|
+
for j in f:
|
|
12
|
+
if j.startswith("#")==False:
|
|
13
|
+
if j.strip()=="":
|
|
14
|
+
continue
|
|
15
|
+
id=j.split("\t")[-2]
|
|
16
|
+
|
|
17
|
+
if ch not in d:
|
|
18
|
+
d[ch]={}
|
|
19
|
+
if id not in d[ch]:
|
|
20
|
+
d[ch][id]=1
|
|
21
|
+
else:
|
|
22
|
+
d[ch][id]+=1
|
|
23
|
+
n=ch.split("CH")[0]
|
|
24
|
+
if ch in d:
|
|
25
|
+
m=max(d[ch],key=d[ch].get)
|
|
26
|
+
if n not in dict:
|
|
27
|
+
dict[n]={}
|
|
28
|
+
if m not in dict[n]:
|
|
29
|
+
dict[n][m]=[]
|
|
30
|
+
dict[n][m].append(ch)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
print(d)
|
|
34
|
+
print(dict)
|
|
35
|
+
return dict
|
|
36
|
+
|
|
37
|
+
def ScientificName(n):
|
|
38
|
+
m=Entrez.efetch(db="taxonomy",id=n,retmode="xml")
|
|
39
|
+
h=Entrez.read(m)
|
|
40
|
+
k=h[0]["ScientificName"]
|
|
41
|
+
return k
|
|
42
|
+
|
|
43
|
+
def printt(output,fasta_path):
|
|
44
|
+
l=len(dict)
|
|
45
|
+
d={}
|
|
46
|
+
for i in dict:
|
|
47
|
+
for j in dict[i]:
|
|
48
|
+
e=len(dict[i][j])
|
|
49
|
+
if j not in d:
|
|
50
|
+
d[j]=0
|
|
51
|
+
d[j]+=e
|
|
52
|
+
m=max(d,key=d.get)
|
|
53
|
+
m=ScientificName(m)
|
|
54
|
+
with open(output,"w")as f:
|
|
55
|
+
f.write("MAG\tNo_Of_Contigs\tOrganismName\n")
|
|
56
|
+
f.write(f"{fasta_path}\t{l}\t{m}\n")
|
|
57
|
+
f.write("Contigs\tTotalChunks\tSpeciesAssigned\tNo_Of_Chunks\tName_of_Chunk\n")
|
|
58
|
+
for i in dict:
|
|
59
|
+
s=a=c=p=""
|
|
60
|
+
k=0
|
|
61
|
+
for j in dict[i]:
|
|
62
|
+
k=k+len(dict[i][j])
|
|
63
|
+
if a=="":
|
|
64
|
+
a=ScientificName(j)
|
|
65
|
+
else:
|
|
66
|
+
a=a+"/"+ScientificName(j)
|
|
67
|
+
if p=="":
|
|
68
|
+
p=str(len(dict[i][j]))
|
|
69
|
+
else:
|
|
70
|
+
p=p+"/"+str(len(dict[i][j]))
|
|
71
|
+
if c=="":
|
|
72
|
+
c="-".join(dict[i][j])
|
|
73
|
+
else:
|
|
74
|
+
c=c+"/"+"-".join(dict[i][j])
|
|
75
|
+
f.write(f"{i}\t{k}\t{a}\t{p}\t{c}\n")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
setup.py
|
|
3
|
+
Ekl_mgenomics/__init__.py
|
|
4
|
+
Ekl_mgenomics/chunker.py
|
|
5
|
+
Ekl_mgenomics/cli.py
|
|
6
|
+
Ekl_mgenomics/report.py
|
|
7
|
+
Ekl_mgenomics.egg-info/PKG-INFO
|
|
8
|
+
Ekl_mgenomics.egg-info/SOURCES.txt
|
|
9
|
+
Ekl_mgenomics.egg-info/dependency_links.txt
|
|
10
|
+
Ekl_mgenomics.egg-info/entry_points.txt
|
|
11
|
+
Ekl_mgenomics.egg-info/requires.txt
|
|
12
|
+
Ekl_mgenomics.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
biopython
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Ekl_mgenomics
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name="Ekl_mgenomics",
|
|
5
|
+
version="0.1",
|
|
6
|
+
packages=find_packages(),
|
|
7
|
+
install_requires=[
|
|
8
|
+
"biopython",
|
|
9
|
+
],
|
|
10
|
+
entry_points={
|
|
11
|
+
"console_scripts": [
|
|
12
|
+
"ekl_tax=Ekl_mgenomics.cli:main",
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
)
|