Channel 9 Interview: Look Who's Working on Visual Basic (Beth Massi)
23 July 08 03:00 PM

Last month when I was in Redmond I was pulled into a photo with some of the people working on Visual Basic. Do you notice something quirky about these pictures (besides me)? Yes, they are all wearing grey shirts! There's apparently a running joke going on with how Jonathan Aneja (top row, 4th from the left in the first picture) only wears grey. So the team all wore grey to see if he would even notice!

The joke is explained in this Channel 9 interview with the VB Language Design Team. I sat down with the VB Language design team and asked them about their design process, favorite features, their thoughts on other languages, as well as what the Visual Basic language strategy really is. It was a fun and enlightening interview with a group of really smart people lead by Paul Vick.

Enjoy,
-Beth Massi, VS Community

Postedby VBTeam | 3 Comments    
Filed under: ,
WANTED: Your feedback on a potential Call Hierarchy feature (Lisa Feigenbaum)
22 July 08 07:45 AM

Last post, I introduced the VS Languages Future Focus page on Code Gallery. This time, we'd like to get your feedback on another potential IDE feature: Call Hierarchy.

Please find a description of the feature here:
http://code.msdn.microsoft.com/vslangfutures/Wiki/View.aspx?title=Call%20Hierarchy&referringTitle=Home

Please leave your feedback here:
http://code.msdn.microsoft.com/Thread/View.aspx?ProjectName=vslangfutures&ThreadId=123

Thanks!
Lisa

DISCLAIMER: It is important that readers of Future Focus topics have the right expectations. The information presented is not a binding commitment nor is it necessarily our most current design. The Visual Studio schedule, unforeseen technical problems, intellectual property rights and competitive pressures may impact our schedule or our ability to share our plans. Future focus is not designed to present a detailed specification of future features. Instead, its purpose is to outline in broad strokes, and easy to understand terms, the directions the team might take in the future. We will read all comments submitted to Future Focus, and consider them in our designs.

Postedby VBTeam | 3 Comments    
Filed under: ,
WANTED: Your feedback on a potential Quick Search & Navigate feature (Lisa Feigenbaum)
21 July 08 01:07 AM

We've started a new page on Code Gallery called "Future Focus", to collect your feedback on ideas that we're considering for future versions of Visual Studio.

The latest post is regarding an IDE feature to help you quickly search for and navigate to symbols in your code. Please see a description of the feature here:
http://code.msdn.microsoft.com/vslangfutures/Wiki/View.aspx?title=Symbol%20Search&referringTitle=Home

Please leave your feedback on this feature here:
http://code.msdn.microsoft.com/Thread/View.aspx?ProjectName=vslangfutures&ThreadId=520

Thanks!
Lisa

DISCLAIMER: It is important that readers of Future Focus topics have the right expectations. The information presented is not a binding commitment nor is it necessarily our most current design. The Visual Studio schedule, unforeseen technical problems, intellectual property rights and competitive pressures may impact our schedule or our ability to share our plans. Future focus is not designed to present a detailed specification of future features. Instead, its purpose is to outline in broad strokes, and easy to understand terms, the directions the team might take in the future. We will read all comments submitted to Future Focus, and consider them in our designs.

Postedby VBTeam | 3 Comments    
Filed under: ,
Community Article: Using Windows Communication Foundation with Windows Workflow Foundation – Part 1 (Beth Massi)
18 July 08 10:19 AM

This week on the VB Dev Center we're featuring another community submitted article by Maurice de Beijer (VB MVP) on Using Windows Communication Foundation with Windows Workflow Foundation. Maurice has a great wiki as well that you should check out if you're doing Windows Workflow development.

In this article he shows you how to use SendActivity which enables you to call WCF as well as standard web services in your workflows. Stay tuned for the next article which will show you how to use ReceiveActivity, which enables a you to publish a workflow as a WCF service.

Enjoy,
-Beth Massi, VS Community

