formats.py 2.18 KB
Newer Older
Jerome Mariette's avatar
Jerome Mariette committed
1
#
Jerome Mariette's avatar
Jerome Mariette committed
2
# Copyright (C) 2015 INRA
Jerome Mariette's avatar
Jerome Mariette committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

18
import jflow
Jerome Mariette's avatar
Jerome Mariette committed
19
from jflow import seqio
cnoirot's avatar
cnoirot committed
20
from jflow.featureiolib.gff3 import GFF3IO
21
from jflow.exceptions import InvalidFormatError
Jerome Mariette's avatar
Jerome Mariette committed
22
23
24
25
import os
import sys


26
27
def any(ifile): pass
def bam(ifile): pass
Jerome Mariette's avatar
Jerome Mariette committed
28
29
30
31
32
33
34
35
36

def fastq(ifile):
    try:
        reader = seqio.FastqReader(ifile)
        nb_seq = 0
        for id, desc, seq, qualities in reader:
            nb_seq += 1
            # only check the first 10 sequences
            if nb_seq == 10: break
37
    except:
38
        raise InvalidFormatError("The provided file '" + ifile + "' is not a fastq file!")
Jerome Mariette's avatar
Jerome Mariette committed
39
40
41
    
def fasta(ifile):
    try:
42
        reader = seqio.FastaReader(ifile)
Jerome Mariette's avatar
Jerome Mariette committed
43
44
45
        nb_seq = 0
        for id, desc, seq, qualities in reader:
            nb_seq += 1
46
47
             # only check the first 3 sequences
            if nb_seq == 3: break
48
    except:
49
        raise InvalidFormatError("The provided file '" + ifile + "' is not a fasta file!")
Jerome Mariette's avatar
Jerome Mariette committed
50
51
52
53
54
55
56
57
58
    
def sff(ifile):
    try:
        reader = seqio.SFFReader(ifile)
        nb_seq = 0
        for id, desc, seq, qualities in reader:
            nb_seq += 1
            # only check the first 10 sequences
            if nb_seq == 10: break
59
    except:
60
        raise InvalidFormatError("The provided file '" + ifile + "' is not a sff file!")
cnoirot's avatar
cnoirot committed
61
62
63
64
65
66
67
68
69
70
71

def gff3(ifile):
    #try:
        reader = GFF3IO(ifile,"r")
        nb_line = 0
        for record in reader:
            nb_line += 1
            # only check the first 10 sequences
            if nb_line == 10: break
    #except:
    #    raise InvalidFormatError("The provided file '" + ifile + "' is not a gff3 file!")