-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyomix.py
72 lines (58 loc) · 2.77 KB
/
pyomix.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
##########################################################################
# - PyOmiX - Analysis Workflow #
# - Python Script #
# - April 6,2019 #
# - Copyright: Ahmed Omar, Mohamed Magdy, Usama Bakry, and Waleed Amer #
# - Nile University #
##########################################################################
## project Description ..
print('PyOmiX v0.1 | by Ahmed Omar, Mohamed Magdy, Usama Bakry and Waleed Amer\n'
, 'Check https://github.com/ubakry/pyomix for updates.')
# Importing libraries
import os
import argparse
import subprocess
args = None
# ----------------------------------------------------------------------
def get_args():
""""""
parser = argparse.ArgumentParser(
description="PyOmiX - Analysis WorkFlow",
epilog="This is where you might put example usage"
)
# required argument
parser.add_argument('-i', action="store", required=True, help='Swiss-Prot ids txt file directory')
# optional arguments
parser.add_argument('-o', action="store", help='The output directory', default='.')
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
arguments = vars(parser.parse_args())
return arguments
# ----------------------------------------------------------------------
if __name__ == '__main__':
args = get_args()
# Function to make directories for swiss-prot ids
# ----------------------------------------------------------------------
def makdirs(file):
os.mkdir(args['o'] + "/pymoix-results", int(0o755))
os.chdir(args['o'] + "/pymoix-results")
for line in file:
os.mkdir(str(os.getcwd())+"/"+line.rstrip("\n"), int(0o755))
# ----------------------------------------------------------------------
file = open(args['i'])
makdirs(file)
file.close()
# ----------------------------------------------------------------------
# function for alignment using diamond
# ----------------------------------------------------------------------
def diamond_align(fasta, db):
# create refrance database for alignment using diamond (makedb)
make_db = ['diamond', 'makedb', '--in', db, '-d', 'db']
make_db_proc = subprocess.Popen(make_db, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# check the process
stdout, stderr = make_db_proc.communicate()
print(stderr.decode())
# alignment using blastp
diamond = ['diamond', 'blastp', '-q', fasta, '-d', 'db.dmnd', '-f', '6', 'qseqid', '-o', 'id_list.fa']
diamond_proc = subprocess.Popen(diamond, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = diamond_proc.communicate()
print(stderr.decode())