Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • concatenation by perl

    Hi everyone,
    I have some files like this:
    E.coli ---MGKALVIVESPAKAKTINKYLGSD-----------YVVKSSVGHIRDLPTSGSAAKK
    A.aeolicus -----MELFIVESPTKAKTIQKFLGKG-----------FLVKATLGHVKDLPEK------
    B.subtillis ---MSDYLVIVESPAKAKTIERYLGKK-----------YKVKASMGHVRDLPKS------
    helicobacter ----MKHLIIVESPAKAKTIKNFLDKN-----------YEVIASKGHVRDLSKFALG---
    Thermotoga MSKKVKKYIVVESPAKAKTIKSILGNE-----------YEVFASMGHIIDLPKS------
    mycoplasma ---MSKNLVVIESPNKVKTLQKYLPND-----------FEIVSTIGHIREMVHKNFG---
    B.fragil -----MIALIAEKPSVAKDIARIIGATGRNDGYLSGNGYMVTWAFGHLIQLAMPEAYG--
    .: *.* .* : : : : : **: ::

    E.coli SADSTSTKTAKKPKKDERGALVNRMGVDPWHNWEAHYEVLPGKEKVVSELKQLAEKADHI
    A.aeolicus -----------------------ELGVD-LRTLKAKYVYKRGKKKLVEQLKKLSRRSSIV
    B.subtillis -----------------------QMGVDIEQNFEPKYITIRGKGPVLKELKTAAKKAKKV
    helicobacter -------------------------IKIDETGFTPNYVVDKDHKELVKQIIELSKKASIT
    Thermotoga -----------------------KFGVDLEKDFEPEFAVIKGKEKVVEKLKDLAKKG-EL
    mycoplasma ------FNEADYSPVWEDWTKSKKKFSSLSFKGNLKGKKLLSKYDIIKSIKEKASKATNI
    B.fragil --------VANFRRESLPILPPDFQLIPRQVKAEKGYKADPGVLKQLKVIKEVFDQCDRI

    and I want to concatenate each lines for certain species within file and then concatenate of the result of each file with another file and get output.I know that there are some easier way to do that but I like to know how can do that with perl script?
    Thanks for your help

  • #2
    Can you give an example of the intended output?

    I'm thinking you would like this:
    File 1:
    E.coli ---MGKALVIVESPAKAKTINKYLGSD-----------YVVKSSVGHIRDLPTSGSAAKK
    E.coli ---ALISLILIASLILILAISLA

    File 2:
    E.coli SADSTSTKTAKKPKKDERGALVNRMGVDPWHNWEAHYEVLPGKEKVVSELKQLAEKADHI

    Output:
    E.coli ---MGKALVIVESPAKAKTINKYLGSD-----------YVVKSSVGHIRDLPTSGSAAKK---ALISLILIASLILILAISLASADSTSTKTAKKPKKDERGALVNRMGVDPWHNWEAHYEVLPGKEKVVSELKQLAEKADHI

    Is that correct?

    EDIT
    Ignore the whitespace in the sequences.
    Last edited by Thomas Doktor; 02-24-2011, 04:10 AM. Reason: Whitespace appearing in final post but not in edit mode

    Comment


    • #3
      Hi Thomas,
      yes you are almost right.but this is tht I show just 1 file. And I want to do the same thing for other file and finally concatenate for each species and genereate just one final uotput.
      for eample for E.coli we have:
      AAAAAAAAAAAA

      and again within this file for E.coli
      BBBBB----BBB
      for this file so we will have
      AAAAAAAAAAAABBBBBBBB
      and this for other species and so on.
      Thanks

      Comment


      • #4
        well i won't write the script for you, but it is quite easy. ;-)

        get the files you want ( @files = <*.txt>)

        go over all these files (foreach (@files)){ while <$_> { chomp;....
        user pattern matching $_ ~= /((w+)|(w+\.w+))\s+(*.)/
        remove the --- in $2
        ...
        store it in a hash sequences($1) = "sequences($1)"."$2"

        and in the end print the hash like you want it in the output file.

        something like that, of course there will be some problems, but try it on your own first, then show what you got.

        Comment


        • #5
          in a file prog_name.pl:

          #!/usr/bin/perl

          $in=$ARGV[0]; #input file name
          $out=$ARGV[1];

          open(FH, "< $in") || die "here1";
          open(OUT, "> $out") || die "here2";

          while(<FH>){
          if($_=~/E. coli/){
          $hash{"e_coli"}.=$_;
          }elsif($_=~/A. aeolicus/){
          $hash{"a_aeol"}.=$_;
          }elsif( keep listing it out for as many lines){

          }

          }
          foreach $key (keys %hash){
          print OUT $hash{$key}, "\n";
          }
          close FH;
          close OUT;

          Comment

          Latest Articles

          Collapse

          • seqadmin
            Recent Advances in Sequencing Analysis Tools
            by seqadmin


            The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
            05-06-2024, 07:48 AM
          • 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...
            04-22-2024, 07:01 AM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, Yesterday, 06:35 AM
          0 responses
          14 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-09-2024, 02:46 PM
          0 responses
          18 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-07-2024, 06:57 AM
          0 responses
          17 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-06-2024, 07:17 AM
          0 responses
          19 views
          0 likes
          Last Post seqadmin  
          Working...
          X