Postedby VBTeam | 1 Comments    
Filed under: , ,
How-Do-I Videos: WPF Forms over Data (Beth Massi)
17 July 08 02:34 PM

If you haven't noticed, we released a couple new how-to videos on the VB Dev Center starting a new series which is focused on data-based application development in Windows Presentation Foundation using Visual Studio 2008. The videos are also being featured on www.WindowsClient.net today. Look for many more in the coming weeks!

Enjoy,
-Beth Massi, VS Community

Postedby VBTeam | 2 Comments    
Filed under: ,
Article: Sharpening Your Axis with Visual Basic 9 (Beth Massi)
30 June 08 05:30 PM

In the July/August issue of CoDe Magazine there's an article I wrote with Avner Aharoni (the Program Manager on XML literals) called Sharpening Your Axis with Visual Basic 9. (They just opened up online access to even non-subscribers today!) I highly recommend this article which shows you from the beginning how XML literals, embedded expressions and axis properties work in Visual Basic.

I start with the basic syntax and definitions and then walk through the XML to Schema tool (which has been added to VS2008 SP1) to enable XML IntelliSense, as well as show some practical examples of using these features with LINQ. Avner describes how IntelliSense works and discusses advanced scenarios with XML namespaces. We end with tips-and-tricks which get you thinking about using XML literals in other text generation/manipulation scenarios.

If you like this topic, so do I! Check out the XML topic feed from my blog for more resources.

Enjoy,
-Beth Massi, VS Community

Postedby VBTeam | 2 Comments    
Filed under: , , ,
PInvoke Interop Assistant on CodePlex (Jared Parsons)
20 June 08 09:27 AM

I'm happy to announce that the PInvoke Interop Assistant tool is now available on CodePlex.  This includes the binaries, source code and the dev authored unit tests. 

It is hosted on the more general CLR Interop Tools page. 

http://www.codeplex.com/clrinterop

I will be actively maintaining this tool in the future and (hopefully) adding more features.  There were several features we cut just before release due to QA costing that I would like to add back (including VS integration, wrapper functions).  

Please post any suggestions you have for the tool on the site and we will definitely consider them.

Jared Parsons

http://blogs.msdn.com/jaredpar

Protein is Good for You, part 2 (Matt Gertz)
17 June 08 07:30 AM

In yesterday’s blog post, I walked through an engine for translating DNA to its amino acid results via messenger RNA.  In today’s blog, we’ll work on the visualization using WPF StackPanels.  (This example requires VS2008, although it could certainly be written in WinForms as well with just a little bit of extra work.)

Caution:  The point of this blog is to demonstrate StackPanels, and specifically how you can control their orientation and nesting.  Consequently, for the sake of that argument, I’m creating a lot of text objects (one for each base and each amino) and nesting them to demonstrate this.  For a really robust program, I would ditch the extra objects and just do owner draw directly.  In other words, don’t use this example on enormous 20000-sequence strands of DNA, as neither you nor your PC would like the performance results.

StackPanels

In the last post, I added a ScrollViewer to the Window, changed it to scroll horizontally instead of vertically, but otherwise left it alone.  Now we’ll dig into the details of how we’ll populate it with StackPanels. 

StackPanels expose a very easy way to organize a set of drawable objects on the screen.  StackPanels expose a Children collection, and when you add objects to the that collection, they’ll display in the order you add them and in the direction you specify.  What’s really cool is that StackPanels will nest with each other, and I’ll take advantage of that fact by creating three StackPanels that organize information horizontally (one each for DNA, mRNA, and aminos), and then adding them to a parent StackPanel so that they line up with each other.  I’ll then add the parent StackPanel to the ScrollViewer so that the alignment of all three sub-panels can be seen.

