Unconfigured Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • semna
    Member
    • Apr 2010
    • 55

    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
  • Thomas Doktor
    Senior Member
    • Apr 2009
    • 105

    #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

    • semna
      Member
      • Apr 2010
      • 55

      #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

      • Thorondor
        Member
        • Feb 2011
        • 69

        #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

        • JohnK
          Senior Member
          • Feb 2010
          • 106

          #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

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by SEQadmin2, 06-09-2026, 11:58 AM
          0 responses
          24 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 06-05-2026, 10:09 AM
          0 responses
          29 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 06-04-2026, 08:59 AM
          0 responses
          39 views
          0 reactions
          Last Post SEQadmin2  
          Started by SEQadmin2, 06-02-2026, 12:03 PM
          0 responses
          62 views
          0 reactions
          Last Post SEQadmin2  
          Working...