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
            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-05-2023, 02:24 PM
          0 responses
          17 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 12-05-2023, 07:37 AM
          0 responses
          26 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 12-04-2023, 08:23 AM
          0 responses
          12 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 12-01-2023, 09:55 AM
          0 responses
          26 views
          0 likes
          Last Post seqadmin  
          Working...
          X