annotate PDAUG_Word_Vector_Descriptor/PDAUG_Word_Vector_Descriptor.py @ 8:8cd2aab4b0f6 draft

"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit d396d7ff89705cc0dd626ed32c45a9f4029b1b05"
author jay
date Mon, 10 Jan 2022 04:10:20 +0000
parents e59674e3a391
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
1 import numpy as np
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
2 import os
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
3 import pandas as pd
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
4 from Bio import SeqIO
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
5 from nltk import bigrams
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
6 from nltk import trigrams
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
7 import gensim
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
8 import argparse
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
9
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
10 parser = argparse.ArgumentParser()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
11
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
12 parser.add_argument("-M", "--ModelInput", required=True, default=None, help="Path to target tsv file")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
13 parser.add_argument("-R", "--row", required=True, default=None, help="Path to target tsv file")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
14 parser.add_argument("-I", "--InputFasta", required=True, default=6, help="Path to target tsv file")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
15 parser.add_argument("-O", "--OutFile", required=False, default='model.txt', help="Path to target tsv file")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
16 parser.add_argument("-P", "--positive", required=True, help="Path to target tsv file")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
17 parser.add_argument("-N", "--negative", required=True, help="Path to target tsv file")
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
18
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
19 args = parser.parse_args()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
20
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
21 seed = 42
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
22 np.random.seed(seed)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
23
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
24 new_model = gensim.models.KeyedVectors.load_word2vec_format(args.ModelInput, binary=False)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
25
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
26 import time
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
27 t0 = time.time()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
28
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
29 temp_word = np.zeros(shape=(int(args.row), 200))
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
30
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
31 for index, seqs in enumerate(SeqIO.parse(args.InputFasta, 'fasta')):
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
32 seq_sum = 0
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
33 tri_seq = trigrams(seqs.seq)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
34 for item in ((tri_seq)):
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
35 tri_str = item[0] + item[1] + item[2]
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
36 if tri_str not in list(new_model.wv.vocab):
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
37 continue
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
38 seq_sum = seq_sum + new_model[tri_str]
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
39
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
40 temp_word[index] = seq_sum
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
41
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
42 t1 = time.time()
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
43
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
44
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
45 temp_word = temp_word
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
46
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
47
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
48 clm = [x for x in range(0,temp_word.shape[1])]
8
8cd2aab4b0f6 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit d396d7ff89705cc0dd626ed32c45a9f4029b1b05"
jay
parents: 0
diff changeset
49 y_temp_word = np.vstack((np.ones((int(args.positive), 1),dtype=int), np.zeros((int(args.negative),1),dtype=int)))
0
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
50
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
51 c, r = y_temp_word.shape
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
52 y_temp_word = y_temp_word.reshape(c,)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
53
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
54 class_label = pd.DataFrame(y_temp_word, columns=["Class_label"])
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
55
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
56 df = pd.DataFrame(temp_word, columns=clm)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
57 df = pd.concat([df,class_label], axis=1)
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
58
e59674e3a391 "planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit 6f53ad797ec1af02b41510063a86bec7d121abf3"
jay
parents:
diff changeset
59 df.to_csv(args.OutFile, index=None, sep="\t")