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
                      Advanced Methods for the Detection of Infectious Disease
                      by seqadmin




                      The recent pandemic caused worldwide health, economic, and social disruptions with its reverberations still felt today. A key takeaway from this event is the need for accurate and accessible tools for detecting and tracking infectious diseases. Timely identification is essential for early intervention, managing outbreaks, and preventing their spread. This article reviews several valuable tools employed in the detection and surveillance of infectious diseases.
                      ...
                      11-27-2023, 01:15 PM
                    • seqadmin
                      Strategies for Investigating the Microbiome
                      by seqadmin




                      Microbiome research has led to the discovery of important connections to human and environmental health. Sequencing has become a core investigational tool in microbiome research, a subject that we covered during a recent webinar. Our expert speakers shared a number of advancements including improved experimental workflows, research involving transmission dynamics, and invaluable analysis resources. This article recaps their informative presentations, offering insights...
                      11-09-2023, 07:02 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by seqadmin, 12-01-2023, 09:55 AM
                    0 responses
                    19 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 11-30-2023, 10:48 AM
                    0 responses
                    20 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 11-29-2023, 08:26 AM
                    0 responses
                    14 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 11-29-2023, 08:12 AM
                    0 responses
                    17 views
                    0 likes
                    Last Post seqadmin  
                    Working...
                    X