forked from JacobIsrael/BlastHtmlEmbed-Parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlastHtmlEmbedParser.cs
executable file
·123 lines (110 loc) · 4.03 KB
/
BlastHtmlEmbedParser.cs
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//gmcs BlastHtmlEmbedParser.cs /t:library -out:../bin/BlastHtmlEmbedParser.dll
// BlastHtmlEmbedParser.cs
//
// Copyright (C) 2008 Jacob, [email protected], [email protected]
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
using System;
using System.IO;
namespace BlastHtmlEmbedParser
{
public class blastHtmlParser {
private StreamReader sr;
private StreamWriter sw;
private string fileName;
private string fileNew;
public void Load(string file)
{
fileName = Path.GetFullPath(file);
fileNew = Path.GetDirectoryName(fileName) + "/" + Path.GetFileNameWithoutExtension(fileName) + "_new.htm";
sr = File.OpenText(fileName);
sw = File.CreateText(fileNew);
}
public void Format()
{
string lineHtml = "";
string nameCtg = "";
string anameNumber = "";
int pos = 0;
short countPRE = 0;
try {
sw.WriteLine("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">");
do
{
/************************HEAD*******************/
lineHtml = sr.ReadLine();
if(lineHtml.IndexOf("<TITLE>") != -1) {
sw.WriteLine(lineHtml);
sw.WriteLine("<SCRIPT src='../../../script/drawgraphicfromBlastReport.js'></SCRIPT>");
sw.WriteLine("<SCRIPT src='../script/drawgraphicfromBlastReport.js'></SCRIPT>");
continue;
}
if(lineHtml.IndexOf("<BODY") != -1) {
sw.WriteLine(lineHtml);
sw.WriteLine("<form method='post' id='frmSendQueryDefFromBlast' name='frmSendQueryDefFromBlast' action='/qvisualizerDemoDeveloping.aspx'>");
sw.WriteLine(" <input id='txtqueryfblast' name='txtqueryfblast' type='text' style='visibility:hidden' >");
sw.WriteLine(" <input id='txtqueryshidden' name='txtqueryshidden' type='hidden' value=''>");
sw.WriteLine(" <input id='txtdeschidden' name='txtdeschidden' type='hidden' value=''>");
//sw.WriteLine(" <input id='buttest' name='buttest' type='button' onclick=\"showContigInfo('E09xyz')\" />");
sw.WriteLine("</form>");
continue;
}
if(countPRE < 4) {
sw.WriteLine(lineHtml);
pos = lineHtml.IndexOf("PRE");
if(pos != -1)
countPRE++;
}
/************************HEAD*******************/
/************************BODY*****************/
if(countPRE >= 4) {
pos = lineHtml.IndexOf("<a name = ");
if(pos != -1) {
pos = lineHtml.IndexOf("/a");
if(pos != -1) {
nameCtg = lineHtml.Substring(pos+3,(lineHtml.Length - (pos + 3)));
anameNumber = lineHtml.Substring(0,pos+3);
sw.Write(anameNumber + "<span id='sp_" + nameCtg + "' style='text-decoration:underline;color:blue;cursor:pointer' onclick=\"showContigInfo('" + nameCtg + "')\">");
sw.WriteLine(nameCtg + "</span>");
}
}
else
sw.WriteLine(lineHtml);
}
/************************BODY*****************/
}
while(lineHtml!=null);
}
catch(Exception e) {
;
}
sw.WriteLine("");sw.WriteLine("");sw.WriteLine("");
sw.WriteLine("<b><i>Parsed by Blast Html Embed Parser Tool</i></b>");
sw.WriteLine("<i><b>Copyright 2008</b>, <a href='mailto:[email protected]'>[email protected]</a></i>");
sw.Close();
File.Delete(fileName);
File.Move(fileNew,fileName);
}
}
public class testBlastParser
{
public static void Main(string[] args)
{
blastHtmlParser obj = new blastHtmlParser();
obj.Load(args[0]);
obj.Format();
}
}
}