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
                      Genetic Variation in Immunogenetics and Antibody Diversity
                      by seqadmin



                      The field of immunogenetics explores how genetic variations influence immune responses and susceptibility to disease. In a recent SEQanswers webinar, Oscar Rodriguez, Ph.D., Postdoctoral Researcher at the University of Louisville, and Ruben Martínez Barricarte, Ph.D., Assistant Professor of Medicine at Vanderbilt University, shared recent advancements in immunogenetics. This article discusses their research on genetic variation in antibody loci, antibody production processes,...
                      11-06-2024, 07:24 PM
                    • seqadmin
                      Choosing Between NGS and qPCR
                      by seqadmin



                      Next-generation sequencing (NGS) and quantitative polymerase chain reaction (qPCR) are essential techniques for investigating the genome, transcriptome, and epigenome. In many cases, choosing the appropriate technique is straightforward, but in others, it can be more challenging to determine the most effective option. A simple distinction is that smaller, more focused projects are typically better suited for qPCR, while larger, more complex datasets benefit from NGS. However,...
                      10-18-2024, 07:11 AM

                    ad_right_rmr

                    Collapse

                    News

                    Collapse

                    Topics Statistics Last Post
                    Started by seqadmin, 11-08-2024, 11:09 AM
                    0 responses
                    227 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 11-08-2024, 06:13 AM
                    0 responses
                    166 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 11-01-2024, 06:09 AM
                    0 responses
                    80 views
                    0 likes
                    Last Post seqadmin  
                    Started by seqadmin, 10-30-2024, 05:31 AM
                    0 responses
                    27 views
                    0 likes
                    Last Post seqadmin  
                    Working...
                    X