Header Leaderboard Ad

Collapse

Create perl program

Collapse

Announcement

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

  • Create perl program

    Hi,

    I have two sequence file.I want only the mathching sequences which is present on both files and save that output in third file...Can you please help me for creating perl program for this.??

    FILE1:

    >Contig1
    TTCAAAAACTCATATGGGTGGTACAATGCGTCTTGGATCTAGGAGAACATATTTTCAAGTTGCAGATTGTAAATCTGCAAAATTATATGGTAACCAGAGCTTTGTAGATGAGAGGCATCGACACAGATATGAGGTGAACCCCGACATGGTGCAGC

    >Contig2
    GACTTGAAGATGCTGGTCTTTCTTTCACTGGCAAAGATGAAAGTGGTCATCGCATGGAGATTGTTGAGCTGCCGAGTCATCCTTACTTCATCGGAGTTCAATTTCATCCAGAATTTAAATCAAGGCCAGGAACCCCTTCAGCCCTGTTT

    >Contig3
    CTAGGACTTATAGCCGCAGCAACTGGGCAACTTGAAACTCTCTTGAAGAAGGGTGTTCCCAAAACATGGGGGTTGAGCAATGGTACGTCAGGACTAAAATCACATCGATATGTAAATGGGACAAAACTGTTTAATGGATCATTAGATG

    >Contig4
    GCATTTATTGCAATGGGAATGGTATACATGTTTAAAGGAAACAGTAACATATGTTGTGGGCGCTTGGCCCCGGATTTTTGATAATCAAATTTTGCTACTGCATTTTTTTTAAAG

    >Contig5
    CCCCCCCTTATTTGTCGTTTTTGATAATCAAATTTTGCTACTGCATTTTTTTTAAAG

    FILE2:

    >Contig1
    TTCAAAAACTCATATGGGTGGTACAATGCGTCTTGGATCTAGGAGAACATATTTTCAAGTTGCAGATTGTAAATCTGCAAAATTATATGGTAACCAGAGCTTTGTAGATGAGAGGCATCGACACAGATATGAGGTGAACCCCGACATGGTGCAGC

    >Contig3

    CTAGGACTTATAGCCGCAGCAACTGGGCAACTTGAAACTCTCTTGAAGAAGGGTGTTCCCAAAACATGGGGGTTGAGCAATGGTACGTCAGGACTAAAATCACATCGATATGTAAATGGGACAAAACTGTTTAATGGATCATTAGATG

    >Contig4
    GCATTTATTGCAATGGGAATGGTATACATGTTTAAAGGAAACAGTAACATATGTTGTGGGCGCTTGGCCCCGGATTTTTGATAATCAAATTTTGCTACTGCATTTTTTTTAAAG

    >Contig6
    GCATTTATTGCAATGTTTTGATAATCAAATTTTGCTACTGCATTTTTTTTAAAGCCAGAGCTTTGTAGATGAGAGGCATGGTACAATGCGTCTTG

    EXPECTED OUTPUT:

    >Contig1
    TTCAAAAACTCATATGGGTGGTACAATGCGTCTTGGATCTAGGAGAACATATTTTCAAGTTGCAGATTGTAAATCTGCAAAATTATATGGTAACCAGAGCTTTGTAGATGAGAGGCATCGACACAGATATGAGGTGAACCCCGACATGGTGCAGC

    >Contig3
    CTAGGACTTATAGCCGCAGCAACTGGGCAACTTGAAACTCTCTTGAAGAAGGGTGTTCCCAAAACATGGGGGTTGAGCAATGGTACGTCAGGACTAAAATCACATCGATATGTAAATGGGACAAAACTGTTTAATGGATCATTAGATG

    >Contig4
    GCATTTATTGCAATGGGAATGGTATACATGTTTAAAGGAAACAGTAACATATGTTGTGGGCGCTTGGCCCCGGATTTTTGATAATCAAATTTTGCTACTGCATTTTTTTTAAAG

  • #2
    cross-posted : https://www.biostars.org/p/160027/

    Comment


    • #3
      @vineetha: Are you looking to actually match the sequences or you just want to find matching headers? If a header matches then is the sequence always identical in both files?

      Comment


      • #4
        @vineetha: Can awk be used to do this? A one-liner like below will work.

        Code:
        awk 'NR==FNR{a[$0];next}$0 in a{print $0}' file1.txt file2.txt
        >Contig1
        TTCAAAAACTCATATGGGTGGTACAATGCGTCTTGGATCTAGGAGAACATATTTTCAAGTTGCAGATTGTAAATCTGCAAAATTATATGGTAACCAGAGCTTTGTAGATGAGAGGCATCGACACAGATATGAGGTGAACCCCGACATGGTGCAGC
        
        >Contig3
        CTAGGACTTATAGCCGCAGCAACTGGGCAACTTGAAACTCTCTTGAAGAAGGGTGTTCCCAAAACATGGGGGTTGAGCAATGGTACGTCAGGACTAAAATCACATCGATATGTAAATGGGACAAAACTGTTTAATGGATCATTAGATG
        
        >Contig4
        GCATTTATTGCAATGGGAATGGTATACATGTTTAAAGGAAACAGTAACATATGTTGTGGGCGCTTGGCCCCGGATTTTTGATAATCAAATTTTGCTACTGCATTTTTTTTAAAG
        The perl equivalent would be something like:

        Code:
        perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/'  file1.txt file2.txt
        >Contig1
        TTCAAAAACTCATATGGGTGGTACAATGCGTCTTGGATCTAGGAGAACATATTTTCAAGTTGCAGATTGTAAATCTGCAAAATTATATGGTAACCAGAGCTTTGTAGATGAGAGGCATCGACACAGATATGAGGTGAACCCCGACATGGTGCAGC
        
        >Contig3
        CTAGGACTTATAGCCGCAGCAACTGGGCAACTTGAAACTCTCTTGAAGAAGGGTGTTCCCAAAACATGGGGGTTGAGCAATGGTACGTCAGGACTAAAATCACATCGATATGTAAATGGGACAAAACTGTTTAATGGATCATTAGATG
        >Contig4
        GCATTTATTGCAATGGGAATGGTATACATGTTTAAAGGAAACAGTAACATATGTTGTGGGCGCTTGGCCCCGGATTTTTGATAATCAAATTTTGCTACTGCATTTTTTTTAAAG
        Last edited by cmccabe; 10-01-2015, 12:59 PM. Reason: added perl

        Comment

        Working...
        X