Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Pradhaun
    Member
    • Nov 2011
    • 16

    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.
  • kmcarr
    Senior Member
    • May 2008
    • 1181

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

    Comment

    • heiya
      Member
      • Nov 2011
      • 14

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

      Comment

      • Pradhaun
        Member
        • Nov 2011
        • 16

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

        Comment

        • pmiguel
          Senior Member
          • Aug 2008
          • 2328

          #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

          • Pradhaun
            Member
            • Nov 2011
            • 16

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

            -pradhaun

            Comment

            • pmiguel
              Senior Member
              • Aug 2008
              • 2328

              #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

              • Pradhaun
                Member
                • Nov 2011
                • 16

                #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

                • swbarnes2
                  Senior Member
                  • May 2008
                  • 910

                  #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

                  • westerman
                    Rick Westerman
                    • Jun 2008
                    • 1104

                    #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

                    • SEQadmin2
                      Proteomic Platforms: How to Choose the Right Analytical Strategy to Improve Detection and Clinical Applications
                      by SEQadmin2


                      Proteomics platforms are evolving rapidly, with advances in mass spectrometry and affinity-based approaches expanding what researchers can detect and at what scale. As the field moves toward deeper proteome coverage and clinical applications, scientists face an increasingly complex landscape of tools. This article will explore how researchers are navigating these choices to find the right platform for their work.

                      The systematic characterization of the human proteome has
                      ...
                      07-20-2026, 11:48 AM
                    • SEQadmin2
                      Advanced Sequencing Platforms Tackle Neuroscience’s Toughest Genomics Problems
                      by SEQadmin2



                      Genomics studies in neuroscience face a special challenge due to the brain’s complexity and scarcity of samples. Mapping changes in cell type and state using conventional next-generation sequencing methods remains challenging. Advances in technologies like single-cell sequencing, spatial transcriptomics, and long-read sequencing have opened the door to deeper studies of the brain and diseases like Alzheimer’s, amyotrophic lateral sclerosis (ALS), and schizophrenia.
                      ...
                      07-09-2026, 11:10 AM
                    • SEQadmin2
                      Cancer Drug Resistance: The Lingering Barrier to Rising Survival
                      by SEQadmin2



                      Cancer survival rates have significantly increased in the last few decades in the United States, reaching a combined 70% 5-year survival rate by 2021. Behind this number, there are years of research to find new therapies, drug targets, and early detection methods. But there is one core challenge that keeps slowing down these advances, and it’s about drug resistance.

                      There is no single reason why many patients don’t respond to treatment as expected. Cancer is...
                      07-08-2026, 05:17 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by SEQadmin2, 07-24-2026, 12:17 PM
                    0 responses
                    29 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-23-2026, 11:41 AM
                    0 responses
                    21 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-20-2026, 11:10 AM
                    0 responses
                    211 views
                    0 reactions
                    Last Post SEQadmin2  
                    Started by SEQadmin2, 07-13-2026, 10:26 AM
                    0 responses
                    78 views
                    0 reactions
                    Last Post SEQadmin2  
                    Working...