Each of the sub-panels will contain one of more text objects which either contain the abbreviation of a base, the abbreviation of an amino, or blank space (representing unused intron material).  Aminos correspond to three bases, and so those text objects need to be three times wider.  I’ll create some helper functions to return the appropriate text objects:

    Const baseWidth As Integer = 16

 

    Private Function DrawBase(ByVal base As Char) As TextBlock

        Dim baseTextBlock As New TextBlock

        Select Case base ' Switch for colors

            Case "C"

                baseTextBlock.Background = Brushes.LightSalmon

            Case "G"

                baseTextBlock.Background = Brushes.LightGoldenrodYellow

            Case "A"

                baseTextBlock.Background = Brushes.LightGreen

            Case "T"

                baseTextBlock.Background = Brushes.LightSkyBlue

            Case "U"

                baseTextBlock.Background = Brushes.LightSteelBlue

        End Select

 

        baseTextBlock.Inlines.Add(New Bold(New Run(base)))

        baseTextBlock.Height = 32

        baseTextBlock.Width = baseWidth

        baseTextBlock.TextAlignment = TextAlignment.Center

 

        Return baseTextBlock

    End Function

 

That last function will be used by both DNA and RNA, creating and returning a fixed block of an appropriate color (a different one for each base) 16 x 32 pixels with the base abbreviation (passed into the function) centered within it.  I've chosen light colors so that the dark text will show up against the background properly. 

For the amino chains, it’s pretty similar, except that each block is three times wider, to keep the amino lined up with the codon:

    Private Function DrawAmino(ByVal amino As String) As TextBlock

        Dim aminoTextBlock As New TextBlock

        Select Case amino ' Switch for colors

            Case "Phe"

                aminoTextBlock.Background = Brushes.AliceBlue

            Case "Leu"

                aminoTextBlock.Background = Brushes.Beige

            Case "Ser"

                aminoTextBlock.Background = Brushes.Cyan

            Case "Tyr"

                aminoTextBlock.Background = Brushes.LightSeaGreen

           ' (Etc… the other aminos omitted for brevity’s sake; see final code for full list.)

 

        End Select

        aminoTextBlock.Inlines.Add(New Bold(New Run(amino)))

        aminoTextBlock.Height = 32

        aminoTextBlock.Width = baseWidth * 3

        aminoTextBlock.TextAlignment = TextAlignment.Center

        Return aminoTextBlock

    End Function

And for empty space, I just pass in the number of spaces required and multiple it by the baseWidth:

    Private Function DrawNoMap(ByVal noMapSize As Integer) As TextBlock

        Dim noMapTextBlock As New TextBlock

        noMapTextBlock.Background = ScrollViewer1.Background

        noMapTextBlock.Height = 32

        noMapTextBlock.Width = baseWidth * noMapSize

        Return noMapTextBlock

    End Function

 

Now I have the tools; we can put them to good use.  First, let’s create & populate the DNA StackPanel:

    Private Function DrawBases(ByVal s As String) As StackPanel

        ' DNA goes here (horizontal orientation):

        Dim myStackPanel As New StackPanel

        myStackPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left

        myStackPanel.VerticalAlignment = System.Windows.VerticalAlignment.Top

        myStackPanel.Orientation = Orientation.Horizontal

 

        'Add child elements to the parent StackPanel.

        For i As Integer = 0 To s.Length - 1

            myStackPanel.Children.Add(DrawBase(s(i)))

        Next

 

        Return myStackPanel

    End Function

 

This is a simple function that does three things:

(1)    Create a stack panel that has horizontal orientation, containing object that start from the top left.

(2)    Step through each base in the DNA or RNA and add the TextBlock for it created in DrawBase.

(3)    Return the completed StackPanel

