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
            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 on Modified Bases...
            Today, 07:01 AM
          • seqadmin
            Current Approaches to Protein Sequencing
            by seqadmin


            Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
            04-04-2024, 04:25 PM

          ad_right_rmr

          Collapse

          News

          Collapse

          Topics Statistics Last Post
          Started by seqadmin, 04-11-2024, 12:08 PM
          0 responses
          37 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 04-10-2024, 10:19 PM
          0 responses
          41 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 04-10-2024, 09:21 AM
          0 responses
          35 views
          0 likes
          Last Post seqadmin  
          Started by seqadmin, 04-04-2024, 09:00 AM
          0 responses
          54 views
          0 likes
          Last Post seqadmin  
          Working...
          X