lineage
lineage copied to clipboard
Status code: 502 Reason: Bad Gateway
I'm using lineage==4.3.1. I use it in my code block as I typically do, but I'm now getting a Bac Gateway error message.
This is my code block:
from lineage import Lineage
# https://snps.readthedocs.io/en/stable/
# https://lineage.readthedocs.io/en/stable/
# initialize Lineage object
l = Lineage(
output_dir = output_dir,
resources_dir = f"{references_directory}",
parallelize = True,
processes = 8
)
# initialize dictionary variables
individuals_dict = {}
sex_determination = {}
# initialize count variable
count = 0
directory_path = os.path.join(data_directory, "opensnp_data")
file_pattern = os.path.join(directory_path, "*.ancestry.txt")
opensnp_files = glob.glob(file_pattern)
len_opensnp_files = len(opensnp_files)
# Path for the sex determination TSV file
sex_determination_file = os.path.join(results_directory, "opensnp_sex_determination.tsv")
# Create a lineage individual object for each Ancestry file
# Loop through file names and create individuals_dict
for file_path in opensnp_files:
count = count + 1
filename = os.path.basename(file_path)
username = filename.split("_")[0]
print(f"Processing file {count} in {len_opensnp_files}: {username}")
# print(username)
# assign_par_snps (bool) – assign PAR SNPs to the X and Y chromosomes
# with = True, error message: Chromosome PAR not remapped; removing chromosome from SNPs for consistency
# deduplicate_MT_chrom (bool) – deduplicate alleles on MT; see SNPs.heterozygous_MT
# deduplicate_XY_chrom (bool or str) – deduplicate alleles in the non-PAR regions of X and Y for males
# Why message: Chromosome PAR not remapped; removing chromosome from SNPs for consistency
individuals_dict[username] = l.create_individual(username,
file=file_path,
assign_par_snps=True,
deduplicate_MT_chrom=True,
deduplicate_XY_chrom=True)
if individuals_dict[username].build != 38:
individuals_dict[username].remap(38)
individuals_dict[username].sort()
individuals_dict[username].to_tsv(os.path.join(output_dir, f"{username}.tsv"))
# Determine sex
# heterozygous_x_snps_threshold (float) – percentage heterozygous X SNPs; above this threshold, Female is determined
# y_snps_not_null_threshold (float) – percentage Y SNPs that are not null; above this threshold, Male is determined
# chrom ({“X”, “Y”}) – use X or Y chromosome SNPs to determine sex
# Returns ‘Male’ or ‘Female’ if detected, else empty str
sex_determination[username] = individuals_dict[username].determine_sex(
heterozygous_x_snps_threshold=0.03,
y_snps_not_null_threshold=0.3,
chrom='X'
)
# print(sex_determination[username])
# Save sex determinations to TSV
with open(sex_determination_file, 'w', newline='') as file:
writer = csv.writer(file, delimiter='\t')
writer.writerow(['Username', 'Sex'])
for username, sex in sex_determination.items():
writer.writerow([username, sex])
print("All files processed.")
And this is the error message
Processing file 1 in 3: user6579
Request failed for /variation/v0/refsnp/34943879: Status code: 502 Reason: Bad Gateway
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[10], [line 43](vscode-notebook-cell:?execution_count=10&line=43)
[35](vscode-notebook-cell:?execution_count=10&line=35) print(f"Processing file {count} in {len_opensnp_files}: {username}")
[37](vscode-notebook-cell:?execution_count=10&line=37) # print(username)
[38](vscode-notebook-cell:?execution_count=10&line=38) # assign_par_snps (bool) – assign PAR SNPs to the X and Y chromosomes
[39](vscode-notebook-cell:?execution_count=10&line=39) # with = True, error message: Chromosome PAR not remapped; removing chromosome from SNPs for consistency
[40](vscode-notebook-cell:?execution_count=10&line=40) # deduplicate_MT_chrom (bool) – deduplicate alleles on MT; see SNPs.heterozygous_MT
[41](vscode-notebook-cell:?execution_count=10&line=41) # deduplicate_XY_chrom (bool or str) – deduplicate alleles in the non-PAR regions of X and Y for males
[42](vscode-notebook-cell:?execution_count=10&line=42) # Why message: Chromosome PAR not remapped; removing chromosome from SNPs for consistency
---> [43](vscode-notebook-cell:?execution_count=10&line=43) individuals_dict[username] = l.create_individual(username,
[44](vscode-notebook-cell:?execution_count=10&line=44) file=file_path,
[45](vscode-notebook-cell:?execution_count=10&line=45) assign_par_snps=True,
[46](vscode-notebook-cell:?execution_count=10&line=46) deduplicate_MT_chrom=True,
[47](vscode-notebook-cell:?execution_count=10&line=47) deduplicate_XY_chrom=True)
[49](vscode-notebook-cell:?execution_count=10&line=49) if individuals_dict[username].build != 38:
[50](vscode-notebook-cell:?execution_count=10&line=50) individuals_dict[username].remap(38)
File [~/.venv/lib/python3.10/site-packages/lineage/__init__.py:104](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/lakishadavid/anthropology_genetic_genealogy/~/.venv/lib/python3.10/site-packages/lineage/__init__.py:104), in Lineage.create_individual(self, name, raw_data, **kwargs)
[101](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/lakishadavid/anthropology_genetic_genealogy/~/.venv/lib/python3.10/site-packages/lineage/__init__.py:101) if "resources_dir" not in kwargs:
[102](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/lakishadavid/anthropology_genetic_genealogy/~/.venv/lib/python3.10/site-packages/lineage/__init__.py:102) kwargs["resources_dir"] = self._resources_dir
--> [104](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/lakishadavid/anthropology_genetic_genealogy/~/.venv/lib/python3.10/site-packages/lineage/__init__.py:104) return Individual(name, raw_data, **kwargs)
File [~/.venv/lib/python3.10/site-packages/lineage/individual.py:61](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/lakishadavid/anthropology_genetic_genealogy/~/.venv/lib/python3.10/site-packages/lineage/individual.py:61), in Individual.__init__(self, name, raw_data, **kwargs)
[58](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/lakishadavid/anthropology_genetic_genealogy/~/.venv/lib/python3.10/site-packages/lineage/individual.py:58) init_args = self._get_defined_kwargs(SNPs, kwargs)
...
[905](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/lakishadavid/anthropology_genetic_genealogy/~/.venv/lib/python3.10/site-packages/snps/snps.py:905) # we'll pick the first one to decide which chromosome this PAR will be assigned to
[906](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/lakishadavid/anthropology_genetic_genealogy/~/.venv/lib/python3.10/site-packages/snps/snps.py:906) merged_id = "rs" + response["merged_snapshot_data"]["merged_into"][0]
[907](https://vscode-remote+wsl-002bubuntu-002d22-002e04.vscode-resource.vscode-cdn.net/home/lakishadavid/anthropology_genetic_genealogy/~/.venv/lib/python3.10/site-packages/snps/snps.py:907) logger.info(f"SNP id {rsid} has been merged into id {merged_id}")
TypeError: argument of type 'NoneType' is not iterable