1、烟草核酸数据库管理系统源程序云南省烟草科学研究所2006-12-18源程序的前 10页ImportsSystemImportsSystem.ioImportsSystem.TextPublicClass Abitracer 解析一个 abi 文件/the next three lines are the important persistent dataPrivatesequence AsStringPrivateA(), G(), C(), T(), Basecalls()As IntegerPrivateTraceLength, SeqLengthAs Integer/This is th
2、e actual file data.PrivateTraceData()As BytePrivatemaximum As Integer= 0/the next four declaration lines comprise the file index informationPrivateMacJunk As Integer= 0/sometimes when macintosh files are/FTPed in binary form, they have 128 bytes/of crap pre-pended to them. This constant/allows ABITr
3、ace to handle that in a way that /is invisible to the user.PrivateShared AbsIndexBaseAs Integer = 26/The file location of the Index pointerPrivateIndexBase, PLOC As IntegerPrivateATraceStart, CTraceStart, GTraceStart, TTraceStartAs Integer/the next declaration is for the actual file pointersPrivateD
4、ATA9, DATA10, DATA11, DATA12, PBAS2, FWOAs IntegerPrivate stremtempfile As String = stream Dim Basecalls() As IntegerDim acolorAs Color = Color.DarkGreenDim ccolorAs Color = Color.BlueDim gcolorAs Color = Color.BlackDim tcolorAs Color = Color.RedDim ncolorAs Color = Color.PinkDim abrushAs Brush = Br
5、ushes.BlueDim cbrushAs Brush = Brushes.RedDim gbrushAs Brush = Brushes.DarkGreenDim tbrushAs Brush = Brushes.BlackDim nbrushAs Brush = Brushes.PinkDim backcolor As Color = Color.WhiteDim dffontAs Font = NewFont(Times New Roman, 10)PrivatemyRund, mydate, myDYEP, myMACH, myMODL, myBCAL As StringPublic
6、lableAsStringPrivateerrstringPublicFunctionABITrace( ByVal ABIFile()As Byte ) As BooleaninitData(ABIFile)Iferrstring ReturnFalseThenElseReturnTrueEnd IfEnd FunctionPublicFunctionABITrace(ByVal ABIFileAs String)As BooleanIfABIFile = Thenerrstring = 请输入文件!ReturnFalseExitFunctionEnd IfDim bytes()As Byt
7、eDim fsAs FileStreamDim readerAs BinaryReaderTryfs =NewFileStream(ABIFile, FileMode.Open)reader =NewBinaryReader(fs)bytes = reader.ReadBytes(fs.Length)reader.Close()fs.Close()fs =NothingCatch exAs Exceptionerrstring = ex.ToStringReturnFalseExitFunctionEnd TryIfIsNothing(bytes)Thenerrstring = 无效文件!Re
8、turnFalseExitFunctionEnd Iferrstring = initData(bytes)Iferrstring ReturnFalseThenElseReturnEnd IfTrueEnd FunctionPrivateSub initData(ByVal fileData()As Byte )TraceData = fileDataIfisABI()ThensetIndex()setBasecalls()setSeq()setTraces()End IfEnd SubPublicSub getImage(ByRef outAs PictureBox,ByVal width
9、ScaleAs Integer)out.Image =CType(getImage(out.Height, widthScale), Image)End SubPublicFunctiongetImage(ByVal heightAs Integer,ByVal widthScaleAs Double )As BitmapDim out As Bitmap out = NewBitmap(CInt (TraceLength * 2 * widthScale), height)out.Widthout.Width = TraceLength * widthScaleDim imageHeight
10、As Integer= out.Height out.Height = imageHeightDim gdDim mypen As PenDim scaleAs Doublescale = calculateScale(out.Height)Dim bc()As Integer= Basecallsbc 可能是定义nt 所在的坐标位置Dim seq()As CharDim dfcolorAs Color = Color.BlackDim dfbrush = Brushes.BlackDim aaAs Brushseq = sequence.ToCharArraygd = Graphics.Fr
11、omImage(out)gd.Clear(backcolor)Dim here, basenumAs Integerhere = 0basenum = 0For qAs Integer= 1To 5For xAs Integer= 0To 2 * TraceLength - 2Ifq = 1Then 画A的轨迹 g.setColor(acolor)gd.DrawLine(NewPen(acolor), 2 * x, transmute(A(x), imageHeight, scale), _2 * (x + 1), transmute(A(x + 1), imageHeight, scale)
12、End IfIfq = 2Thengd.DrawLine(NewPen(ccolor), 2 * x, transmute(C(x), imageHeight, scale), _ 2 * (x + 1), transmute(C(x + 1), imageHeight,scale)End IfIfq = 3Thengd.DrawLine(NewPen(tcolor), 2 * x, transmute(T(x), imageHeight, scale), _ 2 * (x + 1), transmute(T(x + 1), imageHeight,scale)End IfIfq = 4The
13、ngd.DrawLine(NewPen(gcolor), 2 * x, transmute(G(x), imageHeight, scale), _ 2 * (x + 1), transmute(G(x + 1), imageHeight,scale)End IfIfq = 5Then 画其他内容的If(here bc.Length - 1)Or (basenum seq.Length - 1)Then ExitForIfxMod 30 = 0Thengd.DrawString(2 * x, dffont, Brushes.Black, _ (2 * x - 3), transmute(-27
14、 imageHeight, 1.0) End IfIf(bc(here) = x)Thengd.DrawLine(NewPen(dfcolor), 2 * x, transmute(-2, imageHeight, 1.0), _2 * x, transmute(-7, imageHeight, 1.0)If(basenum + 1)Mod10 = 0)Then /if the basecount is divisible by ten/add a numbergd.DrawLine(NewPen(dfcolor),2 * x,transmute(-20,imageHeight,1.0),_
15、2 * x, transmute(-25, imageHeight, 1.0)gd.DrawString(basenum + 1, dffont, Brushes.Black, _(2 * x - 3), transmute(-36, imageHeight, 1.0)End IfSelectCase seq(basenum)Case A, adfbrush = abrushCase C, cdfbrush = cbrushCase G, gdfbrush = gbrushCase T, tdfbrush = tbrushCase Elsedfbrush = nbrushEnd Selectg
16、d.DrawString(seq(basenum), dffont, dfbrush, (2 * x - 3), transmute(-18, imageHeight, 1.0)dfbrush = Brushes.Black 输入一个位图坐标,得到相应的一个here += 1basenum += 1End IfEnd IfNextNextReturn outEnd FunctionPublicFunctiongetabasebyid(ByVal xAs Integer )As CharbaseIfx sequence.Length - 1Return REnd IfThenReturnCTyp
17、e(sequence.Chars(x),Char)End FunctionPublicFunctiongetsiglebase(ByVal xAs Integer )As Char 输入一个位图坐标,得到相应的一个baseDim basenum As Integer= getbaseX(x)MsgBox(basenum)Ifbasenum sequence.Length - 1Return REnd IfThenReturnCType(sequence.Chars(basenum),Char)End FunctionPublicFunctiongetbaseX(ByVal xAs Intege
18、r )As Integer 根据输入的坐标得到最近 base的索引( x 方向)Dim xidx, xs, xsminAs IntegerIfx 2 * TraceLengthThenerrstring = 坐标越界! Return -1ExitFunctionEnd IfDim bc()As Integer= Basecallsxsmin = 2 * TraceLength - 2For iAs Integer= 0To bc.Length - 1xs = (x - bc(i) * 2) 2Ifxs xsminThenxsmin = xsxidx = iEnd IfNextMsgBox(xs
19、min) MsgBox(bc(xidx)bc =NothingReturn xidxEnd FunctionPublic Function getbaseLX( ByVal seq As String , ByVal count As Integer , ByVal islast As Boolean ) As Integer 得到要查找询列的Dim idxAs Integeridx = getbaseX(seq, count, islast)Ifidx = -1Then Return -1Return Basecalls(idx) * 2End FunctionPublicFunctiong
20、etbaseLX( ByVal idxAs Integer)As Integer 得到要查找询列的坐标If idx = Basecalls.LengthThen Return -1Return Basecalls(idx) * 2End FunctionPublicFunctiongetbaseY_cf(ByVal idxAs Integer) As Integer 得到该序列的置信度transmute(A(x + 1), imageHeight, scale)Ifidx sequence.Length - 1ThenReturn REnd IfDim baseAs Char = sequen
21、ce.Chars(idx)Dim YY As Integer()SelectCase baseCase A, aYY=Alable = ACase T, tYY = Tlable = TCase C, cYY = C lable = CCase G, g YY=Glable = G Case ElseMsgBox(r) End SelectIfIsNothing(YY)Then Return -1Dim Yidx, xidxAs Integer xidx = getbaseLX(idx) If xidx = -1 Then Return -1Yidx = YY(Basecalls(idx)YY
22、 =NothingReturn YidxEnd FunctionPublicFunctiongetbaseX( ByVal seq As String, ByVal countAs Integer ,ByVal islastAs Boolean ) 根据序列查找索引Ifsequence = ThenReturn -1End Ifseq = seq.ToLowerDim seq1As String= sequence.ToLowerDim idx, i, x, assAs Integerx = 1idx = seq1.IndexOf()ass = 0While i -1i = seq1.Inde
23、xOf(seq)Ifi -1Thenass += i + seq.Lengthseq1 = seq1.Substring(i + seq.Length)End IfIfx = countIfi = -1ThenThenidx = -1Elseidx = assEnd IfExitWhileEnd Ifx += 1End WhileIfidx = -1ThenReturn -1End If MsgBox(islast)IfNot islastThenidx -= seq.LengthEnd IfMsgBox(idx)Return idxReturn Basecalls(idx) * 2 注意这里
24、要不要*2End FunctionPrivateSub setIndex()Dim DataCounter, PBASCounter, PLOCCounter, NumRecordsDim RecNameArray(3)As ByteDim RecName As StringAs IntegerDim record = 0Dim myRund1, mydate1, myDYEP1, myMACH1, myMODL1, myBCAL1 As IntegerDataCounter = 0PBASCounter = 0PLOCCounter = 0IndexBase = getIntAt(AbsIn
25、dexBase + MacJunk)NumRecords = getIntAt(AbsIndexBase - 8 + MacJunk)For record = 0To NumRecords - 1getSubArray(RecNameArray, (IndexBase + (record * 28)RecName = ToString_ASC(RecNameArray)IfRecName = FWO_Then FWO = IndexBase + (record * 28) + 20IfRecName = DATAThenDataCounter += 1If(DataCounter = 9)Th
26、en DATA9 = IndexBase + (record * 28) + 20If(DataCounter = 10)Then DATA10 = IndexBase + (record * 28) + 20If(DataCounter = 11)Then DATA11 = IndexBase + (record * 28) + 20If(DataCounter = 12)Then DATA12 = IndexBase + (record * 28) + 20End IfIfRecName = PBASThenPBASCounter += 1If(PBASCounter = 2)Then P
27、BAS2 = IndexBase + (record * 28) + 20End IfIfRecName = PLOCThenPLOCCounter += 1If(PLOCCounter = 2)Then PLOC = IndexBase + (record * 28) + 20End IfPrivate myRund, mydate, myDYEP, myMACH, myMODL, myBCAL As String If RecName.ToUpper = RUND ThenmyRund1 = IndexBase + (record * 28) + 20End IfIfRecName.ToU
28、pper = DATEThenmyRund1 = IndexBase + (record * 28) + 20End IfIfRecName.ToUpper = DYEPThenmyRund1 = IndexBase + (record * 28) + 20End IfIfRecName.ToUpper = MACHThenmyRund1 = IndexBase + (record * 28) + 20End IfIfRecName.ToUpper = BCALThenmyRund1 = IndexBase + (record * 28) + 20End IfIfRecName.ToUpper
29、 = MODLThenmyRund1 = IndexBase + (record * 28) + 20End IfNextTraceLength = getIntAt(DATA12 - 8)SeqLength = getIntAt(PBAS2 - 4)PLOC = getIntAt(PLOC) + MacJunkDATA9 = getIntAt(DATA9) + MacJunkDATA10 = getIntAt(DATA10) + MacJunkDATA11 = getIntAt(DATA11) + MacJunkDATA12 = getIntAt(DATA12) + MacJunkPBAS2
30、 = getIntAt(PBAS2) + MacJunkmyRund = getIntAt(PBAS2) + MacJunkmydate = getIntAt(PBAS2) + MacJunkmyDYEP = getIntAt(PBAS2) + MacJunkmyMACH = getIntAt(PBAS2) + MacJunkmyMODL = getIntAt(PBAS2) + MacJunkmyBCAL = getIntAt(PBAS2) + MacJunkEnd SubPrivateSub setBasecalls()Dim baselenthAs Integer= SeqLength -
31、 1ReDimBasecalls(baselenth)Dim qq(baselenth * 2)Dim iAs IntegerAs BytegetSubArray(qq, PLOC)Dim readintAs NewAbitracer.mystreamFor i = 0To SeqLength - 1TryBasecalls(i) = readint.read_int16_next(qq)Catch exAs Exceptionerrstring = ex.ToStringEnd TryNextreadint =NothingEnd SubPrivateSub setSeq()Dim xAs
32、IntegerDim tempseq(SeqLength - 1)As CharFor x = 0To SeqLength - 1tempseq(x) = ChrW(TraceData(PBAS2 + x)Nextsequence = ToString_char(tempseq)End SubPrivateSub setTraces()Dim pointers(3)As Integer alphabetical, 0=A, 1=C, 2=G, 3=TDim datas(3)AsIntegerDim order(3)AsCharDim iAs Integerdatas(0) = DATA9dat
33、as(1) = DATA10datas(2) = DATA11datas(3) = DATA12For i = 0To 3order(i) = ChrW(TraceData(FWO + i)NextFor i = 0To 3SelectCase order(i)Case a, Apointers(0) = datas(0)Case c, Cpointers(1) = datas(1)Case g, Gpointers(2) = datas(2)Case t, Tpointers(3) = datas(3)Case Elseerrstring = Trace contains illegal v
34、alues!MsgBox()ExitSubEnd SelectNextReDimA(2 * TraceLength - 1)ReDimC(2 * TraceLength - 1)ReDimG(2 * TraceLength - 1)ReDimT(2 * TraceLength - 1)For i = 0To 3Dim qq(TraceLength * 2 - 1)As BytegetSubArray(qq, pointers(i)Dim xAs IntegerDim rdAs NewmystreamFor x = 0To 2 * TraceLength - 1TryIf(i = 0)Then
35、A(x) = rd.read_int16_next(qq)If(i = 1)Then C(x) = rd.read_int16_next(qq)If(i = 2)Then G(x) = rd.read_int16_next(qq)If(i = 3)Then T(x) = rd.read_int16_next(qq)Catch exAs Exceptionerrstring = ex.ToStringEnd TryNextrd =NothingNextEnd SubPrivateFunctionisABI()As BooleanDim ABI(3)As CharDim i, nAs Intege
36、rFor i = 0To 2ABI(i) = ChrW(TraceData(i)NextIfABI(0) = AAnd ABI(1) = BAnd ABI(2) = IThenReturnTrueElseFor i = 128To 130ABI(i) = ChrW(TraceData(i)NextIfABI(0) = AAnd ABI(1) = BAnd ABI(2) = IThenReturnTrueElseReturnFalseEnd IfEnd IfEnd FunctionPrivateFunctiongetIntAt(ByVal pointerAs Integer)As Integer
37、Dim outAs Integer= 0Dim temp()As Byte =New Byte (3) getSubArray(temp, pointer)Dim mystm As Newmystreamout = mystm.read_int32(temp)mystm =Nothing aa = Me.ToString_Uni(temp) Return outEnd FunctionPrivateSub getSubArray(ByRef bAs Byte (),ByVal traceDataOffsetAs Integer )Dim xAs IntegerDim aaAs ByteFor x = 0To b.Length - 1aa = TraceData(traceDataOffset + x) b(x) = aaNextEnd SubPrivateFunctioncalculateScale(ByVal heightAs Integer )As DoubleDim newScaleAs Double = 0.0Dim max As Double = getMaximum()Dim htAs Double = he