Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Perl - how to get the last few elements in a string

    Hi folks,

    Could any one please tell me how to get the last few elements from a string using perl?

    for eg, $string= ATTGGCTACC;

    if I want to print the last 3 elements in the above string, how can I script it?


    Thank you,

    Pradhaun.

  • #2
    Why don't you try this: http://lmgtfy.com/?q=perl+substring

    Comment


    • #3
      $substring=substr($string,7,3);
      or $substring=substr($string,-3,3);

      Comment


      • #4
        thank you heiya!! It worked out!!
        Thank you so much!!

        Comment


        • #5
          The substr always seems alien to me, whereas simple regexes seem natural.

          my ($substring) =$string=~ /(...)$/;

          speaks to me "capture the last 3 characters before the end of the string and assign them to $substring. (Okay the parentheses around $substring, denoting that the characters themselves should be assigned to $substring, not just whether the test succeeded or not -- that is not very intuitive.)

          But if I want to only capture the last three bases if they are sequence characters, only a minor change is required:

          my ($substring)=$string=~/([ACGTacgtNn]{3})$/;

          But I have heard that substr is faster.

          --
          Phillip

          Comment


          • #6
            Thank you pmiguel! I tried your suggestion. It worked well! Thank you so much!

            -pradhaun

            Comment


            • #7
              Hi Pradhaun,

              Welcome to the world of regular expressions!
              Although I should caution you about the old perl joke:

              Say you have a problem and think "I will use regular expressions to solve that". Now, you have two problems...

              Also Rick though I should have shortened the line to:

              my ($substring)=$string=~/([ACGTN]{3})$/i;

              --
              Phillip

              Comment


              • #8
                How to estimate the total copy number of genes from FPKM values?

                Hello all,

                I am using Tophat and cufflinks to estimate the copy number of genes in an organism by comparing to its closely related organism genes. I got a bam and gtf file as a outputs from Tophat and Cufflinks . I tried to view the alignment (Tophat output) file as well as the gtf file in IGV. I can see the FPKM value for every single gene but My question is, how can I know whether these two organisms are closely related? Like for eg., "There are x number of same set of genes present in both the organisms" Or is there any way to know the overall FPKM or copy number?

                I am new to this kind of study, am not sure whether my thinking can be applicable or not. So I would appreciate if you can please provide your suggestions...

                Thank you,
                Pradhaun

                Comment


                • #9
                  Originally posted by pmiguel View Post
                  The substr always seems alien to me, whereas simple regexes seem natural.

                  my ($substring) =$string=~ /(...)$/;

                  speaks to me "capture the last 3 characters before the end of the string and assign them to $substring. (Okay the parentheses around $substring, denoting that the characters themselves should be assigned to $substring, not just whether the test succeeded or not -- that is not very intuitive.)

                  But if I want to only capture the last three bases if they are sequence characters, only a minor change is required:

                  my ($substring)=$string=~/([ACGTacgtNn]{3})$/;

                  But I have heard that substr is faster.

                  --
                  Phillip
                  I also think substring will work on really huge strings (like a chromosome length sequence), regex not so much, in my experience.

                  Comment


                  • #10
                    Originally posted by Pradhaun View Post
                    Hello all,

                    I am using Tophat and cufflinks to estimate the copy number of genes in an organism by comparing to its closely related organism genes. I got a bam and gtf file as a outputs from Tophat and Cufflinks . I tried to view the alignment (Tophat output) file as well as the gtf file in IGV. I can see the FPKM value for every single gene but My question is, how can I know whether these two organisms are closely related? Like for eg., "There are x number of same set of genes present in both the organisms" Or is there any way to know the overall FPKM or copy number?

                    I am new to this kind of study, am not sure whether my thinking can be applicable or not. So I would appreciate if you can please provide your suggestions...

                    Thank you,
                    Pradhaun
                    Maybe if you put your question into a new thread instead of an old thread about Perl programming then you will receive some meaningful comments. It would be interesting to see what other people have to say. My feeling is that there is too much variation in normal transcriptome studies to give a feel for relatedness. Not to mention the entirely fuzzy definition of 'related'.

                    Comment

                    Latest Articles

                    Collapse

                    • seqadmin
                      Essential Discoveries and Tools in Epitranscriptomics
                      by seqadmin


                      The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist on Modified Bases...
                      Yesterday, 07:01 AM
                    • seqadmin
                      Current Approaches to Protein Sequencing
                      by seqadmin


                      Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
                      04-04-2024, 04:25 PM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by seqadmin, 04-11-2024, 12:08 PM
                    0 responses
                    39 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 04-10-2024, 10:19 PM
                    0 responses
                    41 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 04-10-2024, 09:21 AM
                    0 responses
                    35 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 04-04-2024, 09:00 AM
                    0 responses
                    55 views
                    0 likes
                    Last Post seqadmin  
                    Working...
                    X