Commit 491d11c4 authored by Romain Feron's avatar Romain Feron
Browse files

Function open_all to open normal / gz files

parent dd17c36a
import gzip
from collections import defaultdict
from radseq_analysis.file_handler.file_open import open_all
def get_info_from_catalog(catalog_path,
......@@ -22,7 +22,7 @@ def get_info_from_catalog(catalog_path,
{ Number of individuals with haplotype: count }
'''
catalog = gzip.open(catalog_path, 'rt')
catalog = open_all(catalog_path)
catalog.readline()
if correspondance:
......
import statistics
from radseq_analysis.file_handler.file_open import open_all
def get_coverage(coverage_file_path):
......@@ -13,7 +14,7 @@ def get_coverage(coverage_file_path):
coverage_data = {}
temp = {}
coverage_file = open(coverage_file_path)
coverage_file = open_all(coverage_file_path)
for line in coverage_file:
fields = line[:-1].split('\t')
......
import gzip
def open_all(file_path):
if file_path.endswith('.gz'):
file = gzip.open(file_path, 'rt')
else:
file = open(file_path)
return file
from collections import defaultdict
from radseq_analysis.shared.commons import *
from radseq_analysis.file_handler.file_open import open_all
def get_haplotypes(haplotypes_file_path, global_parameters, haplotypes=True, numbers=True):
......@@ -15,7 +16,7 @@ def get_haplotypes(haplotypes_file_path, global_parameters, haplotypes=True, num
{ Locus ID: { Haplotype: { Males: N, Females: M } } }
'''
haplotypes_file = open(haplotypes_file_path)
haplotypes_file = open_all(haplotypes_file_path)
line = haplotypes_file.readline()
names = line[:-1].split('\t')[2:]
......
import gzip
from collections import defaultdict
from radseq_analysis.file_handler.file_open import open_all
def get_individual_sequences(individual_file_path, loci_to_extract=None):
# Open file, read 2nd line, extract individual number and reset to 2nd line
individual_file = gzip.open(individual_file_path, 'rt')
individual_file = open_all(individual_file_path, 'rt')
individual_file.readline()
individual_number = individual_file.readline().split('\t')[1]
individual_file.close()
individual_file = gzip.open(individual_file_path, 'rt')
individual_file = open_all(individual_file_path, 'rt')
individual_file.readline()
individual_data = defaultdict(int)
......
from radseq_analysis.file_handler.file_open import open_all
def get_markers(markers_file_path):
......@@ -6,7 +7,9 @@ def get_markers(markers_file_path):
Extract information from a markers file (list of markers ID)
'''
markers_file = open(markers_file_path)
markers_file = open_all(markers_file_path)
markers = [line[:-1] for line in markers_file if line[:-1]]
print(markers)
return markers
from radseq_analysis.file_handler.file_open import open_all
# TODO: verifications
def load_popmap(popmap_file_path, global_parameters):
popmap_file = open(popmap_file_path)
popmap_file = open_all(popmap_file_path)
popmap = {line.split('\t')[0]: line.split('\t')[1][:-1] for
line in popmap_file if line[:-1]}
......
from radseq_analysis.file_handler.file_open import open_all
def load_positions_list(positions_file_path, global_parameters):
positions = []
with open(positions_file_path) as positions_file:
with open_all(positions_file_path) as positions_file:
for line in positions_file:
if line[:-1]:
try:
......
from radseq_analysis.shared import *
from radseq_analysis.shared import Locus
from radseq_analysis.file_handler.file_open import open_all
def get_sequences(sequences_file_path):
......@@ -10,7 +11,7 @@ def get_sequences(sequences_file_path):
sequences = {}
sequences_file = open(sequences_file_path)
sequences_file = open_all(sequences_file_path)
sequences_file.readline()
for line in sequences_file:
......
......@@ -77,9 +77,9 @@ def analysis(markers_file_path, catalog_file_path,
coverage = file_handler.get_coverage(coverage_file_path)
markers_list = file_handler.get_markers(markers_file_path)
correspondance = file_handler.get_info_from_catalog(catalog_file_path,
loci_list=markers_list,
consensus=False,
correspondance=True)
loci_list=markers_list,
consensus=False,
correspondance=True)
individual_names = get_individual_names(individual_files_paths)
print(' - Creating stacks ...')
markers = initialize_markers(markers_list)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment