Corrected the problems and updated some test data files for sniff.py

This commit is contained in:
Greg Von Kuster
2007-03-12 19:05:03 +00:00
parent e799b40458
commit 80d5d5ef19
4 changed files with 121 additions and 48 deletions
+41 -47
View File
@@ -5,7 +5,6 @@ import logging, sys, os, csv, tempfile, shutil, re
log = logging.getLogger(__name__)
valid_strand = ['+', '-', '.']
valid_frame = [0, 2, '.']
def get_test_fname(fname):
"""Returns test data filename"""
@@ -151,27 +150,32 @@ def is_gff(headers):
>>> is_fasta(headers)
False
>>> fname = get_test_fname('test.gff')
>>> headers = get_headers(fname,sep=' ')
>>> headers = get_headers(fname,sep='\\t')
>>> is_gff(headers)
True
"""
try:
if len(headers) < 2:
return False
"""
Assume the first line in the file is not actual data
(it could be a description), so we'll use the 2nd line
"""
line = headers[1]
if len(line) != 9:
return False
try:
map(int, [line[3], line[4], line[5]])
except:
return False
score = int(line[5])
if (score < 0 or score > 1000) and line[6] not in valid_strand and line[7] not in valid_frame:
if len(headers) < 2:
return False
for idx, hdr in enumerate(headers):
if hdr and len(hdr) > 1 and not hdr[0].startswith('#'):
if len(hdr) != 9:
return False
try:
map(int, [hdr[3], hdr[4]])
except:
return False
if hdr[5] != '.':
try:
score = int(hdr[5])
except:
return False
if (score < 0 or score > 1000):
return False
if hdr[6] not in valid_strand:
return False
if idx > 29:
break
return True
except:
return False
@@ -295,9 +299,6 @@ def is_wiggle(headers):
if hdr and hdr[0] == 'track' and hdr[1].startswith('type=wiggle'):
return True
if idx > 29:
"""
This is a weakness since it assumes < 29 blank lines, comments, etc.
"""
break
return False
except:
@@ -317,23 +318,21 @@ def is_bed(headers, skip=1):
>>> headers = get_headers(fname, sep='\\t')
>>> is_bed(headers)
True
>>> fname = get_test_fname('interval.bed')
>>> headers = get_headers(fname, sep='\\t')
>>> is_bed(headers)
False
True
"""
try:
if not headers:
return False
for hdr in headers[skip:-1]:
"""
We'll try to ensure we are not looking at a comment line
"""
for hdr in headers[skip:]:
if len(hdr) < 3:
return False
if hdr[0].startswith('chr') or hdr[0].startswith('scaffold'):
if len(hdr) < 3:
return False
try:
map(int, [hdr[1], hdr[2]])
except:
@@ -388,11 +387,10 @@ def is_interval(headers, skip=1):
the format is_column_based, but not any of the other formats, then it must be interval.
>>> fname = get_test_fname('test_space.bed')
>>> headers = get_headers(fname, sep=' ')
>>> headers = get_headers(fname, sep='\\t')
>>> is_interval(headers)
False
>>> fname = get_test_fname('interval.bed')
>>> fname = get_test_fname('interval.interval')
>>> headers = get_headers(fname, sep='\\t')
>>> is_interval(headers)
True
@@ -404,13 +402,11 @@ def is_interval(headers, skip=1):
If we got here, we already know the file is_column_based and is not bed,
so we'll just look for some valid data.
"""
for hdr in headers[skip:-1]:
"""
This is a weakness in that it assumes no more than 5 blank lines, comments, etc.
"""
for hdr in headers[skip:]:
if len(hdr) < 3:
return False
if hdr[0].startswith('chr') or hdr[0].startswith('scaffold'):
if len(hdr) < 3:
return False
try:
map(int, [hdr[1], hdr[2]])
except:
@@ -449,35 +445,33 @@ def guess_ext(fname):
Returns an extension that can be used in the datatype factory to
generate a data for the 'fname' file
>>> fname = get_test_fname('interval.bed')
>>> fname = get_test_fname('interval.interval')
>>> guess_ext(fname)
'interval'
>>> fname = get_test_fname('interval.bed')
>>> guess_ext(fname)
'bed'
>>> fname = get_test_fname('test_tab.bed')
>>> guess_ext(fname)
'bed'
>>> fname = get_test_fname('sequence.maf')
>>> guess_ext(fname)
'maf'
>>> fname = get_test_fname('sequence.fasta')
>>> guess_ext(fname)
'fasta'
>>> fname = get_test_fname('file.html')
>>> guess_ext(fname)
'html'
>>> fname = get_test_fname('temp.txt')
>>> file(fname, 'wt').write("a 2\\nc 1")
>>> guess_ext(fname)
'tabular'
>>> fname = get_test_fname('temp.txt')
>>> file(fname, 'wt').write("a 1 2 x\\nb 3 4 y")
>>> guess_ext(fname)
'bed'
>>> fname = get_test_fname('test.gff')
>>> guess_ext(fname)
'gff'
"""
try:
"""
@@ -506,7 +500,7 @@ def guess_ext(fname):
return 'html'
elif is_axt(headers):
return 'axt'
# convert space to tabs
if is_column_based(fname, sep=' '):
sep2tabs(fname)
+74
View File
@@ -0,0 +1,74 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<META http-equiv="Content-Script-Type" content="text/javascript">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<TITLE>
Hyperlinks to Genome Browser </TITLE>
<LINK REL="STYLESHEET" HREF="/style/HGStyle.css">
</HEAD>
<BODY BGCOLOR="#FFF9D2" LINK="0000CC" VLINK="#330066" ALINK="#6600FF">
<A NAME="TOP"></A>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%">
<!-- +++++++++++++++++++++ HOTLINKS BAR +++++++++++++++++++ -->
<TR><TD COLSPAN=3 HEIGHT=40 >
<table bgcolor="#000000" cellpadding="1" cellspacing="1" width="100%%" height="27">
<tr bgcolor="#2636D1"><td valign="middle">
<table BORDER=0 CELLSPACING=0 CELLPADDING=0 bgcolor="#2636D1" height="24"><TR>
<TD VALIGN="middle"><font color="#89A1DE">&nbsp;
&nbsp;<A HREF="/index.html?org=Bushbaby&db=otoGar1&hgsid=1118408" class="topbar">
Home</A> &nbsp;&nbsp;&nbsp;
<A HREF="/cgi-bin/hgGateway?org=Bushbaby&db=otoGar1&hgsid=1118408" class="topbar">
Genomes</A> &nbsp;&nbsp;&nbsp;
<A HREF="/cgi-bin/hgTracks?org=Bushbaby&db=otoGar1&hgsid=1118408" class="topbar">
Genome Browser</A> &nbsp;&nbsp;&nbsp;
<A HREF="/cgi-bin/hgBlat?command=start&org=Bushbaby&db=otoGar1&hgsid=1118408" class="topbar"> Blat</A> &nbsp;&nbsp;&nbsp;
<A HREF="/cgi-bin/hgTables?org=Bushbaby&db=otoGar1&hgsid=1118408&hgta_doMainPage=1" class="topbar">
Tables</A> &nbsp;&nbsp;&nbsp;
<A HREF="/cgi-bin/hgNear?org=Bushbaby&db=otoGar1&hgsid=1118408" class="topbar">
Gene Sorter</A> &nbsp;&nbsp;&nbsp;
<A HREF="/cgi-bin/hgSession?org=Bushbaby&db=otoGar1&hgsid=1118408&hgS_doMainPage=1" class="topbar">Session</A>&nbsp;&nbsp;&nbsp;
<A HREF="/FAQ/" class="topbar">
FAQ</A> &nbsp;&nbsp;&nbsp;
<A HREF="/goldenPath/help/hgTablesHelp.html"
class="topbar">
Help</A>
&nbsp;</font></TD>
</TR></TABLE>
</TD></TR></TABLE>
</TD></TR>
<!-- +++++++++++++++++++++ CONTENT TABLES +++++++++++++++++++ -->
<TR><TD COLSPAN=3>
<!--outer table is for border purposes-->
<TABLE WIDTH="100%" BGCOLOR="#888888" BORDER="0" CELLSPACING="0" CELLPADDING="1"><TR><TD>
<TABLE BGCOLOR="#FFFEE8" WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0"><TR><TD>
<TABLE BGCOLOR="#D9E4F8" BACKGROUND="/images/hr.gif" WIDTH="100%"><TR><TD>
<FONT SIZE="4"><b>&nbsp;
Hyperlinks to Genome Browser</b></FONT></TD></TR></TABLE>
<TABLE BGCOLOR="#FFFEE8" WIDTH="100%" CELLPADDING=0><TR><TH HEIGHT=10></TH></TR>
<TR><TD WIDTH=10>&nbsp;</TD><TD>
<A HREF="http://hgwdev.cse.ucsc.edu/cgi-bin/hgTracks?db=otoGar1&position=scaffold_0.1-193456:96554-98437&gold=pack" TARGET=_blank>scaffold_0.1-193456_25 at scaffold_0.1-193456:96554-98437</A><BR>
<A HREF="http://hgwdev.cse.ucsc.edu/cgi-bin/hgTracks?db=otoGar1&position=scaffold_0.1-193456:100227-101729&gold=pack" TARGET=_blank>scaffold_0.1-193456_26 at scaffold_0.1-193456:100227-101729</A><BR>
<A HREF="http://hgwdev.cse.ucsc.edu/cgi-bin/hgTracks?db=otoGar1&position=scaffold_0.1-193456:101830-103994&gold=pack" TARGET=_blank>scaffold_0.1-193456_27 at scaffold_0.1-193456:101830-103994</A><BR>
<A HREF="http://hgwdev.cse.ucsc.edu/cgi-bin/hgTracks?db=otoGar1&position=scaffold_0.1-193456:105267-107614&gold=pack" TARGET=_blank>scaffold_0.1-193456_28 at scaffold_0.1-193456:105267-107614</A><BR>
</TD><TD WIDTH=15></TD></TR></TABLE>
<br></TD></TR></TABLE>
</TD></TR></TABLE>
</TD></TR></TABLE>
</BODY></HTML>
@@ -0,0 +1,5 @@
chr1 4348187 4348589 3.70 4.90 2.55 0.24 0.46
chr1 4488177 4488442 4.03 5.77 1.92 -0.67 0.81
chr1 4774091 4774440 8.07 8.33 7.82 0.85 -0.40
chr1 4800122 4800409 6.40 7.35 5.44 1.19 -0.42
chr1 4878925 4879277 2.18 0.28 4.93 -0.96 1.24
+1 -1
View File
@@ -1,3 +1,3 @@
track name="tb_knownGene" description="table browser query on knownGene" visibility=3 url=
track type=wiggle_0 name="tb_knownGene" description="table browser query on knownGene" visibility=3 url=
chr7 127475281 127491632 NM_000230 0 + 127486022 127488767 0 3 29,172,3225, 0,10713,13126,
chr7 127486011 127488900 D49487 0 + 127486022 127488767 0 2 155,490, 0,2399,