-
Notifications
You must be signed in to change notification settings - Fork 0
/
conversions.py
65 lines (51 loc) · 1.69 KB
/
conversions.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
#! /usr/bin/env python2
# -*- coding: utf-8 -*-
import argparse
import sys
import os
import pexpect
import subprocess
import pdb
#Other script imports
from hh_reader import read_result
#FUNCTIONS
def pdb_to_fasta(uid, outdir):
'''Convert pdb file to fasta.
'''
inname = outdir+uid+'.pdb'
outname = inname+'.fa'
#Path to pdb parser
command = 'python ./parse_pdb_resid.py ' + inname
outp = subprocess.check_output(command, shell = True)#Save AA sequence
outp = outp.decode()
sequence = outp.split('\n')[0]
with open(outname, "w") as outfile:
outfile.write('>'+uid+'\n')
i = 0 #index
while i<len(sequence):
outfile.write(sequence[i:i+60]+'\n')
i+=60
return None
def run_hhblits(uid, indir, hhblits, uniprot):
'''A function that runs hhblits to create a HMM of an input sequence in fasta format
'''
inname = indir+uid+'.fa'
outname = uid+'.hhm'
statement = hhblits +' -i ' + inname + ' -d ' + uniprot + ' -ohhm ' + outname
outp = subprocess.check_output(statement, shell = True)
return None
def make_phylip(uids, query_aln, template_aln, outdir):
'''Print phylip format for tree-puzzle calculations
'''
#Create text in phylip format
text = (' 4 ' + str(len(query_aln)) + '\n'
+ uids[0] + '00|' + query_aln + '\n'
+ 'copy11111' + '|' + query_aln + '\n'
+ uids[1] + '00|' + template_aln + '\n'
+ 'copy22222' + '|' + template_aln + '\n')
#Define file name
file_name = uids[0] + '_' + uids[1] + '.phy'
#Open file and write text to it
with open(outdir+file_name, "w") as file:
file.write(text)
return None