I can use this for both DNA and mRNA just by passing in the appropriate string.  Aminos are a bit trickier because I’ve decided to save them as lists of strings rather than one long string (to make it easier to access individual proteins should I wish to expand this program in the future):

    Private Function DrawAminos() As StackPanel

        ' Aminos go here (horizontal orientation):

        Dim myStackPanelAminos As New StackPanel

        myStackPanelAminos.HorizontalAlignment = System.Windows.HorizontalAlignment.Left

        myStackPanelAminos.VerticalAlignment = System.Windows.VerticalAlignment.Top

        myStackPanelAminos.Orientation = Orientation.Horizontal

        'Add child elements to the parent StackPanel.

        For Each p In Proteins

            Dim i As Integer = 0

            Do While i < p.Length - 1

                If p(i) = " " Then

                    Dim noMapSize As Integer = 0

                    Do While i < p.Length AndAlso p(i) = " " ' Make sure we don't go over when lining things up

                        noMapSize += 1

                        i += 1 ' Skip piece of intron for spacing

                    Loop

                    myStackPanelAminos.Children.Add(DrawNoMap(noMapSize))

                Else

                    myStackPanelAminos.Children.Add(DrawAmino(p.Substring(i, 3)))

                    i += 3 ' Skip length of amino

                End If

            Loop

        Next

 

        Return myStackPanelAminos

    End Function

 

In this case, the panel is once again oriented horizontally from the top-left, but I have to (a) go through each string in the list looking for aminos to draw and (b) determine if there are spaces that need to take up room in the drawing but don’t contain actual amino content.  Sequences without a stop codon would always be the final sequence (because the engine would have run through the whole string looking for them) and are just ignored by the application; they imply space without having to explicitly draw that space, since nothing else comes after it. 

I don’t want to create a text block for each space in an adjacent block of spaces – that’s too wasteful even for a simple example like this – so I’ll determine the number of adjacent spaces whenever I encounter them and group them together in on big “no map” block.  The “gotcha” in the above code is that I need to make sure that I don’t go past the final character both when looking for aminos as well as when drilling through the spaces.

Now, having created all of the drawing code as well as the code that runs through the sequences and calls them, I can create a master function that kicks off the drawing.  First, I need to get rid of any old content in the ScrollViewer, tossing it into the garbage collector:

    Private Sub DrawResults()

        'Get rid of any old content

        Me.ScrollViewer1.Content = Nothing

 

Next, I’ll create the master stack panel.  Unlike the others, its orientation is vertical (which is the default, so I don’t need to explicitly state it), because I’m going to stack the other panels vertically from top-left:

        ' This stack panel will contian the other stack panels.

        ' It defaults to a vertical orientation

        Dim myStackPanel As New StackPanel

        myStackPanel.HorizontalAlignment = System.Windows.HorizontalAlignment.Left

        myStackPanel.VerticalAlignment = System.Windows.VerticalAlignment.Top

 

Now, I’ll use the previously defined helper functions to create and draw the sub-panels, and then add them to the parent StackPanel:

        Dim myStackPanelDNA As StackPanel = DrawBases(DNA)

        Dim myStackPanelRNA As StackPanel = DrawBases(RNA)

        Dim myStackPanelAminos As StackPanel = DrawAminos()

 

        myStackPanel.Children.Add(myStackPanelDNA)

        myStackPanel.Children.Add(myStackPanelRNA)

        myStackPanel.Children.Add(myStackPanelAminos)

 

Finally, I add the parent panel to the ScrollViewer:

        'Add the StackPanel as the lone Child of the Border

        Me.ScrollViewer1.Content = myStackPanel

 

    End Sub

I’m almost done now; there’s only one thing left to do.  I’ve got to call DrawResults() after the DNA is loaded and translated, so I’ll add this line of code to the end of the LoadSequenceBtn_Click handler:

       DrawResults()

And we’re done!  I can launch the application, load in a file, see the translation visually, and save the results.  For example, with a text file containing the string:

ACACGGGCGCGTACAAAAGATGAACTGGGGCCCCGCGCTACCGCCGCCACATTAAAAA

The output I save will look like:

