Mercurial > repos > jay > pdaug_sequence_based_peptide_generation
comparison PDAUG_Sequence_Network/PDAUG_Sequence_Network.py @ 0:93f7668caa55 draft
"planemo upload for repository https://github.com/jaidevjoshi83/pdaug commit a9bd83f6a1afa6338cb6e4358b63ebff5bed155e"
| author | jay |
|---|---|
| date | Wed, 28 Oct 2020 02:18:30 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:93f7668caa55 |
|---|---|
| 1 import Levenshtein | |
| 2 import matplotlib.pyplot as plt | |
| 3 import networkx as nx | |
| 4 import os | |
| 5 | |
| 6 | |
| 7 def SeqSimilarityNetwork(InFile, OutFile): | |
| 8 | |
| 9 f = open(InFile) | |
| 10 lines = f.readlines() | |
| 11 | |
| 12 record = [] | |
| 13 seq = [] | |
| 14 | |
| 15 G = nx.Graph() | |
| 16 | |
| 17 for line in lines: | |
| 18 | |
| 19 if ">" in line: | |
| 20 record.append(line.strip('\n')) | |
| 21 else: | |
| 22 seq.append(line.strip('\n')) | |
| 23 | |
| 24 for x, i in enumerate(seq): | |
| 25 for X, I in enumerate(seq): | |
| 26 L = Levenshtein.ratio(i, I ) | |
| 27 if L >= 0.4: | |
| 28 G.add_edge(record[x], record[X], weight=float(Levenshtein.ratio(i, I ))) | |
| 29 | |
| 30 elarge = [(u, v) for (u, v, d) in G.edges(data=True) if d['weight'] >= 0.4] | |
| 31 | |
| 32 pos = nx.spring_layout(G) | |
| 33 nx.draw_networkx_nodes(G, pos, node_size=10) | |
| 34 nx.draw_networkx_edges(G, pos, edgelist=elarge,width=1) | |
| 35 plt.axis('off') | |
| 36 | |
| 37 plt.savefig(OutFile) | |
| 38 | |
| 39 | |
| 40 | |
| 41 if __name__=="__main__": | |
| 42 | |
| 43 import argparse | |
| 44 | |
| 45 parser = argparse.ArgumentParser() | |
| 46 | |
| 47 parser.add_argument("-I", "--InFile", required=True, default=None, help="Path to target tsv file") | |
| 48 parser.add_argument("-O","--OutFile", required=False, help="HTML out file", default="out.png") | |
| 49 args = parser.parse_args() | |
| 50 | |
| 51 SeqSimilarityNetwork(args.InFile, args.OutFile) | |
| 52 | |
| 53 |
