@@ -1752,23 +1752,41 @@ def check_presence_of_genes(database):
17521752def detect_file_format (file ):
17531753 detected_format = "none"
17541754
1755+ #I don't know how this could happen, but good to have it in place?
1756+ toomuch = 0
1757+
17551758 #If the user supplies a mismatch file, then this will run. Otw, we should only run the requested check to avoid excess effort.
17561759 isfasta = detect_fasta (file )
17571760 isbam = detect_bam (file )
17581761 issam = detect_sam (file )
17591762 isblast = detect_blast (file )
17601763 isdb = detect_is_db (file )
1764+ isassoc = detect_is_assoc (file )
1765+ isprodigalgff = detect_is_prodigal (file )
17611766
17621767 if isfasta :
17631768 detected_format = "fasta"
1769+ toomuch += 1
17641770 if isbam :
17651771 detected_format = "bam"
1772+ toomuch += 1
17661773 if issam :
17671774 detected_format = "sam"
1775+ toomuch += 1
17681776 if isblast :
17691777 detected_format = "blast"
1778+ toomuch += 1
17701779 if (isdb ):
17711780 detected_format = "database"
1781+ toomuch += 1
1782+ if (isassoc ):
1783+ detected_format = "assoc"
1784+ toomuch += 1
1785+ if (isprodigalgff ):
1786+ detected_format = "genes"
1787+ toomuch += 1
1788+ if toomuch > 1 :
1789+ detected_format = "none"
17721790
17731791 return (detected_format )
17741792
@@ -1863,4 +1881,61 @@ def detect_is_db(dbname):
18631881 conn .close ()
18641882 except :
18651883 isdb = False
1866- return isdb
1884+ return isdb
1885+
1886+ #todo write these, include in fmt checker
1887+ def detect_is_assoc (file ):
1888+ fh = open (file , "r" )
1889+
1890+ fmt_fine = True
1891+
1892+ #Check first line
1893+ try :
1894+ line = fh .readline ()
1895+ except :
1896+ fmt_fine = False
1897+ else :
1898+ segment = line .strip ().split ()
1899+ if len (segment ) != 2 :
1900+ fmt_fine = False
1901+
1902+ #Check the next 29 lines, or all until EOF.
1903+ for i in range (1 , 30 ):
1904+ try :
1905+ line = fh .readline ()
1906+ except :
1907+ fmt_fine = False
1908+ break
1909+ else :
1910+ segment = line .strip ().split ()
1911+ if len (segment ) == 2 :
1912+ pass
1913+ #Basically an EOF check.
1914+ if len (line ) == 0 :
1915+ break
1916+ else :
1917+ fmt_fine = False
1918+ break
1919+
1920+ fh .close ()
1921+
1922+ return (fmt_fine )
1923+
1924+ def detect_is_prodigal (file ):
1925+ fh = open (file , "r" )
1926+
1927+ fmt_fine = True
1928+
1929+ try :
1930+ line
1931+ except :
1932+ fmt_fine = False
1933+ else :
1934+ if line .startswith ("##gff-version" ):
1935+ pass
1936+ else :
1937+ fmt_fine = False
1938+
1939+ fh .close ()
1940+
1941+ return (fmt_fine )
0 commit comments