1、精选优质文档-倾情为你奉上烟草核酸数据库管理系统源程序云南省烟草科学研究所2006-12-18源程序的前10页Imports SystemImports System.ioImports System.TextPublic Class Abitracer 解析一个abi文件 /the next three lines are the important persistent data Private sequence As String Private A(), G(), C(), T(), Basecalls() As Integer Private TraceLength, SeqLeng
2、th As Integer /This is the actual file data. Private TraceData() As Byte Private maximum As Integer = 0 /the next four declaration lines comprise the file index information Private MacJunk As Integer = 0 /sometimes when macintosh files are /FTPed in binary form, they have 128 bytes /of crap pre-pend
3、ed to them. This constant /allows ABITrace to handle that in a way that /is invisible to the user. Private Shared AbsIndexBase As Integer = 26 /The file location of the Index pointer Private IndexBase, PLOC As Integer Private ATraceStart, CTraceStart, GTraceStart, TTraceStart As Integer /the next de
4、claration is for the actual file pointers Private DATA9, DATA10, DATA11, DATA12, PBAS2, FWO As Integer Private stremtempfile As String = stream Dim Basecalls() As Integer Dim acolor As Color = Color.DarkGreen Dim ccolor As Color = Color.Blue Dim gcolor As Color = Color.Black Dim tcolor As Color = Co
5、lor.Red Dim ncolor As Color = Color.Pink Dim abrush As Brush = Brushes.Blue Dim cbrush As Brush = Brushes.Red Dim gbrush As Brush = Brushes.DarkGreen Dim tbrush As Brush = Brushes.Black Dim nbrush As Brush = Brushes.Pink Dim backcolor As Color = Color.White Dim dffont As Font = New Font(Times New Ro
6、man, 10) Private myRund, mydate, myDYEP, myMACH, myMODL, myBCAL As String Public lable As String Private errstring Public Function ABITrace(ByVal ABIFile() As Byte) As Boolean initData(ABIFile) If errstring Then Return False Else Return True End If End Function Public Function ABITrace(ByVal ABIFile
7、 As String) As Boolean If ABIFile = Then errstring = 请输入文件! Return False Exit Function End If Dim bytes() As Byte Dim fs As FileStream Dim reader As BinaryReader Try fs = New FileStream(ABIFile, FileMode.Open) reader = New BinaryReader(fs) bytes = reader.ReadBytes(fs.Length) reader.Close() fs.Close(
8、) fs = Nothing Catch ex As Exception errstring = ex.ToString Return False Exit Function End Try If IsNothing(bytes) Then errstring = 无效文件! Return False Exit Function End If errstring = initData(bytes) If errstring Then Return False Else Return True End If End Function Private Sub initData(ByVal file
9、Data() As Byte) TraceData = fileData If isABI() Then setIndex() setBasecalls() setSeq() setTraces() End If End Sub Public Sub getImage(ByRef out As PictureBox, ByVal widthScale As Integer) out.Image = CType(getImage(out.Height, widthScale), Image) End Sub Public Function getImage(ByVal height As Int
10、eger, ByVal widthScale As Double) As Bitmap Dim out As Bitmap out = New Bitmap(CInt(TraceLength * 2 * widthScale), height) out.Width out.Width = TraceLength * widthScale Dim imageHeight As Integer = out.Height out.Height = imageHeight Dim gd As System.Drawing.Graphics Dim mypen As Pen Dim scale As D
11、ouble scale = calculateScale(out.Height) Dim bc() As Integer = Basecalls bc可能是定义nt所在的坐标位置 Dim seq() As Char Dim dfcolor As Color = Color.Black Dim dfbrush = Brushes.Black Dim aa As Brush seq = sequence.ToCharArray gd = Graphics.FromImage(out) gd.Clear(backcolor) Dim here, basenum As Integer here = 0
12、 basenum = 0 For q As Integer = 1 To 5 For x As Integer = 0 To 2 * TraceLength - 2 If q = 1 Then 画A的轨迹 g.setColor(acolor) gd.DrawLine(New Pen(acolor), 2 * x, transmute(A(x), imageHeight, scale), _ 2 * (x + 1), transmute(A(x + 1), imageHeight, scale) End If If q = 2 Then gd.DrawLine(New Pen(ccolor),
13、2 * x, transmute(C(x), imageHeight, scale), _ 2 * (x + 1), transmute(C(x + 1), imageHeight, scale) End If If q = 3 Then gd.DrawLine(New Pen(tcolor), 2 * x, transmute(T(x), imageHeight, scale), _ 2 * (x + 1), transmute(T(x + 1), imageHeight, scale) End If If q = 4 Then gd.DrawLine(New Pen(gcolor), 2
14、 x, transmute(G(x), imageHeight, scale), _ 2 * (x + 1), transmute(G(x + 1), imageHeight, scale) End If If q = 5 Then 画其他内容的 If (here bc.Length - 1) Or (basenum seq.Length - 1) Then Exit For If x Mod 30 = 0 Then gd.DrawString(2 * x, dffont, Brushes.Black, _ (2 * x - 3), transmute(-27, imageHeight, 1
15、0) End If If (bc(here) = x) Then gd.DrawLine(New Pen(dfcolor), 2 * x, transmute(-2, imageHeight, 1.0), _ 2 * x, transmute(-7, imageHeight, 1.0) If (basenum + 1) Mod 10 = 0) Then /if the basecount is divisible by ten /add a number gd.DrawLine(New Pen(dfcolor), 2 * x, transmute(-20, imageHeight, 1.0)
16、 _ 2 * x, transmute(-25, imageHeight, 1.0) gd.DrawString(basenum + 1, dffont, Brushes.Black, _ (2 * x - 3), transmute(-36, imageHeight, 1.0) End If Select Case seq(basenum) Case A, a dfbrush = abrush Case C, c dfbrush = cbrush Case G, g dfbrush = gbrush Case T, t dfbrush = tbrush Case Else dfbrush
17、 nbrush End Select gd.DrawString(seq(basenum), dffont, dfbrush, (2 * x - 3), transmute(-18, imageHeight, 1.0) dfbrush = Brushes.Black here += 1 basenum += 1 End If End If Next Next Return out End Function Public Function getabasebyid(ByVal x As Integer) As Char 输入一个位图坐标,得到相应的一个base If x sequence.Le
18、ngth - 1 Then Return R End If Return CType(sequence.Chars(x), Char) End Function Public Function getsiglebase(ByVal x As Integer) As Char 输入一个位图坐标,得到相应的一个base Dim basenum As Integer = getbaseX(x) MsgBox(basenum) If basenum sequence.Length - 1 Then Return R End If Return CType(sequence.Chars(basenum)
19、 Char) End Function Public Function getbaseX(ByVal x As Integer) As Integer 根据输入的坐标得到最近base的索引(x方向) Dim xidx, xs, xsmin As Integer If x 2 * TraceLength Then errstring = 坐标越界! Return -1 Exit Function End If Dim bc() As Integer = Basecalls xsmin = 2 * TraceLength - 2 For i As Integer = 0 To bc.Length
20、 - 1 xs = (x - bc(i) * 2) 2 If xs xsmin Then xsmin = xs xidx = i End If Next MsgBox(xsmin) MsgBox(bc(xidx) bc = Nothing Return xidx End Function Public Function getbaseLX(ByVal seq As String, ByVal count As Integer, ByVal islast As Boolean) As Integer 得到要查找询列的 Dim idx As Integer idx = getbaseX(seq,
21、count, islast) If idx = -1 Then Return -1 Return Basecalls(idx) * 2 End Function Public Function getbaseLX(ByVal idx As Integer) As Integer 得到要查找询列的坐标 If idx = Basecalls.Length Then Return -1 Return Basecalls(idx) * 2 End Function Public Function getbaseY_cf(ByVal idx As Integer) As Integer 得到该序列的置信
22、度 transmute(A(x + 1), imageHeight, scale) If idx sequence.Length - 1 Then Return R End If Dim base As Char = sequence.Chars(idx) Dim YY As Integer() Select Case base Case A, a YY = A lable = A Case T, t YY = T lable = T Case C, c YY = C lable = C Case G, g YY = G lable = G Case Else MsgBox(r) End Se
23、lect If IsNothing(YY) Then Return -1 Dim Yidx, xidx As Integer xidx = getbaseLX(idx) If xidx = -1 Then Return -1 Yidx = YY(Basecalls(idx) YY = Nothing Return Yidx End Function Public Function getbaseX(ByVal seq As String, ByVal count As Integer, ByVal islast As Boolean) As Integer 根据序列查找索引 If sequen
24、ce = Then Return -1 End If seq = seq.ToLower Dim seq1 As String = sequence.ToLower Dim idx, i, x, ass As Integer x = 1 idx = seq1.IndexOf() ass = 0 While i -1 i = seq1.IndexOf(seq) If i -1 Then ass += i + seq.Length seq1 = seq1.Substring(i + seq.Length) End If If x = count Then If i = -1 Then idx =
25、1 Else idx = ass End If Exit While End If x += 1 End While If idx = -1 Then Return -1 End If MsgBox(islast) If Not islast Then idx -= seq.Length End If MsgBox(idx) Return idx Return Basecalls(idx) * 2 注意这里要不要*2 End Function Private Sub setIndex() Dim DataCounter, PBASCounter, PLOCCounter, NumRecord
26、s As Integer Dim RecNameArray(3) As Byte Dim RecName As String Dim record = 0 Dim myRund1, mydate1, myDYEP1, myMACH1, myMODL1, myBCAL1 As Integer DataCounter = 0 PBASCounter = 0 PLOCCounter = 0 IndexBase = getIntAt(AbsIndexBase + MacJunk) NumRecords = getIntAt(AbsIndexBase - 8 + MacJunk) For record
27、 0 To NumRecords - 1 getSubArray(RecNameArray, (IndexBase + (record * 28) RecName = ToString_ASC(RecNameArray) If RecName = FWO_ Then FWO = IndexBase + (record * 28) + 20 If RecName = DATA Then DataCounter += 1 If (DataCounter = 9) Then DATA9 = IndexBase + (record * 28) + 20 If (DataCounter = 10) T
28、hen DATA10 = IndexBase + (record * 28) + 20 If (DataCounter = 11) Then DATA11 = IndexBase + (record * 28) + 20 If (DataCounter = 12) Then DATA12 = IndexBase + (record * 28) + 20 End If If RecName = PBAS Then PBASCounter += 1 If (PBASCounter = 2) Then PBAS2 = IndexBase + (record * 28) + 20 End If If
29、RecName = PLOC Then PLOCCounter += 1 If (PLOCCounter = 2) Then PLOC = IndexBase + (record * 28) + 20 End If Private myRund, mydate, myDYEP, myMACH, myMODL, myBCAL As String If RecName.ToUpper = RUND Then myRund1 = IndexBase + (record * 28) + 20 End If If RecName.ToUpper = DATE Then myRund1 = IndexBa
30、se + (record * 28) + 20 End If If RecName.ToUpper = DYEP Then myRund1 = IndexBase + (record * 28) + 20 End If If RecName.ToUpper = MACH Then myRund1 = IndexBase + (record * 28) + 20 End If If RecName.ToUpper = BCAL Then myRund1 = IndexBase + (record * 28) + 20 End If If RecName.ToUpper = MODL Then m
31、yRund1 = IndexBase + (record * 28) + 20 End If Next TraceLength = getIntAt(DATA12 - 8) SeqLength = getIntAt(PBAS2 - 4) PLOC = getIntAt(PLOC) + MacJunk DATA9 = getIntAt(DATA9) + MacJunk DATA10 = getIntAt(DATA10) + MacJunk DATA11 = getIntAt(DATA11) + MacJunk DATA12 = getIntAt(DATA12) + MacJunk PBAS2 =
32、 getIntAt(PBAS2) + MacJunk myRund = getIntAt(PBAS2) + MacJunk mydate = getIntAt(PBAS2) + MacJunk myDYEP = getIntAt(PBAS2) + MacJunk myMACH = getIntAt(PBAS2) + MacJunk myMODL = getIntAt(PBAS2) + MacJunk myBCAL = getIntAt(PBAS2) + MacJunk End Sub Private Sub setBasecalls() Dim baselenth As Integer = SeqLength - 1 ReDim Basecalls(baselenth) Dim qq(baselenth * 2) As Byte Dim i As Integer getSubArray(qq, PLOC) Dim readint As New Abitracer.mystream For i = 0 To SeqLength - 1 Try Basecalls(i) = readint.read_int16_next(qq) Catch ex As Exception errstring = ex.ToString End Try Next readint = Nothing E