@@ -369,7 +369,7 @@ def exists_table(table):
369
369
"""
370
370
with qdb .sql_connection .TRN :
371
371
sql = """SELECT exists(
372
- SELECT * FROM information_schema.tables
372
+ SELECT table_name FROM information_schema.tables
373
373
WHERE table_name=%s)"""
374
374
qdb .sql_connection .TRN .add (sql , [table ])
375
375
return qdb .sql_connection .TRN .execute_fetchlast ()
@@ -1464,6 +1464,10 @@ def generate_study_list(user, visibility):
1464
1464
(SELECT COUNT(sample_id) FROM qiita.study_sample
1465
1465
WHERE study_id=qiita.study.study_id)
1466
1466
AS number_samples_collected,
1467
+ (SELECT EXISTS(
1468
+ SELECT 1 FROM qiita.study_sample
1469
+ WHERE study_id = qiita.study.study_id LIMIT 1))
1470
+ AS has_sample_info,
1467
1471
(SELECT array_agg(row_to_json((prep_template_id, data_type,
1468
1472
artifact_id, artifact_type, deprecated,
1469
1473
qiita.bioms_from_preparation_artifacts(prep_template_id)),
@@ -1500,65 +1504,95 @@ def generate_study_list(user, visibility):
1500
1504
if sids :
1501
1505
with qdb .sql_connection .TRN :
1502
1506
qdb .sql_connection .TRN .add (sql , [tuple (sids )])
1503
- for info in qdb .sql_connection .TRN .execute_fetchindex ():
1504
- info = dict (info )
1505
-
1506
- # cleaning owners name
1507
- if info ['owner' ] in (None , '' ):
1508
- info ['owner' ] = info ['owner_email' ]
1509
- del info ['owner_email' ]
1510
-
1511
- preparation_data_types = []
1512
- artifact_biom_ids = []
1513
- if info ['preparation_information' ] is not None :
1514
- for pinfo in info ['preparation_information' ]:
1515
- # 'f1': prep_template_id, 'f2': data_type,
1516
- # 'f3': artifact_id, 'f4': artifact_type,
1517
- # 'f5':deprecated, 'f6': biom artifacts
1518
- if pinfo ['f5' ]:
1519
- continue
1520
- preparation_data_types .append (pinfo ['f2' ])
1521
- if pinfo ['f4' ] == 'BIOM' :
1522
- artifact_biom_ids .append (pinfo ['f3' ])
1523
- if pinfo ['f6' ] is not None :
1524
- artifact_biom_ids .extend (
1525
- map (int , pinfo ['f6' ].split (',' )))
1526
- del info ['preparation_information' ]
1527
- info ['artifact_biom_ids' ] = list (set (artifact_biom_ids ))
1528
- info ['preparation_data_types' ] = list (set (
1529
- preparation_data_types ))
1530
-
1531
- # publication info
1532
- info ['publication_doi' ] = []
1533
- info ['publication_pid' ] = []
1534
- if info ['publications' ] is not None :
1535
- for p in info ['publications' ]:
1536
- # f1-2 are the default names given by pgsql
1537
- pub = p ['f1' ]
1538
- is_doi = p ['f2' ]
1539
- if is_doi :
1540
- info ['publication_doi' ].append (pub )
1541
- else :
1542
- info ['publication_pid' ].append (pub )
1543
- del info ['publications' ]
1544
-
1545
- # pi info
1546
- info ["pi" ] = (info ['pi_email' ], info ['pi_name' ])
1547
- del info ["pi_email" ]
1548
- del info ["pi_name" ]
1549
-
1550
- # shared with
1551
- info ['shared' ] = []
1552
- if info ['shared_with_name' ] and info ['shared_with_email' ]:
1553
- for name , email in zip (info ['shared_with_name' ],
1554
- info ['shared_with_email' ]):
1555
- if not name :
1556
- name = email
1557
- info ['shared' ].append ((email , name ))
1558
- del info ["shared_with_name" ]
1559
- del info ["shared_with_email" ]
1560
-
1561
- infolist .append (info )
1507
+ results = qdb .sql_connection .TRN .execute_fetchindex ()
1508
+
1509
+ for info in results :
1510
+ info = dict (info )
1511
+
1512
+ # cleaning owners name
1513
+ if info ['owner' ] in (None , '' ):
1514
+ info ['owner' ] = info ['owner_email' ]
1515
+ del info ['owner_email' ]
1516
+
1517
+ preparation_data_types = []
1518
+ artifact_biom_ids = []
1519
+ if info ['preparation_information' ] is not None :
1520
+ for pinfo in info ['preparation_information' ]:
1521
+ # 'f1': prep_template_id, 'f2': data_type,
1522
+ # 'f3': artifact_id, 'f4': artifact_type,
1523
+ # 'f5':deprecated, 'f6': biom artifacts
1524
+ if pinfo ['f5' ]:
1525
+ continue
1526
+ preparation_data_types .append (pinfo ['f2' ])
1527
+ if pinfo ['f4' ] == 'BIOM' :
1528
+ artifact_biom_ids .append (pinfo ['f3' ])
1529
+ if pinfo ['f6' ] is not None :
1530
+ artifact_biom_ids .extend (
1531
+ map (int , pinfo ['f6' ].split (',' )))
1532
+ del info ['preparation_information' ]
1533
+ info ['artifact_biom_ids' ] = list (set (artifact_biom_ids ))
1534
+ info ['preparation_data_types' ] = list (set (
1535
+ preparation_data_types ))
1536
+
1537
+ # publication info
1538
+ info ['publication_doi' ] = []
1539
+ info ['publication_pid' ] = []
1540
+ if info ['publications' ] is not None :
1541
+ for p in info ['publications' ]:
1542
+ # f1-2 are the default names given by pgsql
1543
+ pub = p ['f1' ]
1544
+ is_doi = p ['f2' ]
1545
+ if is_doi :
1546
+ info ['publication_doi' ].append (pub )
1547
+ else :
1548
+ info ['publication_pid' ].append (pub )
1549
+ del info ['publications' ]
1550
+
1551
+ # pi info
1552
+ info ["pi" ] = (info ['pi_email' ], info ['pi_name' ])
1553
+ del info ["pi_email" ]
1554
+ del info ["pi_name" ]
1555
+
1556
+ # shared with
1557
+ info ['shared' ] = []
1558
+ if info ['shared_with_name' ] and info ['shared_with_email' ]:
1559
+ for name , email in zip (info ['shared_with_name' ],
1560
+ info ['shared_with_email' ]):
1561
+ if not name :
1562
+ name = email
1563
+ info ['shared' ].append ((email , name ))
1564
+ del info ["shared_with_name" ]
1565
+ del info ["shared_with_email" ]
1566
+
1567
+ # # add extra info about sample information file
1568
+ # if info['has_sample_info']:
1569
+ # # the fix for #3091 should go here; please reference that
1570
+ # # issue for more information of why it hasn't been closed
1571
+ # with qdb.sql_connection.TRN:
1572
+ # # check if host_scientific_name is part of the metadata
1573
+ # BMT = qdb.metadata_template.base_metadata_template
1574
+ # QCN = BMT.QIITA_COLUMN_NAME
1575
+ # sql = """SELECT POSITION('host_scientific_name' IN
1576
+ # sample_values->>'columns')
1577
+ # FROM qiita.sample_%d
1578
+ # WHERE sample_id = '%s'""" % (
1579
+ # info['study_id'], QCN)
1580
+ # qdb.sql_connection.TRN.add(sql)
1581
+ # has_hsn = qdb.sql_connection.TRN.execute_fetchflatten()
1582
+ # # if it has that column, we can retrieve the information
1583
+ # if has_hsn[0] != 0:
1584
+ # sql = """SELECT array_agg(
1585
+ # DISTINCT
1586
+ # sample_values->>'host_scientific_name')
1587
+ # FROM qiita.sample_%d
1588
+ # WHERE sample_id != '%s'""" % (
1589
+ # info['study_id'], QCN))
1590
+ # qdb.sql_connection.TRN.add(sql)
1591
+ # hsn = qdb.sql_connection.TRN.execute_fetchflatten()
1592
+ # info['host_scientific_name'] = hsn
1593
+ del info ['has_sample_info' ]
1594
+
1595
+ infolist .append (info )
1562
1596
return infolist
1563
1597
1564
1598
0 commit comments