def test_load_existing(): """Load existing index""" i = Index('test/data/index.txt') assert i is not None i.set_format('test/data/format.json') i.open() assert len(i) == 36
def test_open_string(): """Test open with string parameter""" i = Index() assert i is not None i.set_format('test/data/format.json') i.open('test/data/index.txt') assert len(i) == 36
def test_lookup_full_index(): """Test export""" i = Index('test/data/index.txt') assert i is not None i.set_format('test/data/format.json') i.open() result = i.lookup(type='gtf') assert result.export()[0][0] != '.'
def test_lookup_more_types_index_id(): """Test export""" i = Index('test/data/index_gfs.txt') assert i is not None i.set_format('test/data/format.json') i.open() result = i.lookup(id='WWP.1') assert result.export()[0][0] != '.'
def test_export_ol_no_map_tab_path(): """Test export""" i = Index('test/data/index_oneline.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export(map=None, export_type='tab', tags=['path']) assert exp[0] == 'aWL3.2/aWL3.2_4204_ACTGAT_transcript.gtf'
def test_open_file(): """Test open with file parameter""" i = Index() assert i is not None i.set_format('test/data/format.json') f = open('test/data/index.txt', 'r') i.open(f) f.close() assert len(i) == 36
def test_export_ol_no_map_tab_all(): """Test export""" i = Index('test/data/index_oneline.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export(map=None, export_type='tab') assert exp[ 0] == '''ACTGAT(A)\tL3\tAR025\tanterior\trnaSeq\taWL3.2\t"5.8 ng/uL (30 nM) 08/04/2013"\tcell\t297\t37478754\tdmel\taWL3.2/aWL3.2_4204_ACTGAT_transcript.gtf\t2\tMATE1_SENSE\t2x75D\t2\tlongPolyA\t100\twing\tgtf\tTranscriptFB554'''
def test_export_oneline(): """Test export one known line""" i = Index('test/data/index_oneline.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export() assert exp[ 0] == '''aWL3.2/aWL3.2_4204_ACTGAT_transcript.gtf\tLIBRARY_ID=aWL3.2; RNA_quantity=100; barcode=AR025; cell=anterior; dataType=rnaSeq; developmental_point=L3; library_Bioanalyser="5.8 ng/uL (30 nM) 08/04/2013"; localization=cell; max_peak=297; n_sequences=37478754; organism=dmel; pool_ID=2; readStrand=MATE1_SENSE; readType=2x75D; replicate=2; rnaExtract=longPolyA; sequence=ACTGAT(A); tissue=wing; type=gtf; view=TranscriptFB554;'''
def test_export_oneline_no_map(): """Test export one known line""" i = Index('test/data/index_oneline.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export(map=None) assert exp[ 0] == '''aWL3.2/aWL3.2_4204_ACTGAT_transcript.gtf\tadaptor=ACTGAT(A); age=L3; barcode=AR025; cell=anterior; dataType=rnaSeq; labExpId=aWL3.2; libBio="5.8 ng/uL (30 nM) 08/04/2013"; localization=cell; maxPeak=297; nReads=37478754; organism=dmel; poolId=2; readStrand=MATE1_SENSE; readType=2x75D; replicate=2; rnaExtract=longPolyA; rnaQuantity=100; tissue=wing; type=gtf; view=TranscriptFB554;'''
def test_export_no_map(): """Test export""" i = Index('test/data/index.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export(map=None) assert len(exp) == 216 assert 'labExpId' in exp[0] assert 'fileinfo' not in exp[0]
def test_export(): """Test export""" i = Index('test/data/index.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export() assert type(exp) == list assert len(exp) == 216 assert 'LIBRARY_ID' in exp[0]
def test_lookup_more_types_index(): """Test export""" i = Index('test/data/index_one_gfs.txt') assert i is not None i.set_format('test/data/format.json') i.open() result = i.lookup(type='gtf') assert result != None assert result.datasets != {} assert result.export()[0][0] != '.'
def test_open_empty(): """Open empty index""" i = Index() assert i is not None # Disable warning about: # - missing pytest.raises # - statement with no effect # pylint: disable=E1101,W0104 with pytest.raises(AttributeError): i.open()
def test_replicates_w_metadata(): """Test merged datasets with metadata""" i = Index('test/data/index.txt') i.set_format('test/data/format.json') i.open() i.insert(id='aWL3.1,aWL3.2', path='test/data/format.json', type='json', view='json') i.lookup(id='aWL3.1,aWL3.2') i.remove(path='test/data/format.json', clear=True)
def test_lookup_no_path(): i = Index('test/data/index.txt') i.set_format('test/data/format.json') i.open() assert i.datasets.get('WLP.2') is not None selected = i.lookup(id='WLP.2') assert selected.datasets != i.datasets assert len(selected.datasets) == 1 dataset = selected.datasets.get('WLP.2') assert dataset is not None dataset.id = 'WLP.2'
def test_export_ol_no_map_tab_all_header(): """Test export""" i = Index('test/data/index_oneline.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export(map=None, export_type='tab', header=True) assert exp[ 0] == 'adaptor\tage\tbarcode\tcell\tdataType\tlabExpId\tlibBio\tlocalization\tmaxPeak\tnReads\torganism\tpath\tpoolId\treadStrand\treadType\treplicate\trnaExtract\trnaQuantity\ttissue\ttype\tview' assert exp[ 1] == '''ACTGAT(A)\tL3\tAR025\tanterior\trnaSeq\taWL3.2\t"5.8 ng/uL (30 nM) 08/04/2013"\tcell\t297\t37478754\tdmel\taWL3.2/aWL3.2_4204_ACTGAT_transcript.gtf\t2\tMATE1_SENSE\t2x75D\t2\tlongPolyA\t100\twing\tgtf\tTranscriptFB554'''
def test_export_ol_no_map_tab_repeated_tags_header(): """Test export""" i = Index('test/data/index_oneline.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export(map=None, export_type='tab', tags=['id', 'id', 'path'], header=True) assert exp[0] == 'labExpId\tlabExpId\tpath' assert exp[1] == 'aWL3.2\taWL3.2\taWL3.2/aWL3.2_4204_ACTGAT_transcript.gtf'
def test_export_no_map_tab_repeated_tags(): """Test export tab output with repeated tags""" i = Index('test/data/index.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export(map=None, export_type='tab', tags=['id', 'id', 'path'], hide_missing=True) assert len(exp) == 200 assert exp[ 0] == 'EL3.1\tEL3.1\t/users/rg/epalumbo/projects/ERC/fly/bp.pipeline/EL3.1/EL3.1_5355_ATCACG.minusRaw.bigwig'
def test_export_no_map_tab_path_template(): """Test export tab output with path template""" i = Index('test/data/index.txt') assert i is not None i.set_format('test/data/format.json') i.open() exp = i.export(map=None, export_type='tab', tags=['path', '{dirname}/{id}.{view}.{ext}'], hide_missing=True) assert len(exp) == 200 assert exp[ 0] == '/users/rg/epalumbo/projects/ERC/fly/bp.pipeline/EL3.1/EL3.1_5355_ATCACG.minusRaw.bigwig\t/users/rg/epalumbo/projects/ERC/fly/bp.pipeline/EL3.1/EL3.1.MinusRawSignal.bigwig'
def open_index(config): """Open index file from config dictionary""" i = Index() index = config.get('index') idx_format = config.get('format') try: i.set_format(idx_format) i.open(index) except csv.Error: index = config.get('index') i.open(index) except AttributeError: pass return i
def test_replicates(): """Test merged datasets""" i = Index('test/data/index.txt') i.set_format('test/data/format.json') dsid = i.format.get('id', 'id') i.open() reps = i.find_replicates(id="EWP.1,EWP.2") dataset = reps[0] others = reps[1:] merged = dataset.merge(others, dsid=dsid) for key in merged.get_meta_tags(): vals = [getattr(d, key) for d in reps] if len(set(vals)) > 1: if key == dsid: vals = ','.join(vals) assert getattr(merged, key) == vals else: assert getattr(merged, key) == vals[0]