]> git.donarmstrong.com Git - fastq-tools.git/commitdiff
(limited) support for fasta
authorDaniel Jones <dcjones@cs.washington.edu>
Thu, 17 Mar 2011 13:05:30 +0000 (06:05 -0700)
committerDaniel Jones <dcjones@cs.washington.edu>
Thu, 17 Mar 2011 13:05:30 +0000 (06:05 -0700)
src/fastq-grep.c
src/parse.c
src/parse.h

index 67c91901ead7d4a8320605c06ef4d72013966186..3eaffb79c53b89512a4ffe73d295981c7af7566f 100644 (file)
@@ -47,16 +47,6 @@ static int count_flag;
 
 
 
-void print_fastq_entry(FILE* fout, seq_t* seq)
-{
-    fprintf(fout, "@%s\n%s\n+%s\n%s\n",
-                  seq->id1.s,
-                  seq->seq.s,
-                  seq->id2.s,
-                  seq->qual.s );
-}
-
-
 void fastq_grep(FILE* fin, FILE* fout, pcre* re)
 {
     int rc;
@@ -78,7 +68,7 @@ void fastq_grep(FILE* fin, FILE* fout, pcre* re)
 
         if ((invert_flag && rc == PCRE_ERROR_NOMATCH) || rc >= 0) {
             if (count_flag) count++;
-            else            print_fastq_entry(fout, seq);
+            else            fastq_print(fout, seq);
         }
     }
 
index bec5ac346093a21cd39baef72b88e8625186728e..9a7774d381a982972a67e4c806ebb46b7066a7d1 100644 (file)
@@ -176,7 +176,7 @@ int fastq_next(fastq_t* f, seq_t* seq)
 
         /* read id1 */
         else if (f->state == STATE_ID1) {
-            if (*f->c == '@') {
+            if (*f->c == '@' || *f->c == '>') {
                 f->c++;
                 fastq_get_line(f, &seq->id1);
                 if (f->state == STATE_EOF) return 0;
@@ -184,7 +184,9 @@ int fastq_next(fastq_t* f, seq_t* seq)
                 f->state = STATE_SEQ;
             }
             else {
-                fprintf(stderr, "Malformed FASTQ file: expecting an '@', saw a '%c'\n", *f->c);
+                fprintf(stderr,
+                        "Malformed FASTQ file: expecting an '@' or '>', saw a '%c'\n",
+                        *f->c);
                 exit(1);
             }
         }
@@ -207,8 +209,12 @@ int fastq_next(fastq_t* f, seq_t* seq)
                 f->state = STATE_QUAL;
             }
             else {
-                fprintf(stderr, "Malformed FASTQ file: expecting an '+', saw a '%c'\n", *f->c);
-                exit(1);
+                /* fasta style entry */
+                seq->id2.s[0]  = '\0';
+                seq->qual.s[0] = '\0';
+
+                f->state = STATE_ID1;
+                break;
             }
         }
 
@@ -233,3 +239,23 @@ int fastq_next(fastq_t* f, seq_t* seq)
 }
 
 
+void fastq_print(FILE* fout, seq_t* seq)
+{
+    /* FASTQ */
+    if (seq->qual.n > 0) {
+        fprintf(fout, "@%s\n%s\n+%s\n%s\n",
+                      seq->id1.s,
+                      seq->seq.s,
+                      seq->id2.s,
+                      seq->qual.s );
+    }
+
+    /* FASTA */
+    else {
+        fprintf(fout, ">%s\n%s\n",
+                      seq->id1.s,
+                      seq->seq.s );
+    }
+}
+
+
index 56a074ad66f5cf4a1e4c2ea44261a132a6575ae5..64d3726174acc10648f45d9ce45cbba5015a3c64 100644 (file)
@@ -53,5 +53,8 @@ fastq_t* fastq_open(FILE*);
 void fastq_close(fastq_t*);
 int  fastq_next(fastq_t*, seq_t*);
 
+void fastq_print(FILE* fout, seq_t* seq);
+
+
 #endif