ACACGGGCGCGTACAAAAGATGAACTGGGGCCCCGCGCTACCGCCGCCACATTAAAAA

UGUGCCCGCGCAUGUUUUCUACUUGACCCCGGGGCGCGAUGGCGGCGGUGUAAUUUUU

           MetPheSerThr               MetAlaAlaVal  

 

On the screen, it looks much prettier, and I can scroll left-to-right to see all of the results.

That’s it for this post.  The final code is posted at https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=templeofvb&ReleaseId=1172 -- enjoy!

‘Til next time,

  --Matt-
Postedby VBTeam | 1 Comments    
Filed under: , ,
Protein is Good for You (Matt Gertz)
16 June 08 10:21 PM

As I was preparing to graduate from the University of Michigan way back in the late eighties, I had a big decision to make regarding grad school – robotics at Carnegie Mellon, or biology at Washington State?  On the one hand, biology was something I’d always really loved, having even intended to go to med school at one point.  On the other hand, robotics was more likely to help me pay off my debts a very exciting field with a lot of challenges still ahead of it.  Ultimately, I chose robotics (gaining a degree that, to this day, I have never used), but I often wonder what it might have been like to go into biology. 

Anyway, back when I was dating my future wife (who was in the molecular biology graduate program), I wrote a quick’n’dirty program to translate DNA coding sequences to chains of amino acids for her advisor.  That was fun, and I got feel like I was participating in the research (in a very teeny-tiny way).  Beyond that, I haven’t had much interaction with hands-on biology work in many years, although I try to keep up with what’s going on.  Recently, though, I’ve been scrambling trying to come up with new ideas for blog articles, and that program I wrote nearly 18 years ago came to mind.  I’d never been happy with the visualization of the data, so I decided to give it a second try, this time using the WPF designer to help me out. 

In this blog, I’ll cover the creation of a program to translate DNA from proteins, and tomorrow I’ll talk about visualizing the results using StackPanel controls.  The overall example requires VS2008 or later to code up, although today’s blog code is mostly machinery that would pretty much work on either WinForms or WPF.

“Captain… the alien virus is rewriting his DNA!  He’s changing!”

One of the problems in being both a computer specialist and also somewhat knowledgeable about biology is that it’s very difficult to make it through your average Star Trek episode, between the bad computer science and the bad biology.  (For the record, changing your DNA won’t change your appearance, since the protein structures they code for already exist and represent roughly seven years of dead-end energy investment on your part.  If you’re lucky, any changes will have no impact at all or even be beneficial; if you’re less lucky, the cell will die or cause some deleterious behavior.)  At any rate, this will be a simple DNA/RNA/protein visualization program, and no DNA altering will be allowed. J

I’m not going to give a big overview on DNA transcription; if you don’t remember enough from school to follow along, the Wikipedia article on DNA is pretty good for refreshing one’s memory (as I found out).  For the purposes of this exercise, we’ll just note that DNA is used to determine which proteins are created for a cell: 

(1)    DNA is comprised of a combination of 4 base pairs (A, T, C, G) connected longitudinally by a sugar/phosphate group and latitudinally by hydrogen bonds.  A (adenine) always connects latitudinally to T (thymine), and C (cytosine) always connects to G (guanine).

(2)    During transcription, the DNA (a double-helix) in a given chromosome is cut down the middle

(3)    An mRNA (“messenger RNA”) string is built up from the DNA side which contains the appropriate information for that part of the string.   (RNA is very similar to DNA except that the connective sugar is ribose instead of deoxyribose, and thymine is replaced with uracil (U)).  The resulting mRNA string is an inverse copy of the strand it copied.  I’ll be using the terms mRNA and RNA interchangeably for the purpose of this blog.

(4)    Amino acids are assembled together based on the sequence of the mRNA.  It takes three bases to code for one amino, so given four bases, there are 4^3 = 64 possible combinations for a given triplet (codon) of bases.  Some codons code for the same amino; there are 20 standard aminos mapping to 61 codons.  (Three of the possible codons simply indicate the end of a sequence; one codon indicates the start of a sequence and also codes for a specific amino, methionine.)

