Skip to content

Commit

Permalink
added pdcli as a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
kvdomingo committed Feb 6, 2020
1 parent f8c4caa commit f0b8009
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 55 deletions.
60 changes: 9 additions & 51 deletions sdm/static/sdm/scripts/pdcli.py → pdcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
from Bio.SeqRecord import SeqRecord
from primerclass import *
from pdcli.primerclass import *
from pdcli.input_handler import *


def main():
Expand All @@ -18,63 +19,17 @@ def main():
parser.add_argument('-p', '--position', help='Target base position', type=int)
parser.add_argument('-i', '--interactive', help='Interactive mode', action='store_true')
args = parser.parse_args()
args_dict = dict()

if args.interactive:
print('')
print('====================================')
print('====== ======')
print('=== PrimerDriver v0.1.2 ===')
print('====== ======')
print('====================================\n')
print('(c) 2020 Kenneth Domingo & Nomer Gutierrez\n')
args_dict['mode'] = input('Enter primer mode [dna/pro/char]: ')
if args_dict['mode'].upper() == 'DNA':
args_dict['sequence'] = input('Enter DNA sequence: ')
PrimerChecks(args_dict['sequence']).check_sequence_length()
PrimerChecks(args_dict['sequence']).check_valid_base()
args_dict['mutation_type'] = input('Enter mutation type [s/i/d]: ')
if args_dict['mutation_type'].upper() in ['S', 'SUB']:
args_dict['target'] = input('Enter target base: ')
args_dict['destination'] = input('Enter replacement for target base: ')
args_dict['position'] = int(input('Enter position of target: '))
elif args_dict['mutation_type'].upper() in ['I', 'INS']:
args_dict['target'] = None
args_dict['destination'] = input('Enter insertion sequence: ')
args_dict['position'] = int(input('Enter insertion position: '))
elif args_dict['mutation_type'].upper() in ['I', 'INS']:
args_dict['target'] = None
args_dict['destination'] = input('Enter starting position to delete: ')
else:
raise ValueError("Invalid argument passed to 'MUTATION_TYPE'")
elif args_dict['mode'].upper() == 'CHAR':
args_dict['sequence'] = input('Enter primer sequence: ')
args_dict['mutation_type'] = input('Enter mutation type [s/i/d]: ')
args_dict['mismatched_bases'] = input('Enter number of mismatched bases: ')
else:
raise NotImplementedError(f"{args_dict['mode']} mode not implemented (yet).")

args_dict = interactive_handler()
else:
args_dict['mode'] = args.mode
if args.mode.upper() =='DNA':
args_dict['sequence'] = args.sequence
PrimerChecks(args.sequence).check_sequence_length()
PrimerChecks(args.sequence).check_valid_base()
args_dict['mutation_type'] = args.mutation_type
args_dict['position'] = args.position
args_dict['destination'] = args.destination
if args.mutation_type.upper() in ['S', 'SUB']:
args_dict['target'] = args.target
else:
raise ValueError("Invalid argument passed to 'MUTATION_TYPE'")
else:
raise NotImplementedError(f"{args_dict['mode']} mode not implemented (yet).")
args_dict = singleCommand_handler(args)

res = PrimerDesign(**args_dict)
if args_dict['mode'].upper() == 'CHAR':
res.characterize_primer()
df = res.df
else:
elif args_dict['mode'].upper() == 'DNA':
res.main()
idx = [
'Forward',
Expand All @@ -94,7 +49,10 @@ def main():
index=idx,
dtype=str,
)
save = input("Save? [y/n] ")
else:
raise NotImplementedError

save = input("\nSave? [y/n] ")
if save.upper() == "Y":
while True:
savename = input("Enter filename: ")
Expand Down
Empty file added pdcli/__init__.py
Empty file.
54 changes: 54 additions & 0 deletions pdcli/input_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
def singleCommand_handler(args):
args_dict = dict()
args_dict['mode'] = args.mode
if args.mode.upper() =='DNA':
args_dict['sequence'] = args.sequence
PrimerChecks(args.sequence).check_sequence_length()
PrimerChecks(args.sequence).check_valid_base()
args_dict['mutation_type'] = args.mutation_type
args_dict['position'] = args.position
args_dict['destination'] = args.destination
if args.mutation_type.upper() in ['S', 'SUB']:
args_dict['target'] = args.target
else:
raise ValueError("Invalid argument passed to 'MUTATION_TYPE'")
else:
raise NotImplementedError(f"{args_dict['mode']} mode not implemented (yet).")
return args_dict

def interactive_handler():
args_dict = dict()
print('')
print('====================================')
print('====== ======')
print('=== PrimerDriver v0.1.2 ===')
print('====== ======')
print('====================================\n')
print('(c) 2020 Kenneth Domingo & Nomer Gutierrez\n')
args_dict['mode'] = input('Enter primer mode [dna/pro/char]: ')
if args_dict['mode'].upper() == 'DNA':
args_dict['sequence'] = input('Enter DNA sequence: ')
PrimerChecks(args_dict['sequence']).check_sequence_length()
PrimerChecks(args_dict['sequence']).check_valid_base()
args_dict['mutation_type'] = input('Enter mutation type [s/i/d]: ')
if args_dict['mutation_type'].upper() in ['S', 'SUB']:
args_dict['target'] = input('Enter target base: ')
args_dict['destination'] = input('Enter replacement for target base: ')
args_dict['position'] = int(input('Enter position of target: '))
elif args_dict['mutation_type'].upper() in ['I', 'INS']:
args_dict['target'] = None
args_dict['destination'] = input('Enter insertion sequence: ')
args_dict['position'] = int(input('Enter insertion position: '))
elif args_dict['mutation_type'].upper() in ['I', 'INS']:
args_dict['target'] = None
args_dict['destination'] = input('Enter starting position to delete: ')
else:
raise ValueError("Invalid argument passed to 'MUTATION_TYPE'")
elif args_dict['mode'].upper() == 'CHAR':
args_dict['sequence'] = input('Enter primer sequence: ')
args_dict['mutation_type'] = input('Enter mutation type [s/i/d]: ')
args_dict['mismatched_bases'] = input('Enter number of mismatched bases: ')
else:
raise NotImplementedError(f"{args_dict['mode']} mode not implemented (yet).")

return args_dict
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def deletion(self):
self.forward = ''.join(seq)

def characterize_primer(self):
with open("lut.json", "r", encoding="utf-8") as f:
with open("pdcli/lut.json", "r", encoding="utf-8") as f:
lut = load(f)
mol_weight = lut["mol_weight"]
complement_dict = lut["complement"]
Expand Down Expand Up @@ -109,11 +109,11 @@ def characterize_primer(self):
f'{self.mismatch*100:.2f}%',
gc_end
]
print(tabulate(
print('\n', tabulate(
array([col, dat]).T,
headers=['Primer 1'],
tablefmt='orgtbl'
))
), sep="")
self.df = DataFrame(
data=dat,
columns=['Primer 1'],
Expand All @@ -130,7 +130,7 @@ def main(self):
else:
raise NotImplementedError('Invalid mutation type')

with open("lut.json", "r", encoding="utf-8") as f:
with open("pdcli/lut.json", "r", encoding="utf-8") as f:
complement_dict = load(f)["complement"]
self.rev_compl = ''.join([complement_dict[b] for b in list(self.forward[::-1])])
self.gc_content = (self.forward.count('G') + self.forward.count('C'))/len(self.forward)
Expand Down

0 comments on commit f0b8009

Please sign in to comment.