11
11
from os .path import isfile , relpath
12
12
from shutil import rmtree
13
13
from collections import namedtuple
14
+ from json import dumps
14
15
from qiita_db .util import create_nested_path
15
16
16
17
import networkx as nx
@@ -48,6 +49,7 @@ class Artifact(qdb.base.QiitaObject):
48
49
create
49
50
delete
50
51
being_deleted_by
52
+ archive
51
53
52
54
See Also
53
55
--------
@@ -701,6 +703,7 @@ def archive(cls, artifact_id):
701
703
fids = [x ['fp_id' ] for x in artifact .filepaths
702
704
if x ['fp_type' ] == 'log' ]
703
705
706
+ archive_data = dumps ({"merging_scheme" : artifact .merging_scheme })
704
707
with qdb .sql_connection .TRN :
705
708
artifact ._set_visibility ('archived' , propagate = False )
706
709
sql = 'DELETE FROM qiita.parent_artifact WHERE artifact_id = %s'
@@ -715,6 +718,11 @@ def archive(cls, artifact_id):
715
718
WHERE filepath_id IN %s'''
716
719
qdb .sql_connection .TRN .add (sql , [tuple (fids )])
717
720
721
+ sql = """UPDATE qiita.{0}
722
+ SET archive_data = %s
723
+ WHERE artifact_id = %s""" .format (cls ._table )
724
+ qdb .sql_connection .TRN .add (sql , [archive_data , artifact_id ])
725
+
718
726
qdb .sql_connection .TRN .execute ()
719
727
720
728
# cleaning the extra artifacts
@@ -1461,39 +1469,51 @@ def merging_scheme(self):
1461
1469
The human readable merging scheme and the parent software
1462
1470
information for this artifact
1463
1471
"""
1464
- processing_params = self .processing_parameters
1465
- if processing_params is None :
1466
- return '' , ''
1467
-
1468
- cmd_name = processing_params .command .name
1469
- ms = processing_params .command .merging_scheme
1470
- afps = [x ['fp' ] for x in self .filepaths if x ['fp' ].endswith ('biom' )]
1471
-
1472
- merging_schemes = []
1473
- parent_softwares = []
1474
- # this loop is necessary as in theory an artifact can be
1475
- # generated from multiple prep info files
1476
- for p in self .parents :
1477
- pparent = p .processing_parameters
1478
- # if parent is None, then is a direct upload; for example
1479
- # per_sample_FASTQ in shotgun data
1480
- if pparent is None :
1481
- parent_cmd_name = None
1482
- parent_merging_scheme = None
1483
- parent_pp = None
1484
- parent_software = 'N/A'
1485
- else :
1486
- parent_cmd_name = pparent .command .name
1487
- parent_merging_scheme = pparent .command .merging_scheme
1488
- parent_pp = pparent .values
1489
- psoftware = pparent .command .software
1490
- parent_software = '%s v%s' % (
1491
- psoftware .name , psoftware .version )
1492
-
1493
- merging_schemes .append (qdb .util .human_merging_scheme (
1494
- cmd_name , ms , parent_cmd_name , parent_merging_scheme ,
1495
- processing_params .values , afps , parent_pp ))
1496
- parent_softwares .append (parent_software )
1472
+ vid = qdb .util .convert_to_id (self .visibility , "visibility" )
1473
+ if vid in qdb .util .artifact_visibilities_to_skip ():
1474
+ with qdb .sql_connection .TRN :
1475
+ sql = f"""SELECT archive_data
1476
+ FROM qiita.{ self ._table }
1477
+ WHERE artifact_id = %s"""
1478
+ qdb .sql_connection .TRN .add (sql , [self .id ])
1479
+ archive_data = qdb .sql_connection .TRN .execute_fetchlast ()
1480
+ merging_schemes = [archive_data ['merging_scheme' ][0 ]]
1481
+ parent_softwares = [archive_data ['merging_scheme' ][1 ]]
1482
+ else :
1483
+ processing_params = self .processing_parameters
1484
+ if processing_params is None :
1485
+ return '' , ''
1486
+
1487
+ cmd_name = processing_params .command .name
1488
+ ms = processing_params .command .merging_scheme
1489
+ afps = [x ['fp' ] for x in self .filepaths
1490
+ if x ['fp' ].endswith ('biom' )]
1491
+
1492
+ merging_schemes = []
1493
+ parent_softwares = []
1494
+ # this loop is necessary as in theory an artifact can be
1495
+ # generated from multiple prep info files
1496
+ for p in self .parents :
1497
+ pparent = p .processing_parameters
1498
+ # if parent is None, then is a direct upload; for example
1499
+ # per_sample_FASTQ in shotgun data
1500
+ if pparent is None :
1501
+ parent_cmd_name = None
1502
+ parent_merging_scheme = None
1503
+ parent_pp = None
1504
+ parent_software = 'N/A'
1505
+ else :
1506
+ parent_cmd_name = pparent .command .name
1507
+ parent_merging_scheme = pparent .command .merging_scheme
1508
+ parent_pp = pparent .values
1509
+ psoftware = pparent .command .software
1510
+ parent_software = '%s v%s' % (
1511
+ psoftware .name , psoftware .version )
1512
+
1513
+ merging_schemes .append (qdb .util .human_merging_scheme (
1514
+ cmd_name , ms , parent_cmd_name , parent_merging_scheme ,
1515
+ processing_params .values , afps , parent_pp ))
1516
+ parent_softwares .append (parent_software )
1497
1517
1498
1518
return ', ' .join (merging_schemes ), ', ' .join (parent_softwares )
1499
1519
0 commit comments