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
            Latest Developments in Precision Medicine
            by seqadmin



            Technological advances have led to drastic improvements in the field of precision medicine, enabling more personalized approaches to treatment. This article explores four leading groups that are overcoming many of the challenges of genomic profiling and precision medicine through their innovative platforms and technologies.

            Somatic Genomics
            “We have such a tremendous amount of genetic diversity that exists within each of us, and not just between us as individuals,”...
            05-24-2024, 01:16 PM
          • 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

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, Yesterday, 06:55 AM
          0 responses
          12 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-30-2024, 03:16 PM
          0 responses
          24 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-29-2024, 01:32 PM
          0 responses
          29 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 05-24-2024, 07:15 AM
          0 responses
          215 views
          0 likes
          Last Post seqadmin  
          Working...
          X