Basically, the plan for the program is this:  allow the user to read in a sequence of DNA, automatically convert it to an mRNA sequence, and then convert it to zero or more sequences of amino acids.  We’ll then throw a visual representation of all strings onto the form.

The basic application

First, I’ll create a new WPF application called “VBProtein.”  On its grid, I’m going to throw three main controls:

(1)    A ScrollViewer control for display the sequences graphically.  I’ll set mine to be 112 pixels high (enough for three rows of sequences of height 32 pixels plus the scrollbar).  In the properties of the ScrollViewer, I’ll set “HorizontalScrollbarVisibility” to “Visible” and “VerticalScrollbarVisibility” to “Disabled,” since the sequences will be listed left-to-right.  I’ve also set its “TabIndex” to “0”.

(2)    A Button control labeled “Load” (“TabIndex” = “1”).

(3)    A Button control labeled “Save” (“TabIndex” = “2”).

I’ve also added a few label controls and changed a few colors, but that’s the all of the important stuff.  Everything else gets added in code, so let’s take a look at that.   Double-click on the window frame to generate the Window1_Loaded event.  We’ll populate it later, but for the moment we’ll concentrate on the members we’ll need for the application.  These are:

    Public Translations As New Microsoft.VisualBasic.Collection

    Public DNA As String

    Public RNA As String

    Public Proteins As New List(Of String)

 

We’ll load in the value of DNA, translate it to RNA, and then translate that to the Proteins – in other words, we’ll deal with those later.  Let’s worry about the Translations instead.

For the translations, I decided to go with a Collection since they are easy to work with, they support keys for lookup, and I’m not dealing with too many objects – just the 64 possible codons.  There’s a lot of information I’ll want to keep with each Translation:

    Enum Sequence

        Normal = 0

        SequenceStart = 1

        SequenceStop = 2

    End Enum

    Class Translation

        Public Sub New(ByVal Triplet As String, ByVal Acid As String, _

ByVal Mnem As Char, ByVal Clue As Sequence)

            Codon = Triplet

            Amino = Acid

            shortAmino = Mnem

            Usage = Clue

        End Sub

        Public Overrides Function ToString() As String

            Return Codon

        End Function

        Public Codon As String

        Public Amino As String

        Public shortAmino As Char

        Public Usage As Sequence

    End Class

 

Note that I’m overriding the “ToString” method to return the Codon value, which I’ll be using as a key in the collection.   With this structure, I can initialize the translation collection (abridged from the actual code for the purposes of legibility):

    Private Sub InitializeTranslations()

        Translations.Add(New Translation("UUU", "Phe", "F", Sequence.Normal), "UUU") ' Phenylalanine

        Translations.Add(New Translation("UUC", "Phe", "F", Sequence.Normal), "UUC") ' Phenylalanine

        Translations.Add(New Translation("UAA", "OCH", ".", Sequence.SequenceStop), "UAA") ' Ochre stop sequence

        Translations.Add(New Translation("UAG", "AMB", ".", Sequence.SequenceStop), "UAG") ' Amber stop sequence

 

        Translations.Add(New Translation("UGA", "OPA", ".", Sequence.SequenceStop), "UGA") ' Opal stop sequence

        Translations.Add(New Translation("AUG", "Met", "M", Sequence.SequenceStart), "AUG") ' Methionine

 

' Etc…

 

    End Sub

 

Each translation has a codon, the abbreviated name of the matching amino, the one-character name of the matching amino (which I never use, but what the heck), and a setting which determines if this is a normal codon, a starting codon, or a stopping codon.

Now, in the Window1_Load code, I’ll add the following:

        InitializeTranslations()

        SaveResultsBtn.IsEnabled = False

 

