Seqanswers Leaderboard Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • musta1234
    replied
    Works GREAT!!!

    Hey Genomax and all!!

    The code works great... handles a file with 160 columns and 128,000 lines very well.

    Thanks

    Originally posted by GenoMax View Post
    This is a bash shell script based on a solution in the stackoverflow thread I had posted above.




    Save the code in a file (script.sh in example below) and then run as follows:

    Code:
    $ sh script.sh your_data file
    Code:
    #!/bin/bash 
    declare -a array=( )                      # we build a 1-D-array
    
    read -a line < "$1"                       # read the headline
    
    COLS=${#line[@]}                          # save number of columns
    
    index=0
    while read -a line; do
        for (( COUNTER=0; COUNTER<${#line[@]}; COUNTER++ )); do
            array[$index]=${line[$COUNTER]}
            ((index++))
        done
    done < "$1"
    
    for (( ROW = 0; ROW < COLS; ROW++ )); do
            printf ">"
      for (( COUNTER = ROW; COUNTER < ${#array[@]}; COUNTER += COLS )); do
        printf "%s" ${array[$COUNTER]}
        if [ $COUNTER == $ROW ]
        then
            printf "\n"
        fi
      done
      printf "\n" 
    done

    Leave a comment:


  • musta1234
    replied
    Thanks

    I will definitely give it a try...

    Leave a comment:


  • GenoMax
    replied
    This is a bash shell script based on a solution in the stackoverflow thread I had posted above.

    Save the code in a file (script.sh in example below) and then run as follows:

    Code:
    $ sh script.sh your_data file
    Code:
    #!/bin/bash 
    declare -a array=( )                      # we build a 1-D-array
    
    read -a line < "$1"                       # read the headline
    
    COLS=${#line[@]}                          # save number of columns
    
    index=0
    while read -a line; do
        for (( COUNTER=0; COUNTER<${#line[@]}; COUNTER++ )); do
            array[$index]=${line[$COUNTER]}
            ((index++))
        done
    done < "$1"
    
    for (( ROW = 0; ROW < COLS; ROW++ )); do
            printf ">"
      for (( COUNTER = ROW; COUNTER < ${#array[@]}; COUNTER += COLS )); do
        printf "%s" ${array[$COUNTER]}
        if [ $COUNTER == $ROW ]
        then
            printf "\n"
        fi
      done
      printf "\n" 
    done

    Leave a comment:


  • musta1234
    replied
    Thats right

    Sorry for the sloppy explanation, but all the nucleotides are from a tab delimited file and Genomax stated the way I want it perfectly.


    >SNP_001
    TCCCAATTCGGC
    >SNP_002
    TCCCAATTCGGC
    >SNP_003
    TCCCAATTCGGC

    ......

    SNP_XXX
    ATGCATGCATGC

    Thanks

    Leave a comment:


  • GenoMax
    replied
    I think @musta1234 wants the matrix transposed and then converted to a multi-fasta file.

    >SNP_001
    TCCCAATTCGGC
    >SNP_002
    TCCCAATTCGGC
    >SNP_003
    TCCCAATTCGGC

    Leave a comment:


  • blakeoft
    replied
    Is your input the following:

    T T T T
    C C C C
    C C C C
    C C C C
    A A A A
    A A A A
    T T T T
    T T T T
    C C C C
    G G G G
    G G G G
    C C C C

    and do you want to get

    TCCCAATTCGGC
    TCCCAATTCGGC
    TCCCAATTCGGC
    TCCCAATTCGGC

    back as a result?
    Last edited by blakeoft; 03-31-2014, 05:00 AM. Reason: nitpicky spacing

    Leave a comment:


  • GenoMax
    replied
    See if this thread helps: http://stackoverflow.com/questions/1...a-file-in-bash

    Leave a comment:


  • musta1234
    started a topic Help with While []... done in bash

    Help with While []... done in bash

    Hello all!! I need help converting tab to fasta... I am a newbie and know only a little bash scripting. I need to convert a tab delimited SNP file into either a single fasta file or a multiple fasta files for each column using the first line as identifier.

    The closest I got was a script that generates the required .fasta files but enters a loop and can only be stopped by ctrl-C.


    #!/bin/bash


    echo ">" > carat.txt

    counter=1
    #My tab file has 64 columns

    while : [ $counter -lt 64]
    do

    less <SNP.txt |awk "{print$"$counter"}"| cat carat.txt - >$counter.fa
    counter=$(($counter +1))

    done

    exit



    SNP_001 SNP_002 SNP_003....
    T T T T
    C C C C
    C C C C
    C C C C
    A A A A
    A A A A
    T T T T
    T T T T
    C C C C
    G G G G
    G G G G
    C C C C

Latest Articles

Collapse

  • seqadmin
    Pathogen Surveillance with Advanced Genomic Tools
    by seqadmin




    The COVID-19 pandemic highlighted the need for proactive pathogen surveillance systems. As ongoing threats like avian influenza and newly emerging infections continue to pose risks, researchers are working to improve how quickly and accurately pathogens can be identified and tracked. In a recent SEQanswers webinar, two experts discussed how next-generation sequencing (NGS) and machine learning are shaping efforts to monitor viral variation and trace the origins of infectious...
    03-24-2025, 11:48 AM
  • seqadmin
    New Genomics Tools and Methods Shared at AGBT 2025
    by seqadmin


    This year’s Advances in Genome Biology and Technology (AGBT) General Meeting commemorated the 25th anniversary of the event at its original venue on Marco Island, Florida. While this year’s event didn’t include high-profile musical performances, the industry announcements and cutting-edge research still drew the attention of leading scientists.

    The Headliner
    The biggest announcement was Roche stepping back into the sequencing platform market. In the years since...
    03-03-2025, 01:39 PM

ad_right_rmr

Collapse

News

Collapse

Topics Statistics Last Post
Started by seqadmin, 03-20-2025, 05:03 AM
0 responses
42 views
0 reactions
Last Post seqadmin  
Started by seqadmin, 03-19-2025, 07:27 AM
0 responses
52 views
0 reactions
Last Post seqadmin  
Started by seqadmin, 03-18-2025, 12:50 PM
0 responses
38 views
0 reactions
Last Post seqadmin  
Started by seqadmin, 03-03-2025, 01:15 PM
0 responses
194 views
0 reactions
Last Post seqadmin  
Working...