Code Monkey home page Code Monkey logo

Comments (6)

frederic-mahe avatar frederic-mahe commented on August 19, 2024

Hi Ashley, sorry for not answering earlier. I'll look into your data soon, and come up with a more complete answer.

from swarm.

AshleyZhao20 avatar AshleyZhao20 commented on August 19, 2024

from swarm.

frederic-mahe avatar frederic-mahe commented on August 19, 2024

Here is the code that builds the final table:

STATS="amplicons.stats"
SWARMS="amplicons.swarms"
AMPLICON_TABLE="amplicon_contingency_table.csv"
OTU_TABLE="OTU_contingency_table.csv"

# Header
echo -e "OTU\t$(head -n 1 "${AMPLICON_TABLE}")" > "${OTU_TABLE}"

# Compute "per sample abundance" for each OTU
awk -v SWARM="${SWARMS}" \
    -v TABLE="${AMPLICON_TABLE}" \
    'BEGIN {FS = " "
            while ((getline < SWARM) > 0) {
                swarms[$1] = $0
            }
            FS = "\t"
            while ((getline < TABLE) > 0) {
                table[$1] = $0
            }
           }

     {# Parse the stat file (OTUs sorted by decreasing abundance)
      seed = $3
      n = split(swarms[seed], OTU, " ")
      for (i = 1; i < n; i = i + 2) {
          s = split(table[OTU[i]], abundances, "\t")
          for (j = 1; j < s; j++) {
              samples[j] += abundances[j+1]
          }
      }
      printf "%s\t%s", NR, $3
      for (j = 1; j < s; j++) {
          printf "\t%s", samples[j]
      }
     printf "\n"
     delete samples
     }' "${STATS}" >> "${OTU_TABLE}"

I've changed the line seed = $3 "_" $4 for seed = $3 to adapt the code to the your amplicon name format.

However, your dataset seems to be incomplete. For example, amplicon TDA23-3508 forms its own cluster and is marked as representing 6 reads (see amplicons.stats), but a look at amplicon_contingency_table.csv shows that TDA23-3508 has a total of 2 reads, all from sample TDA23. So 4 reads are missing here, and the resulting OTU table will likely be wrong.

Did you perform a global dereplication of your fasta data before clustering?

from swarm.

AshleyZhao20 avatar AshleyZhao20 commented on August 19, 2024

from swarm.

frederic-mahe avatar frederic-mahe commented on August 19, 2024

I do perform a global dereplication using USEARCH before clustering, is that the reason why the OTU table lose some information?

Performing a global dereplication is strongly recommended, so it is good you did it. When dereplicating, did you use the --sizein option to take into account the per-sample abundance values?

There are count differences between your stats, swarms and table files, so something is wrong. However, it is hard for me to say exactly what step of your process went wrong.

from swarm.

AshleyZhao20 avatar AshleyZhao20 commented on August 19, 2024

Sorry for the delay. I added -sizein option and redone the whole process, but unfortunately, there is still some absence data. I'm gonna try several more times and see if I can work this out. Thank you again for your effort.

from swarm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.