(The second line is unrelated to the previous code and just disables the Save button until we have something to save.)

I can now start writing the functional code.  Back on the grid, I’ll double-click the “Load” button, and in the resulting LoadSequenceBtn_Click event, I’ll add the following code:

        ' Load in the file

        Dim dlg As New OpenFileDialog

        dlg.Filter = My.Resources.FILT_FileFilter

        If dlg.ShowDialog() = True Then

            DNA = My.Computer.FileSystem.ReadAllText(dlg.SafeFileName)

        End If

 

As you can see, first I’m throwing up a file dialog to get the name of the file to load (which is just a TXT file filled with bases -- FILT_FileFilter is a resource I've mapped to "Text Files (*.txt)|*.txt"), and then I open it up and read it into the DNA string variable using a handy “My.Computer” function. 

Given the DNA, I can transcribe it to mRNA.  First, I’ll need a transcription function:

    Private Function Transcribe(ByVal Base As Char) As Char

        Select Case Base

            Case "A" ' Adenine

                Transcribe = "U" ' Uracil

            Case "T" ' Thymine

                Transcribe = "A" ' Adenine

            Case "G" ' Guanine

                Transcribe = "C" ' Cytosine

            Case "C" ' Cytosine

                Transcribe = "G" ' Guanine

            Case Else

                Throw New ApplicationException(String.Format(My.Resources.ERR_UnknownBase, Base))

        End Select

    End Function

 

This is a very simple function which, given a character representing a base, returns the character which is the corresponding base.  If it finds a character that it doesn’t understand, it throws an error, displaying a string (ERR_UnknownBase ) that I’ve defined in the project resources (right-click your project, choose “Properties,” and select the “Resources” tab from the resulting dialog to find the resources for the project).  Transcription is now very easy:

    Private Sub DNA2RNA()

        RNA = ""

        If DNA.Length < 6 Then Return ' Need two codons at least, or we're just wasting time.

        Dim mRNA As New StringBuilder(DNA.Length)

 

        For i As Integer = 0 To DNA.Length - 1

            mRNA.Append(Transcribe(DNA(i)))

        Next

        RNA = mRNA.ToString

    End Sub

 

First I check to make sure there’s at least two codons (six bases) before doing anything – if less than that, then you can’t have both a start and a stop.  Given that, I’ll iterate through the DNA string and collect the corresponding RNA characters.  To save memory thrashing, I’ll use a stringbuilder to collect those and then save the result out to the RNA string.

Transcribing mRNA to aminos is slightly more difficult.  We have to search the mRNA for a particular start sequence, and then end when one of three end sequences is found – and then repeat that again in case there are more sequences available farther along the mRNA string.  (That’s why I’ve used List (Of String) for the collected proteins instead of just one string – if I ever chose to expand this program, it’s nice to have all of the sequences in separate strings already.)  I’ll begin by freeing up any existing protein memory, doing the check on lengths, and setting up an index:

    Private Sub RNA2Proteins()

        ' First, find the start codon.  This is typically AUG.

        ' I'm deliberately not dealing with the rare exceptional

        ' cases sometimes found in mature mRNA.

        Proteins.Clear()

        If RNA.Length < 6 Then Return ' Need two codons at least, or we're just wasting time.

        Dim sProteins As New StringBuilder

        Dim currentIndex = 0

 

As with the DNA->RNA case, I’ll need a way of collecting bits of a string that doesn’t thrash memory, and thus I’ve declared a StringBuilder above.  The currentIndex will track where we are in the RNA string.

I’ve got to look for the first entry codon.  Since there’s only one type of those, I can use InStr to find it.  I’ve got to be careful, though, because InStr is 1-based and not 0-based:

        Do While currentIndex < RNA.Length

            ' Get past the current intron code (so-called "junk" DNA,

            ' though it may serve a function after all) to

            ' the next exon.

            ' CONSIDER:  We could also modify this method to create <